mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-26 02:36:37 +00:00
Forward haptic events to parent window (#4719)
This commit is contained in:
parent
25f5bf0042
commit
b082828a75
@ -319,6 +319,7 @@ class HassioAddonInfo extends LitElement {
|
|||||||
<ha-switch
|
<ha-switch
|
||||||
@change=${this._startOnBootToggled}
|
@change=${this._startOnBootToggled}
|
||||||
.checked=${this.addon.boot === "auto"}
|
.checked=${this.addon.boot === "auto"}
|
||||||
|
haptic
|
||||||
></ha-switch>
|
></ha-switch>
|
||||||
</div>
|
</div>
|
||||||
<div class="state">
|
<div class="state">
|
||||||
@ -326,6 +327,7 @@ class HassioAddonInfo extends LitElement {
|
|||||||
<ha-switch
|
<ha-switch
|
||||||
@change=${this._autoUpdateToggled}
|
@change=${this._autoUpdateToggled}
|
||||||
.checked=${this.addon.auto_update}
|
.checked=${this.addon.auto_update}
|
||||||
|
haptic
|
||||||
></ha-switch>
|
></ha-switch>
|
||||||
</div>
|
</div>
|
||||||
${this.addon.ingress
|
${this.addon.ingress
|
||||||
@ -336,6 +338,7 @@ class HassioAddonInfo extends LitElement {
|
|||||||
@change=${this._panelToggled}
|
@change=${this._panelToggled}
|
||||||
.checked=${this.addon.ingress_panel}
|
.checked=${this.addon.ingress_panel}
|
||||||
.disabled=${this._computeCannotIngressSidebar}
|
.disabled=${this._computeCannotIngressSidebar}
|
||||||
|
haptic
|
||||||
></ha-switch>
|
></ha-switch>
|
||||||
${this._computeCannotIngressSidebar
|
${this._computeCannotIngressSidebar
|
||||||
? html`
|
? html`
|
||||||
@ -363,6 +366,7 @@ class HassioAddonInfo extends LitElement {
|
|||||||
<ha-switch
|
<ha-switch
|
||||||
@change=${this._protectionToggled}
|
@change=${this._protectionToggled}
|
||||||
.checked=${this.addon.protected}
|
.checked=${this.addon.protected}
|
||||||
|
haptic
|
||||||
></ha-switch>
|
></ha-switch>
|
||||||
</div>
|
</div>
|
||||||
`
|
`
|
||||||
|
@ -76,7 +76,6 @@ class HassioMain extends ProvideHassLitMixin(HassRouterPage) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@property() private _supervisorInfo: HassioSupervisorInfo;
|
@property() private _supervisorInfo: HassioSupervisorInfo;
|
||||||
@property() private _hostInfo: HassioHostInfo;
|
@property() private _hostInfo: HassioHostInfo;
|
||||||
@property() private _hassOsInfo?: HassioHassOSInfo;
|
@property() private _hassOsInfo?: HassioHassOSInfo;
|
||||||
@ -111,6 +110,14 @@ class HassioMain extends ProvideHassLitMixin(HassRouterPage) {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Forward haptic events to parent window.
|
||||||
|
window.addEventListener("haptic", (ev) => {
|
||||||
|
// @ts-ignore
|
||||||
|
fireEvent(window.parent, ev.type, ev.detail, {
|
||||||
|
bubbles: false,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
makeDialogManager(this, document.body);
|
makeDialogManager(this, document.body);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,14 +1,19 @@
|
|||||||
import { customElement, CSSResult, css, query } from "lit-element";
|
import { customElement, CSSResult, css, query, property } from "lit-element";
|
||||||
import "@material/mwc-switch";
|
import "@material/mwc-switch";
|
||||||
import { style } from "@material/mwc-switch/mwc-switch-css";
|
import { style } from "@material/mwc-switch/mwc-switch-css";
|
||||||
// tslint:disable-next-line
|
// tslint:disable-next-line
|
||||||
import { Switch } from "@material/mwc-switch";
|
import { Switch } from "@material/mwc-switch";
|
||||||
import { Constructor } from "../types";
|
import { Constructor } from "../types";
|
||||||
|
import { forwardHaptic } from "../data/haptics";
|
||||||
// tslint:disable-next-line
|
// tslint:disable-next-line
|
||||||
const MwcSwitch = customElements.get("mwc-switch") as Constructor<Switch>;
|
const MwcSwitch = customElements.get("mwc-switch") as Constructor<Switch>;
|
||||||
|
|
||||||
@customElement("ha-switch")
|
@customElement("ha-switch")
|
||||||
export class HaSwitch extends MwcSwitch {
|
export class HaSwitch extends MwcSwitch {
|
||||||
|
// Generate a haptic vibration.
|
||||||
|
// Only set to true if the new value of the switch is applied right away when toggling.
|
||||||
|
// Do not add haptic when a user is required to press save.
|
||||||
|
@property({ type: Boolean }) public haptic = false;
|
||||||
@query("slot") private _slot!: HTMLSlotElement;
|
@query("slot") private _slot!: HTMLSlotElement;
|
||||||
|
|
||||||
protected firstUpdated() {
|
protected firstUpdated() {
|
||||||
@ -22,6 +27,11 @@ export class HaSwitch extends MwcSwitch {
|
|||||||
Boolean(this._slot.assignedNodes().length)
|
Boolean(this._slot.assignedNodes().length)
|
||||||
);
|
);
|
||||||
this._slot.addEventListener("click", () => (this.checked = !this.checked));
|
this._slot.addEventListener("click", () => (this.checked = !this.checked));
|
||||||
|
this.addEventListener("change", () => {
|
||||||
|
if (this.haptic) {
|
||||||
|
forwardHaptic("light");
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static get styles(): CSSResult[] {
|
protected static get styles(): CSSResult[] {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user