From 3842e8e3a7a2e871d4965752efa9066a8217f9d3 Mon Sep 17 00:00:00 2001 From: Simon Lamon <32477463+silamon@users.noreply.github.com> Date: Mon, 15 Jan 2024 15:59:46 +0100 Subject: [PATCH] Wrap descriptions in automation list descriptions (#19367) * Wrapped automation descriptions * Fix * Fixes --------- Co-authored-by: Bram Kragten --- src/components/ha-list-item-new.ts | 29 +++++++++ src/components/ha-list-new.ts | 24 +++++++ .../add-automation-element-dialog.ts | 64 +++++++++---------- 3 files changed, 83 insertions(+), 34 deletions(-) create mode 100644 src/components/ha-list-item-new.ts create mode 100644 src/components/ha-list-new.ts diff --git a/src/components/ha-list-item-new.ts b/src/components/ha-list-item-new.ts new file mode 100644 index 0000000000..980c28479a --- /dev/null +++ b/src/components/ha-list-item-new.ts @@ -0,0 +1,29 @@ +import { customElement } from "lit/decorators"; +import "element-internals-polyfill"; +import { MdListItem } from "@material/web/list/list-item"; +import { CSSResult, css } from "lit"; + +@customElement("ha-list-item-new") +export class HaListItemNew extends MdListItem { + static get styles(): CSSResult[] { + return [ + ...MdListItem.styles, + css` + :host { + --ha-icon-display: block; + --md-sys-color-primary: var(--primary-text-color); + --md-sys-color-secondary: var(--secondary-text-color); + --md-sys-color-surface: var(--card-background-color); + --md-sys-color-on-surface: var(--primary-text-color); + --md-sys-color-on-surface-variant: var(--secondary-text-color); + } + `, + ]; + } +} + +declare global { + interface HTMLElementTagNameMap { + "ha-list-item-new": HaListItemNew; + } +} diff --git a/src/components/ha-list-new.ts b/src/components/ha-list-new.ts new file mode 100644 index 0000000000..b88ef32e1a --- /dev/null +++ b/src/components/ha-list-new.ts @@ -0,0 +1,24 @@ +import { customElement } from "lit/decorators"; +import "element-internals-polyfill"; +import { MdList } from "@material/web/list/list"; +import { CSSResult, css } from "lit"; + +@customElement("ha-list-new") +export class HaListNew extends MdList { + static get styles(): CSSResult[] { + return [ + ...MdList.styles, + css` + :host { + --md-sys-color-surface: var(--card-background-color); + } + `, + ]; + } +} + +declare global { + interface HTMLElementTagNameMap { + "ha-list-new": HaListNew; + } +} diff --git a/src/panels/config/automation/add-automation-element-dialog.ts b/src/panels/config/automation/add-automation-element-dialog.ts index cf5874f80c..b449952b64 100644 --- a/src/panels/config/automation/add-automation-element-dialog.ts +++ b/src/panels/config/automation/add-automation-element-dialog.ts @@ -16,7 +16,6 @@ import { styleMap } from "lit/directives/style-map"; import memoizeOne from "memoize-one"; import { fireEvent } from "../../../common/dom/fire_event"; import { domainIconWithoutDefault } from "../../../common/entity/domain_icon"; -import { shouldHandleRequestSelectedEvent } from "../../../common/mwc/handle-request-selected-event"; import { stringCompare } from "../../../common/string/compare"; import { LocalizeFunc } from "../../../common/translations/localize"; import "../../../components/ha-dialog"; @@ -25,8 +24,8 @@ import "../../../components/ha-dialog-header"; import "../../../components/ha-icon-button"; import "../../../components/ha-icon-button-prev"; import "../../../components/ha-icon-next"; -import "../../../components/ha-list-item"; -import "../../../components/search-input"; +import "../../../components/ha-list-new"; +import "../../../components/ha-list-item-new"; import { ACTION_GROUPS, ACTION_ICONS, @@ -52,6 +51,8 @@ import { } from "./show-add-automation-element-dialog"; import { computeDomain } from "../../../common/entity/compute_domain"; import { deepEqual } from "../../../common/util/deep-equal"; +import "../../../components/search-input"; +import "@material/web/divider/divider"; const TYPES = { trigger: { groups: TRIGGER_GROUPS, icons: TRIGGER_ICONS }, @@ -433,7 +434,7 @@ class DialogAddAutomationElement extends LitElement implements HassDialog { protected _opened(): void { // Store the width and height so that when we search, box doesn't jump const boundingRect = - this.shadowRoot!.querySelector("mwc-list")?.getBoundingClientRect(); + this.shadowRoot!.querySelector("ha-list-new")?.getBoundingClientRect(); this._width = boundingRect?.width; this._height = boundingRect?.height; } @@ -525,11 +526,8 @@ class DialogAddAutomationElement extends LitElement implements HassDialog { )} > - item.key === this._params!.clipboardItem)) - ? html` ${this.hass.localize( `ui.panel.config.automation.editor.${this._params.type}s.paste` @@ -557,49 +552,48 @@ class DialogAddAutomationElement extends LitElement implements HassDialog { )} - -
  • ` + > + + ` : ""} ${repeat( items, (item) => item.key, (item) => html` - - ${item.name} - ${item.description} +
    ${item.name}
    +
    ${item.description}
    ${item.icon ? html`` : html``} ${item.group - ? html`` + ? html`` : html``} -
    + ` )} -
    + `; } @@ -619,9 +613,6 @@ class DialogAddAutomationElement extends LitElement implements HassDialog { } private _selected(ev) { - if (!shouldHandleRequestSelectedEvent(ev)) { - return; - } this._dialog!.scrollToPos(0, 0); const item = ev.currentTarget; if (item.group) { @@ -654,9 +645,14 @@ class DialogAddAutomationElement extends LitElement implements HassDialog { ha-icon-next { width: 24px; } - mwc-list { + ha-list-new { max-height: 468px; max-width: 100vw; + --md-list-item-leading-space: 24px; + --md-list-item-trailing-space: 24px; + } + ha-list-item-new img { + width: 24px; } search-input { display: block;