diff --git a/gallery/src/demos/demo-ha-bar.ts b/gallery/src/demos/demo-ha-bar.ts new file mode 100644 index 0000000000..83f47f5dd6 --- /dev/null +++ b/gallery/src/demos/demo-ha-bar.ts @@ -0,0 +1,85 @@ +import { html, css, LitElement, TemplateResult } from "lit"; +import { customElement } from "lit/decorators"; +import { classMap } from "lit/directives/class-map"; +import "../../../src/components/ha-bar"; +import "../../../src/components/ha-card"; + +const bars: { + min?: number; + max?: number; + value: number; + warning?: number; + error?: number; +}[] = [ + { + value: 33, + }, + { + value: 150, + }, + { + min: -10, + value: 0, + }, + { + value: 80, + }, + { + value: 200, + max: 13, + }, + { + value: 4, + min: 13, + }, +]; + +@customElement("demo-ha-bar") +export class DemoHaBar extends LitElement { + protected render(): TemplateResult { + return html` + ${bars + .map((bar) => ({ min: 0, max: 100, warning: 70, error: 90, ...bar })) + .map( + (bar) => html` + +
+
Config: ${JSON.stringify(bar)}
+ bar.warning, + error: bar.value > bar.error, + })} + .min=${bar.min} + .max=${bar.max} + .value=${bar.value} + > + +
+
+ ` + )} + `; + } + + static get styles() { + return css` + ha-card { + max-width: 600px; + margin: 24px auto; + } + .warning { + --ha-bar-primary-color: var(--warning-color); + } + .error { + --ha-bar-primary-color: var(--error-color); + } + `; + } +} + +declare global { + interface HTMLElementTagNameMap { + "demo-ha-bar": DemoHaBar; + } +}