import type { CSSResultGroup } from "lit"; import { css, html, LitElement, nothing } from "lit"; import { customElement, property, state } from "lit/decorators"; import { fireEvent } from "../../../../common/dom/fire_event"; import "../../../../components/ha-icon-picker"; import "../../../../components/ha-textfield"; import type { InputButton } from "../../../../data/input_button"; import { haStyle } from "../../../../resources/styles"; import type { HomeAssistant } from "../../../../types"; @customElement("ha-input_button-form") class HaInputButtonForm extends LitElement { @property({ attribute: false }) public hass!: HomeAssistant; @property({ type: Boolean }) public new = false; @property({ type: Boolean }) public disabled = false; @state() private _name!: string; @state() private _icon!: string; private _item?: InputButton; set item(item: InputButton) { this._item = item; if (item) { this._name = item.name || ""; this._icon = item.icon || ""; } else { this._name = ""; this._icon = ""; } } public focus() { this.updateComplete.then(() => ( this.shadowRoot?.querySelector("[dialogInitialFocus]") as HTMLElement )?.focus() ); } protected render() { if (!this.hass) { return nothing; } return html`
`; } private _valueChanged(ev: CustomEvent) { if (!this.new && !this._item) { return; } ev.stopPropagation(); const configValue = (ev.target as any).configValue; const value = ev.detail?.value || (ev.target as any).value; if (this[`_${configValue}`] === value) { return; } const newValue = { ...this._item }; if (!value) { delete newValue[configValue]; } else { newValue[configValue] = value; } fireEvent(this, "value-changed", { value: newValue, }); } static get styles(): CSSResultGroup { return [ haStyle, css` .form { color: var(--primary-text-color); } .row { padding: 16px 0; } ha-textfield { display: block; margin: 8px 0; } `, ]; } } declare global { interface HTMLElementTagNameMap { "ha-input_button-form": HaInputButtonForm; } }