diff --git a/src/components/device/ha-device-picker.ts b/src/components/device/ha-device-picker.ts index 8d8cb13f35..d5b304fe2a 100644 --- a/src/components/device/ha-device-picker.ts +++ b/src/components/device/ha-device-picker.ts @@ -1,7 +1,7 @@ import type { ComboBoxLitRenderer } from "@vaadin/combo-box/lit"; import type { HassEntity } from "home-assistant-js-websocket"; import type { PropertyValues, TemplateResult } from "lit"; -import { LitElement, html } from "lit"; +import { LitElement, html, nothing } from "lit"; import { customElement, property, query, state } from "lit/decorators"; import memoizeOne from "memoize-one"; import { fireEvent } from "../../common/dom/fire_event"; @@ -19,7 +19,7 @@ import type { EntityRegistryDisplayEntry } from "../../data/entity_registry"; import type { HomeAssistant, ValueChangedEvent } from "../../types"; import "../ha-combo-box"; import type { HaComboBox } from "../ha-combo-box"; -import "../ha-list-item"; +import "../ha-combo-box-item"; interface Device { name: string; @@ -35,11 +35,14 @@ export type HaDevicePickerDeviceFilterFunc = ( export type HaDevicePickerEntityFilterFunc = (entity: HassEntity) => boolean; -const rowRenderer: ComboBoxLitRenderer = (item) => - html` - ${item.name} - ${item.area} - `; +const rowRenderer: ComboBoxLitRenderer = (item) => html` + + ${item.name} + ${item.area + ? html`${item.area}` + : nothing} + +`; @customElement("ha-device-picker") export class HaDevicePicker extends LitElement { diff --git a/src/components/entity/ha-statistic-picker.ts b/src/components/entity/ha-statistic-picker.ts index 78ffb8d247..586c26b52b 100644 --- a/src/components/entity/ha-statistic-picker.ts +++ b/src/components/entity/ha-statistic-picker.ts @@ -1,23 +1,23 @@ -import "@material/mwc-list/mwc-list-item"; +import type { ComboBoxLitRenderer } from "@vaadin/combo-box/lit"; import type { HassEntity } from "home-assistant-js-websocket"; import type { PropertyValues, TemplateResult } from "lit"; import { html, LitElement, nothing } from "lit"; -import type { ComboBoxLitRenderer } from "@vaadin/combo-box/lit"; import { customElement, property, query, state } from "lit/decorators"; import memoizeOne from "memoize-one"; import { ensureArray } from "../../common/array/ensure-array"; import { fireEvent } from "../../common/dom/fire_event"; import { stringCompare } from "../../common/string/compare"; +import type { ScorableTextItem } from "../../common/string/filter/sequence-matching"; +import { fuzzyFilterSort } from "../../common/string/filter/sequence-matching"; import type { StatisticsMetaData } from "../../data/recorder"; import { getStatisticIds, getStatisticLabel } from "../../data/recorder"; -import type { ValueChangedEvent, HomeAssistant } from "../../types"; +import type { HomeAssistant, ValueChangedEvent } from "../../types"; import { documentationUrl } from "../../util/documentation-url"; import "../ha-combo-box"; import type { HaComboBox } from "../ha-combo-box"; +import "../ha-combo-box-item"; import "../ha-svg-icon"; import "./state-badge"; -import type { ScorableTextItem } from "../../common/string/filter/sequence-matching"; -import { fuzzyFilterSort } from "../../common/string/filter/sequence-matching"; interface StatisticItem extends ScorableTextItem { id: string; @@ -99,16 +99,18 @@ export class HaStatisticPicker extends LitElement { @state() private _filteredItems?: StatisticItem[] = undefined; private _rowRenderer: ComboBoxLitRenderer = (item) => - html` + html` ${item.state - ? html`` - : ""} - ${item.name} - + ` + : html``} + ${item.name} + ${item.id === "" || item.id === "__missing" ? html`` : item.id} - `; + `; private _getStatistics = memoizeOne( ( diff --git a/src/components/ha-addon-picker.ts b/src/components/ha-addon-picker.ts index 80889bbe13..ed651ab44e 100644 --- a/src/components/ha-addon-picker.ts +++ b/src/components/ha-addon-picker.ts @@ -10,20 +10,23 @@ import type { HomeAssistant, ValueChangedEvent } from "../types"; import "./ha-alert"; import "./ha-combo-box"; import type { HaComboBox } from "./ha-combo-box"; -import "./ha-list-item"; +import "./ha-combo-box-item"; -const rowRenderer: ComboBoxLitRenderer = (item) => - html` - ${item.name} - ${item.slug} +const rowRenderer: ComboBoxLitRenderer = (item) => html` + + ${item.name} + ${item.slug} ${item.icon - ? html`` - : ""} - `; + ? html` + + ` + : nothing} + +`; @customElement("ha-addon-picker") class HaAddonPicker extends LitElement { diff --git a/src/components/ha-area-floor-picker.ts b/src/components/ha-area-floor-picker.ts index c5e4a7a3dc..5c13690c01 100644 --- a/src/components/ha-area-floor-picker.ts +++ b/src/components/ha-area-floor-picker.ts @@ -25,6 +25,7 @@ import type { HomeAssistant, ValueChangedEvent } from "../types"; import type { HaDevicePickerDeviceFilterFunc } from "./device/ha-device-picker"; import "./ha-combo-box"; import type { HaComboBox } from "./ha-combo-box"; +import "./ha-combo-box-item"; import "./ha-floor-icon"; import "./ha-icon-button"; import "./ha-list-item"; @@ -125,38 +126,38 @@ export class HaAreaFloorPicker extends LitElement { private _rowRenderer: ComboBoxLitRenderer = (item) => { const rtl = computeRTL(this.hass); return html` - ${item.type === "area" && item.hasFloor - ? html`` + ? html` + + ` : nothing} ${item.type === "floor" - ? html`` + ? html`` : item.icon - ? html`` + ? html`` : html``} ${item.name} - + `; }; diff --git a/src/components/ha-area-picker.ts b/src/components/ha-area-picker.ts index cbad36bc03..9b00f0afa7 100644 --- a/src/components/ha-area-picker.ts +++ b/src/components/ha-area-picker.ts @@ -4,7 +4,6 @@ import type { HassEntity } from "home-assistant-js-websocket"; import type { PropertyValues, TemplateResult } from "lit"; import { LitElement, html } from "lit"; import { customElement, property, query, state } from "lit/decorators"; -import { classMap } from "lit/directives/class-map"; import memoizeOne from "memoize-one"; import { fireEvent } from "../common/dom/fire_event"; import { computeDomain } from "../common/entity/compute_domain"; @@ -24,22 +23,21 @@ import type { HomeAssistant, ValueChangedEvent } from "../types"; import type { HaDevicePickerDeviceFilterFunc } from "./device/ha-device-picker"; import "./ha-combo-box"; import type { HaComboBox } from "./ha-combo-box"; +import "./ha-combo-box-item"; import "./ha-icon-button"; import "./ha-list-item"; import "./ha-svg-icon"; type ScorableAreaRegistryEntry = ScorableTextItem & AreaRegistryEntry; -const rowRenderer: ComboBoxLitRenderer = (item) => - html` +const rowRenderer: ComboBoxLitRenderer = (item) => html` + ${item.icon - ? html`` - : html``} + ? html`` + : html``} ${item.name} - `; + +`; const ADD_NEW_ID = "___ADD_NEW___"; const NO_ITEMS_ID = "___NO_ITEMS___"; diff --git a/src/components/ha-combo-box-item.ts b/src/components/ha-combo-box-item.ts index d42db9bd8d..4a1b822ebc 100644 --- a/src/components/ha-combo-box-item.ts +++ b/src/components/ha-combo-box-item.ts @@ -11,6 +11,7 @@ export class HaComboBoxItem extends HaMdListItem { ...super.styles, css` :host { + --md-list-item-one-line-container-height: 48px; --md-list-item-two-line-container-height: 64px; } :host([border-top]) md-item { @@ -29,7 +30,8 @@ export class HaComboBoxItem extends HaMdListItem { font-size: 12px; white-space: nowrap; } - ::slotted(state-badge) { + ::slotted(state-badge), + ::slotted(img) { width: 32px; height: 32px; } diff --git a/src/components/ha-combo-box.ts b/src/components/ha-combo-box.ts index 35b38f5dcc..543fc801ee 100644 --- a/src/components/ha-combo-box.ts +++ b/src/components/ha-combo-box.ts @@ -16,8 +16,8 @@ import { customElement, property, query } from "lit/decorators"; import { ifDefined } from "lit/directives/if-defined"; import { fireEvent } from "../common/dom/fire_event"; import type { HomeAssistant } from "../types"; +import "./ha-combo-box-item"; import "./ha-icon-button"; -import "./ha-list-item"; import "./ha-textfield"; import type { HaTextField } from "./ha-textfield"; @@ -216,10 +216,11 @@ export class HaComboBox extends LitElement { private _defaultRowRenderer: ComboBoxLitRenderer< string | Record - > = (item) => - html` + > = (item) => html` + ${this.itemLabelPath ? item[this.itemLabelPath] : item} - `; + + `; private _clearValue(ev: Event) { ev.stopPropagation(); diff --git a/src/components/ha-config-entry-picker.ts b/src/components/ha-config-entry-picker.ts index ce39a4b210..2ead4e03ed 100644 --- a/src/components/ha-config-entry-picker.ts +++ b/src/components/ha-config-entry-picker.ts @@ -1,4 +1,3 @@ -import "@material/mwc-list/mwc-list-item"; import type { ComboBoxLitRenderer } from "@vaadin/combo-box/lit"; import { html, LitElement, nothing } from "lit"; import { customElement, property, query, state } from "lit/decorators"; @@ -11,6 +10,7 @@ import type { ValueChangedEvent, HomeAssistant } from "../types"; import { brandsUrl } from "../util/brands-url"; import "./ha-combo-box"; import type { HaComboBox } from "./ha-combo-box"; +import "./ha-combo-box-item"; export interface ConfigEntryExtended extends ConfigEntry { localized_domain_name?: string; @@ -48,18 +48,20 @@ class HaConfigEntryPicker extends LitElement { this._getConfigEntries(); } - private _rowRenderer: ComboBoxLitRenderer = (item) => - html` - ${item.title || + private _rowRenderer: ComboBoxLitRenderer = ( + item + ) => html` + + + ${item.title || this.hass.localize( "ui.panel.config.integrations.config_entry.unnamed_entry" - )} - ${item.localized_domain_name} + )} + + ${item.localized_domain_name} - `; + + `; protected render() { if (!this._configEntries) { diff --git a/src/components/ha-floor-picker.ts b/src/components/ha-floor-picker.ts index cfa5678591..4107aadc2c 100644 --- a/src/components/ha-floor-picker.ts +++ b/src/components/ha-floor-picker.ts @@ -3,7 +3,6 @@ import type { HassEntity } from "home-assistant-js-websocket"; import type { PropertyValues, TemplateResult } from "lit"; import { LitElement, html } from "lit"; import { customElement, property, query, state } from "lit/decorators"; -import { classMap } from "lit/directives/class-map"; import memoizeOne from "memoize-one"; import { fireEvent } from "../common/dom/fire_event"; import { computeDomain } from "../common/entity/compute_domain"; @@ -28,9 +27,9 @@ import type { HomeAssistant, ValueChangedEvent } from "../types"; import type { HaDevicePickerDeviceFilterFunc } from "./device/ha-device-picker"; import "./ha-combo-box"; import type { HaComboBox } from "./ha-combo-box"; +import "./ha-combo-box-item"; import "./ha-floor-icon"; import "./ha-icon-button"; -import "./ha-list-item"; type ScorableFloorRegistryEntry = ScorableTextItem & FloorRegistryEntry; @@ -38,14 +37,12 @@ const ADD_NEW_ID = "___ADD_NEW___"; const NO_FLOORS_ID = "___NO_FLOORS___"; const ADD_NEW_SUGGESTION_ID = "___ADD_NEW_SUGGESTION___"; -const rowRenderer: ComboBoxLitRenderer = (item) => - html` - +const rowRenderer: ComboBoxLitRenderer = (item) => html` + + ${item.name} - `; + +`; @customElement("ha-floor-picker") export class HaFloorPicker extends LitElement { diff --git a/src/components/ha-icon-picker.ts b/src/components/ha-icon-picker.ts index 3d1bb30552..8b7348853d 100644 --- a/src/components/ha-icon-picker.ts +++ b/src/components/ha-icon-picker.ts @@ -11,8 +11,8 @@ import { fireEvent } from "../common/dom/fire_event"; import { customIcons } from "../data/custom_icons"; import type { HomeAssistant, ValueChangedEvent } from "../types"; import "./ha-combo-box"; -import "./ha-list-item"; import "./ha-icon"; +import "./ha-combo-box-item"; interface IconItem { icon: string; @@ -67,11 +67,12 @@ const loadCustomIconItems = async (iconsetPrefix: string) => { } }; -const rowRenderer: ComboBoxLitRenderer = (item) => - html` - +const rowRenderer: ComboBoxLitRenderer = (item) => html` + + ${item.icon} - `; + +`; @customElement("ha-icon-picker") export class HaIconPicker extends LitElement { diff --git a/src/components/ha-label-picker.ts b/src/components/ha-label-picker.ts index be81ed9994..4d941226cc 100644 --- a/src/components/ha-label-picker.ts +++ b/src/components/ha-label-picker.ts @@ -3,7 +3,6 @@ import type { HassEntity, UnsubscribeFunc } from "home-assistant-js-websocket"; import type { PropertyValues, TemplateResult } from "lit"; import { LitElement, html, nothing } from "lit"; import { customElement, property, query, state } from "lit/decorators"; -import { classMap } from "lit/directives/class-map"; import memoizeOne from "memoize-one"; import { fireEvent } from "../common/dom/fire_event"; import { computeDomain } from "../common/entity/compute_domain"; @@ -26,8 +25,8 @@ import type { HomeAssistant, ValueChangedEvent } from "../types"; import type { HaDevicePickerDeviceFilterFunc } from "./device/ha-device-picker"; import "./ha-combo-box"; import type { HaComboBox } from "./ha-combo-box"; +import "./ha-combo-box-item"; import "./ha-icon-button"; -import "./ha-list-item"; import "./ha-svg-icon"; type ScorableLabelItem = ScorableTextItem & LabelRegistryEntry; @@ -36,16 +35,14 @@ const ADD_NEW_ID = "___ADD_NEW___"; const NO_LABELS_ID = "___NO_LABELS___"; const ADD_NEW_SUGGESTION_ID = "___ADD_NEW_SUGGESTION___"; -const rowRenderer: ComboBoxLitRenderer = (item) => - html` +const rowRenderer: ComboBoxLitRenderer = (item) => html` + ${item.icon - ? html`` + ? html`` : nothing} ${item.name} - `; + +`; @customElement("ha-label-picker") export class HaLabelPicker extends SubscribeMixin(LitElement) { diff --git a/src/components/ha-navigation-picker.ts b/src/components/ha-navigation-picker.ts index c89c274144..7740e325f3 100644 --- a/src/components/ha-navigation-picker.ts +++ b/src/components/ha-navigation-picker.ts @@ -1,7 +1,6 @@ -import "@material/mwc-list/mwc-list-item"; import type { ComboBoxLitRenderer } from "@vaadin/combo-box/lit"; import type { PropertyValues, TemplateResult } from "lit"; -import { css, html, LitElement } from "lit"; +import { css, html, LitElement, nothing } from "lit"; import { customElement, property, query, state } from "lit/decorators"; import { fireEvent } from "../common/dom/fire_event"; import { titleCase } from "../common/string/title-case"; @@ -10,6 +9,7 @@ import type { LovelaceViewRawConfig } from "../data/lovelace/config/view"; import type { HomeAssistant, PanelInfo, ValueChangedEvent } from "../types"; import "./ha-combo-box"; import type { HaComboBox } from "./ha-combo-box"; +import "./ha-combo-box-item"; import "./ha-icon"; interface NavigationItem { @@ -21,11 +21,13 @@ interface NavigationItem { const DEFAULT_ITEMS: NavigationItem[] = []; const rowRenderer: ComboBoxLitRenderer = (item) => html` - - - ${item.title || item.path} - ${item.path} - + + + ${item.title || item.path} + ${item.title + ? html`${item.path}` + : nothing} + `; const createViewNavigationItem = ( diff --git a/src/components/ha-service-picker.ts b/src/components/ha-service-picker.ts index 848dde391c..a72a1a463c 100644 --- a/src/components/ha-service-picker.ts +++ b/src/components/ha-service-picker.ts @@ -7,7 +7,7 @@ import type { LocalizeFunc } from "../common/translations/localize"; import { domainToName } from "../data/integration"; import type { HomeAssistant } from "../types"; import "./ha-combo-box"; -import "./ha-list-item"; +import "./ha-combo-box-item"; import "./ha-service-icon"; import { getServiceIcons } from "../data/icons"; @@ -29,18 +29,19 @@ class HaServicePicker extends LitElement { } private _rowRenderer: ComboBoxLitRenderer<{ service: string; name: string }> = - (item) => - html` + (item) => html` + - ${item.name} - ${item.name} + ${item.name === item.service ? "" : item.service} - `; + + `; protected render() { return html` diff --git a/src/panels/config/application_credentials/dialog-add-application-credential.ts b/src/panels/config/application_credentials/dialog-add-application-credential.ts index d1bba908ee..83f55fcb15 100644 --- a/src/panels/config/application_credentials/dialog-add-application-credential.ts +++ b/src/panels/config/application_credentials/dialog-add-application-credential.ts @@ -1,17 +1,15 @@ -import "@material/mwc-list/mwc-list-item"; import { mdiOpenInNew } from "@mdi/js"; -import type { ComboBoxLitRenderer } from "@vaadin/combo-box/lit"; 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-alert"; import "../../../components/ha-button"; -import "../../../components/ha-spinner"; import "../../../components/ha-combo-box"; import { createCloseHeading } from "../../../components/ha-dialog"; import "../../../components/ha-markdown"; import "../../../components/ha-password-field"; +import "../../../components/ha-spinner"; import "../../../components/ha-textfield"; import type { ApplicationCredential, @@ -33,11 +31,6 @@ interface Domain { name: string; } -const rowRenderer: ComboBoxLitRenderer = (item) => - html` - ${item.name} - `; - @customElement("dialog-add-application-credential") export class DialogAddApplicationCredential extends LitElement { @property({ attribute: false }) public hass!: HomeAssistant; @@ -171,7 +164,6 @@ export class DialogAddApplicationCredential extends LitElement { "ui.panel.config.application_credentials.editor.domain" )} .value=${this._domain} - .renderer=${rowRenderer} .items=${this._domains} item-id-path="id" item-value-path="id" diff --git a/src/panels/config/category/ha-category-picker.ts b/src/panels/config/category/ha-category-picker.ts index 25665f9116..9d2247a7af 100644 --- a/src/panels/config/category/ha-category-picker.ts +++ b/src/panels/config/category/ha-category-picker.ts @@ -4,15 +4,14 @@ import type { UnsubscribeFunc } from "home-assistant-js-websocket"; import type { PropertyValues } from "lit"; import { html, LitElement, nothing } from "lit"; import { customElement, property, query, state } from "lit/decorators"; -import { classMap } from "lit/directives/class-map"; import memoizeOne from "memoize-one"; import { fireEvent } from "../../../common/dom/fire_event"; import type { ScorableTextItem } from "../../../common/string/filter/sequence-matching"; import { fuzzyFilterSort } from "../../../common/string/filter/sequence-matching"; import "../../../components/ha-combo-box"; import type { HaComboBox } from "../../../components/ha-combo-box"; +import "../../../components/ha-combo-box-item"; import "../../../components/ha-icon-button"; -import "../../../components/ha-list-item"; import "../../../components/ha-svg-icon"; import type { CategoryRegistryEntry } from "../../../data/category_registry"; import { @@ -29,16 +28,14 @@ const ADD_NEW_ID = "___ADD_NEW___"; const NO_CATEGORIES_ID = "___NO_CATEGORIES___"; const ADD_NEW_SUGGESTION_ID = "___ADD_NEW_SUGGESTION___"; -const rowRenderer: ComboBoxLitRenderer = (item) => - html` +const rowRenderer: ComboBoxLitRenderer = (item) => html` + ${item.icon - ? html`` - : html``} + ? html`` + : html``} ${item.name} - `; + +`; @customElement("ha-category-picker") export class HaCategoryPicker extends SubscribeMixin(LitElement) {