import { mdiClose, mdiMagnify } from "@mdi/js"; import type { TemplateResult } from "lit"; import { css, html, LitElement } from "lit"; import { customElement, property, query } from "lit/decorators"; import "./ha-icon-button"; import "./ha-svg-icon"; import "./ha-textfield"; import type { HaTextField } from "./ha-textfield"; import type { HomeAssistant } from "../types"; import { fireEvent } from "../common/dom/fire_event"; @customElement("search-input") class SearchInput extends LitElement { @property({ attribute: false }) public hass!: HomeAssistant; @property() public filter?: string; @property({ type: Boolean }) public suffix = false; // eslint-disable-next-line lit/no-native-attributes @property({ type: Boolean }) public autofocus = false; @property({ type: String }) public label?: string; public focus() { this._input?.focus(); } @query("ha-textfield", true) private _input!: HaTextField; protected render(): TemplateResult { return html`
${this.filter && html` `}
`; } private async _filterChanged(value: string) { fireEvent(this, "value-changed", { value: String(value) }); } private async _filterInputChanged(e) { this._filterChanged(e.target.value); } private async _clearSearch() { this._filterChanged(""); } static styles = css` :host { display: inline-flex; } ha-svg-icon, ha-icon-button { color: var(--primary-text-color); } ha-svg-icon { outline: none; } .clear-button { --mdc-icon-size: 20px; } ha-textfield { display: inherit; } .trailing { display: flex; align-items: center; } `; } declare global { interface HTMLElementTagNameMap { "search-input": SearchInput; } }