Skip to content

Commit

Permalink
Merge branch 'dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
paolapersico1 authored May 7, 2024
2 parents 58067d7 + e55b59d commit 70af495
Show file tree
Hide file tree
Showing 17 changed files with 149 additions and 411 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
"@material/mwc-list": "0.27.0",
"@material/mwc-menu": "0.27.0",
"@material/mwc-radio": "0.27.0",
"@material/mwc-ripple": "0.27.0",
"@material/mwc-select": "0.27.0",
"@material/mwc-snackbar": "0.27.0",
"@material/mwc-switch": "0.27.0",
Expand Down
1 change: 1 addition & 0 deletions src/components/data-table/ha-data-table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -984,6 +984,7 @@ export class HaDataTable extends LitElement {
padding-top: 12px;
padding-left: 12px;
padding-inline-start: 12px;
padding-inline-end: initial;
width: 100%;
font-weight: 500;
display: flex;
Expand Down
63 changes: 7 additions & 56 deletions src/components/ha-control-button.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,14 @@
import { Ripple } from "@material/mwc-ripple";
import { RippleHandlers } from "@material/mwc-ripple/ripple-handlers";
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
import {
customElement,
eventOptions,
property,
queryAsync,
state,
} from "lit/decorators";
import { customElement, property } from "lit/decorators";
import { ifDefined } from "lit/directives/if-defined";
import "./ha-ripple";

@customElement("ha-control-button")
export class HaControlButton extends LitElement {
@property({ type: Boolean, reflect: true }) disabled = false;

@property() public label?: string;

@queryAsync("mwc-ripple") private _ripple!: Promise<Ripple | null>;

@state() private _shouldRenderRipple = false;

protected render(): TemplateResult {
return html`
<button
Expand All @@ -28,54 +17,13 @@ export class HaControlButton extends LitElement {
aria-label=${ifDefined(this.label)}
title=${ifDefined(this.label)}
.disabled=${Boolean(this.disabled)}
@focus=${this.handleRippleFocus}
@blur=${this.handleRippleBlur}
@mousedown=${this.handleRippleActivate}
@mouseup=${this.handleRippleDeactivate}
@mouseenter=${this.handleRippleMouseEnter}
@mouseleave=${this.handleRippleMouseLeave}
@touchstart=${this.handleRippleActivate}
@touchend=${this.handleRippleDeactivate}
@touchcancel=${this.handleRippleDeactivate}
>
<slot></slot>
${this._shouldRenderRipple && !this.disabled
? html`<mwc-ripple></mwc-ripple>`
: ""}
<ha-ripple .disabled=${this.disabled}></ha-ripple>
</button>
`;
}

private _rippleHandlers: RippleHandlers = new RippleHandlers(() => {
this._shouldRenderRipple = true;
return this._ripple;
});

@eventOptions({ passive: true })
private handleRippleActivate(evt?: Event) {
this._rippleHandlers.startPress(evt);
}

private handleRippleDeactivate() {
this._rippleHandlers.endPress();
}

private handleRippleMouseEnter() {
this._rippleHandlers.startHover();
}

private handleRippleMouseLeave() {
this._rippleHandlers.endHover();
}

private handleRippleFocus() {
this._rippleHandlers.startFocus();
}

private handleRippleBlur() {
this._rippleHandlers.endFocus();
}

static get styles(): CSSResultGroup {
return css`
:host {
Expand All @@ -86,6 +34,7 @@ export class HaControlButton extends LitElement {
--control-button-border-radius: 10px;
--control-button-padding: 8px;
--mdc-icon-size: 20px;
--ha-ripple-color: var(--secondary-text-color);
color: var(--primary-text-color);
width: 40px;
height: 40px;
Expand Down Expand Up @@ -113,12 +62,14 @@ export class HaControlButton extends LitElement {
outline: none;
overflow: hidden;
background: none;
--mdc-ripple-color: var(--control-button-background-color);
/* For safari border-radius overflow */
z-index: 0;
font-size: inherit;
color: inherit;
}
.button:focus-visible {
--control-button-background-opacity: 0.4;
}
.button::before {
content: "";
position: absolute;
Expand Down
75 changes: 9 additions & 66 deletions src/components/ha-control-select-menu.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
import { Ripple } from "@material/mwc-ripple";
import { RippleHandlers } from "@material/mwc-ripple/ripple-handlers";
import { SelectBase } from "@material/mwc-select/mwc-select-base";
import { mdiMenuDown } from "@mdi/js";
import { css, html, nothing } from "lit";
import {
customElement,
eventOptions,
property,
query,
queryAsync,
state,
} from "lit/decorators";
import { customElement, property, query } from "lit/decorators";
import { classMap } from "lit/directives/class-map";
import { ifDefined } from "lit/directives/if-defined";
import { debounce } from "../common/util/debounce";
import { nextRender } from "../common/util/render-status";
import "./ha-icon";
import type { HaIcon } from "./ha-icon";
import "./ha-ripple";
import "./ha-svg-icon";
import type { HaSvgIcon } from "./ha-svg-icon";

Expand All @@ -32,10 +24,6 @@ export class HaControlSelectMenu extends SelectBase {
@property({ type: Boolean, attribute: "hide-label" })
public hideLabel = false;

@queryAsync("mwc-ripple") private _ripple!: Promise<Ripple | null>;

@state() private _shouldRenderRipple = false;

public override render() {
const classes = {
"select-disabled": this.disabled,
Expand Down Expand Up @@ -69,17 +57,10 @@ export class HaControlSelectMenu extends SelectBase {
aria-labelledby=${ifDefined(labelledby)}
aria-label=${ifDefined(labelAttribute)}
aria-required=${this.required}
@click=${this.onClick}
@focus=${this.onFocus}
@blur=${this.onBlur}
@click=${this.onClick}
@keydown=${this.onKeydown}
@mousedown=${this.handleRippleActivate}
@mouseup=${this.handleRippleDeactivate}
@mouseenter=${this.handleRippleMouseEnter}
@mouseleave=${this.handleRippleMouseLeave}
@touchstart=${this.handleRippleActivate}
@touchend=${this.handleRippleDeactivate}
@touchcancel=${this.handleRippleDeactivate}
>
${this.renderIcon()}
<div class="content">
Expand All @@ -91,9 +72,7 @@ export class HaControlSelectMenu extends SelectBase {
: nothing}
</div>
${this.renderArrow()}
${this._shouldRenderRipple && !this.disabled
? html` <mwc-ripple></mwc-ripple> `
: nothing}
<ha-ripple .disabled=${this.disabled}></ha-ripple>
</div>
${this.renderMenu()}
</div>
Expand Down Expand Up @@ -135,46 +114,6 @@ export class HaControlSelectMenu extends SelectBase {
`;
}

protected onFocus() {
this.handleRippleFocus();
super.onFocus();
}

protected onBlur() {
this.handleRippleBlur();
super.onBlur();
}

private _rippleHandlers: RippleHandlers = new RippleHandlers(() => {
this._shouldRenderRipple = true;
return this._ripple;
});

@eventOptions({ passive: true })
private handleRippleActivate(evt?: Event) {
this._rippleHandlers.startPress(evt);
}

private handleRippleDeactivate() {
this._rippleHandlers.endPress();
}

private handleRippleMouseEnter() {
this._rippleHandlers.startHover();
}

private handleRippleMouseLeave() {
this._rippleHandlers.endHover();
}

private handleRippleFocus() {
this._rippleHandlers.startFocus();
}

private handleRippleBlur() {
this._rippleHandlers.endFocus();
}

connectedCallback() {
super.connectedCallback();
window.addEventListener("translations-updated", this._translationsUpdated);
Expand Down Expand Up @@ -204,6 +143,7 @@ export class HaControlSelectMenu extends SelectBase {
--control-select-menu-height: 48px;
--control-select-menu-padding: 6px 10px;
--mdc-icon-size: 20px;
--ha-ripple-color: var(--secondary-text-color);
font-size: 14px;
line-height: 1.4;
width: auto;
Expand All @@ -224,7 +164,6 @@ export class HaControlSelectMenu extends SelectBase {
outline: none;
overflow: hidden;
background: none;
--mdc-ripple-color: var(--control-select-menu-background-color);
/* For safari border-radius overflow */
z-index: 0;
transition: color 180ms ease-in-out;
Expand Down Expand Up @@ -264,6 +203,10 @@ export class HaControlSelectMenu extends SelectBase {
letter-spacing: inherit;
}
.select-anchor:focus-visible {
--control-select-menu-background-opacity: 0.4;
}
.select-anchor::before {
content: "";
position: absolute;
Expand Down
4 changes: 2 additions & 2 deletions src/components/ha-filter-domains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,14 @@ export class HaFilterDomains extends LitElement {
align-items: center;
}
.header ha-icon-button {
margin-inline-start: auto;
margin-inline-start: initial;
margin-inline-end: 8px;
}
.badge {
display: inline-block;
margin-left: 8px;
margin-inline-start: 8px;
margin-inline-end: 0;
margin-inline-end: initial;
min-width: 16px;
box-sizing: border-box;
border-radius: 50%;
Expand Down
3 changes: 0 additions & 3 deletions src/components/ha-label.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
import { customElement, property } from "lit/decorators";
import "@material/web/ripple/ripple";

@customElement("ha-label")
class HaLabel extends LitElement {
Expand All @@ -11,7 +10,6 @@ class HaLabel extends LitElement {
<span class="content">
<slot name="icon"></slot>
<slot></slot>
<md-ripple></md-ripple>
</span>
`;
}
Expand All @@ -27,7 +25,6 @@ class HaLabel extends LitElement {
0.15
);
--ha-label-background-opacity: 1;
position: relative;
box-sizing: border-box;
display: inline-flex;
Expand Down
63 changes: 63 additions & 0 deletions src/components/ha-ripple.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { AttachableController } from "@material/web/internal/controller/attachable-controller";
import { MdRipple } from "@material/web/ripple/ripple";
import "element-internals-polyfill";
import { css } from "lit";
import { customElement } from "lit/decorators";

@customElement("ha-ripple")
export class HaRipple extends MdRipple {
private readonly attachableTouchController = new AttachableController(
this,
this.onTouchControlChange.bind(this)
);

attach(control: HTMLElement) {
super.attach(control);
this.attachableTouchController.attach(control);
}

detach() {
super.detach();
this.attachableTouchController.detach();
}

private _handleTouchEnd = () => {
if (!this.disabled) {
// @ts-ignore
super.endPressAnimation();
}
};

private onTouchControlChange(
prev: HTMLElement | null,
next: HTMLElement | null
) {
// Add touchend event to clean ripple on touch devices using action handler
prev?.removeEventListener("touchend", this._handleTouchEnd);
next?.addEventListener("touchend", this._handleTouchEnd);
}

static override styles = [
...super.styles,
css`
:host {
--md-ripple-hover-opacity: var(--ha-ripple-hover-opacity, 0.08);
--md-ripple-pressed-opacity: var(--ha-ripple-pressed-opacity, 0.12);
--md-ripple-hover-color: var(
--ha-ripple-hover-color,
var(--ha-ripple-color, var(--secondary-text-color))
);
--md-ripple-pressed-color: var(
--ha-ripple-pressed-color,
var(--ha-ripple-color, var(--secondary-text-color))
);
}
`,
];
}

declare global {
interface HTMLElementTagNameMap {
"ha-ripple": HaRipple;
}
}
Loading

0 comments on commit 70af495

Please sign in to comment.