mirror of
https://github.com/home-assistant/frontend.git
synced 2026-04-17 15:45:43 +01:00
* Allow HaDropdownSelectEvent to pass the value type * Fix potential type conflict * Add clarification of type * Fix type * Create new type for ha-select * Refactor * Add clearable to only handle undefined when needed * Value changed event * Use clearable type * Remove * Profile section refactor * Protocols refactor * More config refactor * Entity rows 1 * Remove unrelated * Remove ValueChangedEvent changes (moved to separate branch) * Revert * Add * Revert unrelated or extra checks * Restore * Restore * Restore * Update src/components/ha-conversation-agent-picker.ts Co-authored-by: Petar Petrov <MindFreeze@users.noreply.github.com> --------- Co-authored-by: Petar Petrov <MindFreeze@users.noreply.github.com>
80 lines
2.0 KiB
TypeScript
80 lines
2.0 KiB
TypeScript
import type { TemplateResult } from "lit";
|
|
import { css, html, LitElement } from "lit";
|
|
import { customElement, property } from "lit/decorators";
|
|
import { fireEvent } from "../common/dom/fire_event";
|
|
import type { HomeAssistant } from "../types";
|
|
import type { HaSelectOption, HaSelectSelectEvent } from "./ha-select";
|
|
import "./ha-select";
|
|
|
|
const DEFAULT_THEME = "default";
|
|
|
|
@customElement("ha-theme-picker")
|
|
export class HaThemePicker extends LitElement {
|
|
@property() public value?: string;
|
|
|
|
@property() public label?: string;
|
|
|
|
@property({ attribute: "include-default", type: Boolean })
|
|
public includeDefault = false;
|
|
|
|
@property({ attribute: false }) public hass?: HomeAssistant;
|
|
|
|
@property({ type: Boolean, reflect: true }) public disabled = false;
|
|
|
|
@property({ type: Boolean }) public required = false;
|
|
|
|
protected render(): TemplateResult {
|
|
const options: HaSelectOption[] = Object.keys(
|
|
this.hass?.themes.themes || {}
|
|
).map((theme) => ({
|
|
value: theme,
|
|
}));
|
|
|
|
if (this.includeDefault) {
|
|
options.unshift({
|
|
value: DEFAULT_THEME,
|
|
label: "Home Assistant",
|
|
});
|
|
}
|
|
|
|
if (!this.required) {
|
|
options.unshift({
|
|
value: "remove",
|
|
label: this.hass!.localize("ui.components.theme-picker.no_theme"),
|
|
});
|
|
}
|
|
|
|
return html`
|
|
<ha-select
|
|
.label=${this.label ||
|
|
this.hass!.localize("ui.components.theme-picker.theme")}
|
|
.value=${this.value}
|
|
.required=${this.required}
|
|
.disabled=${this.disabled}
|
|
@selected=${this._changed}
|
|
.options=${options}
|
|
></ha-select>
|
|
`;
|
|
}
|
|
|
|
static styles = css`
|
|
ha-select {
|
|
width: 100%;
|
|
}
|
|
`;
|
|
|
|
private _changed(ev: HaSelectSelectEvent): void {
|
|
if (!this.hass || ev.detail.value === "") {
|
|
return;
|
|
}
|
|
this.value = ev.detail.value === "remove" ? undefined : ev.detail.value;
|
|
fireEvent(this, "value-changed", { value: this.value });
|
|
}
|
|
}
|
|
|
|
declare global {
|
|
interface HTMLElementTagNameMap {
|
|
"ha-theme-picker": HaThemePicker;
|
|
}
|
|
}
|