import { mdiGarage, mdiGarageOpen, mdiLightbulb, mdiLightbulbOff, } from "@mdi/js"; import type { TemplateResult } from "lit"; import { css, html, LitElement } from "lit"; import { customElement, state } from "lit/decorators"; import { ifDefined } from "lit/directives/if-defined"; import { repeat } from "lit/directives/repeat"; import "../../../../src/components/ha-card"; import "../../../../src/components/ha-control-switch"; const switches: { id: string; label: string; class?: string; reversed?: boolean; disabled?: boolean; }[] = [ { id: "switch", label: "Switch", }, { id: "switch-reversed", label: "Switch Reversed", reversed: true, }, { id: "switch-custom", label: "Switch and custom style", class: "custom", }, { id: "switch-disabled", label: "Disabled Switch", disabled: true, }, ]; @customElement("demo-components-ha-control-switch") export class DemoHaControlSwitch extends LitElement { @state() private checked = false; handleValueChanged(e: any) { this.checked = e.target.checked as boolean; } protected render(): TemplateResult { return html` ${repeat(switches, (sw) => { const { id, label, ...config } = sw; return html` ${label} Config: ${JSON.stringify(config)} `; })} Vertical ${repeat(switches, (sw) => { const { id, label, ...config } = sw; return html` `; })} `; } static styles = css` ha-card { max-width: 600px; margin: 24px auto; } pre { margin-top: 0; margin-bottom: 8px; } p { margin: 0; } label { font-weight: var(--ha-font-weight-bold); } .custom { --control-switch-on-color: var(--green-color); --control-switch-off-color: var(--red-color); --control-switch-thickness: 130px; --control-switch-border-radius: var(--ha-border-radius-6xl); --control-switch-padding: 6px; --mdc-icon-size: 24px; } .vertical-switches { height: 300px; display: flex; flex-direction: row; justify-content: space-between; } p.title { margin-bottom: 12px; } .vertical-switches > *:not(:last-child) { margin-right: 4px; } `; } declare global { interface HTMLElementTagNameMap { "demo-components-ha-control-switch": DemoHaControlSwitch; } }
Config: ${JSON.stringify(config)}
Vertical