/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at htp://mozilla.org/MPL/2.0/. */ // Bug 1790483: Lit is not bundled yet, this is dev only. // eslint-disable-next-line import/no-unresolved import { html, ifDefined } from "../vendor/lit.all.mjs"; import { MozLitElement } from "../lit-utils.mjs"; export default class MozToggle extends MozLitElement { static LOCAL_NAME = "moz-toggle"; static properties = { checked: { type: Boolean, reflect: true }, disabled: { type: Boolean, reflect: true }, label: { type: String }, description: { type: String }, ariaLabel: { type: String, attribute: "aria-label" }, }; static get queries() { return { inputEl: "#moz-toggle-input", labelEl: "#moz-toggle-label", descriptionEl: "#moz-toggle-description", }; } constructor() { super(); this.checked = false; this.disabled = false; } handleChange() { this.checked = this.inputEl.checked; this.dispatchEvent( new Event("change", { bubbles: true, composed: true, }) ); } labelTemplate() { if (this.label) { return html` `; } return ""; } descriptionTemplate() { if (this.description) { return html`

${this.description}

`; } return ""; } render() { const { checked, disabled, description, ariaLabel, handleChange } = this; return html` ${this.labelTemplate()} ${this.descriptionTemplate()} `; } } customElements.define("moz-toggle", MozToggle);