1
0
mirror of https://github.com/home-assistant/frontend.git synced 2026-04-17 15:45:43 +01:00
Files
frontend/src/components/ha-theme-picker.ts
Aidan Timson f5cc2104ef Refactor ha-select and ha-dropdown event handlers to use generic event types (#29397)
* 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>
2026-02-05 13:47:28 +02:00

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;
}
}