mirror of
https://github.com/home-assistant/frontend.git
synced 2025-10-12 05:09:40 +00:00
58 lines
1.2 KiB
TypeScript
58 lines
1.2 KiB
TypeScript
import {
|
|
css,
|
|
CSSResult,
|
|
customElement,
|
|
html,
|
|
LitElement,
|
|
property,
|
|
} from "lit-element";
|
|
import { fireEvent } from "../../common/dom/fire_event";
|
|
import { HomeAssistant } from "../../types";
|
|
import "../ha-formfield";
|
|
import "../ha-switch";
|
|
|
|
@customElement("ha-selector-boolean")
|
|
export class HaBooleanSelector extends LitElement {
|
|
@property() public hass!: HomeAssistant;
|
|
|
|
@property() public value?: number;
|
|
|
|
@property() public label?: string;
|
|
|
|
@property({ type: Boolean }) public disabled = false;
|
|
|
|
protected render() {
|
|
return html` <ha-formfield alignEnd spaceBetween .label=${this.label}>
|
|
<ha-switch
|
|
.checked=${this.value}
|
|
@change=${this._handleChange}
|
|
.disabled=${this.disabled}
|
|
></ha-switch>
|
|
</ha-formfield>`;
|
|
}
|
|
|
|
private _handleChange(ev) {
|
|
const value = ev.target.checked;
|
|
if (this.value === value) {
|
|
return;
|
|
}
|
|
fireEvent(this, "value-changed", { value });
|
|
}
|
|
|
|
static get styles(): CSSResult {
|
|
return css`
|
|
ha-formfield {
|
|
width: 100%;
|
|
margin: 16px 0;
|
|
--mdc-typography-body2-font-size: 1em;
|
|
}
|
|
`;
|
|
}
|
|
}
|
|
|
|
declare global {
|
|
interface HTMLElementTagNameMap {
|
|
"ha-selector-boolean": HaBooleanSelector;
|
|
}
|
|
}
|