mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +00:00
Wrap descriptions in automation list descriptions (#19367)
* Wrapped automation descriptions * Fix * Fixes --------- Co-authored-by: Bram Kragten <mail@bramkragten.nl>
This commit is contained in:
parent
b881a2a88a
commit
3842e8e3a7
29
src/components/ha-list-item-new.ts
Normal file
29
src/components/ha-list-item-new.ts
Normal file
@ -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;
|
||||||
|
}
|
||||||
|
}
|
24
src/components/ha-list-new.ts
Normal file
24
src/components/ha-list-new.ts
Normal file
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -16,7 +16,6 @@ import { styleMap } from "lit/directives/style-map";
|
|||||||
import memoizeOne from "memoize-one";
|
import memoizeOne from "memoize-one";
|
||||||
import { fireEvent } from "../../../common/dom/fire_event";
|
import { fireEvent } from "../../../common/dom/fire_event";
|
||||||
import { domainIconWithoutDefault } from "../../../common/entity/domain_icon";
|
import { domainIconWithoutDefault } from "../../../common/entity/domain_icon";
|
||||||
import { shouldHandleRequestSelectedEvent } from "../../../common/mwc/handle-request-selected-event";
|
|
||||||
import { stringCompare } from "../../../common/string/compare";
|
import { stringCompare } from "../../../common/string/compare";
|
||||||
import { LocalizeFunc } from "../../../common/translations/localize";
|
import { LocalizeFunc } from "../../../common/translations/localize";
|
||||||
import "../../../components/ha-dialog";
|
import "../../../components/ha-dialog";
|
||||||
@ -25,8 +24,8 @@ import "../../../components/ha-dialog-header";
|
|||||||
import "../../../components/ha-icon-button";
|
import "../../../components/ha-icon-button";
|
||||||
import "../../../components/ha-icon-button-prev";
|
import "../../../components/ha-icon-button-prev";
|
||||||
import "../../../components/ha-icon-next";
|
import "../../../components/ha-icon-next";
|
||||||
import "../../../components/ha-list-item";
|
import "../../../components/ha-list-new";
|
||||||
import "../../../components/search-input";
|
import "../../../components/ha-list-item-new";
|
||||||
import {
|
import {
|
||||||
ACTION_GROUPS,
|
ACTION_GROUPS,
|
||||||
ACTION_ICONS,
|
ACTION_ICONS,
|
||||||
@ -52,6 +51,8 @@ import {
|
|||||||
} from "./show-add-automation-element-dialog";
|
} from "./show-add-automation-element-dialog";
|
||||||
import { computeDomain } from "../../../common/entity/compute_domain";
|
import { computeDomain } from "../../../common/entity/compute_domain";
|
||||||
import { deepEqual } from "../../../common/util/deep-equal";
|
import { deepEqual } from "../../../common/util/deep-equal";
|
||||||
|
import "../../../components/search-input";
|
||||||
|
import "@material/web/divider/divider";
|
||||||
|
|
||||||
const TYPES = {
|
const TYPES = {
|
||||||
trigger: { groups: TRIGGER_GROUPS, icons: TRIGGER_ICONS },
|
trigger: { groups: TRIGGER_GROUPS, icons: TRIGGER_ICONS },
|
||||||
@ -433,7 +434,7 @@ class DialogAddAutomationElement extends LitElement implements HassDialog {
|
|||||||
protected _opened(): void {
|
protected _opened(): void {
|
||||||
// Store the width and height so that when we search, box doesn't jump
|
// Store the width and height so that when we search, box doesn't jump
|
||||||
const boundingRect =
|
const boundingRect =
|
||||||
this.shadowRoot!.querySelector("mwc-list")?.getBoundingClientRect();
|
this.shadowRoot!.querySelector("ha-list-new")?.getBoundingClientRect();
|
||||||
this._width = boundingRect?.width;
|
this._width = boundingRect?.width;
|
||||||
this._height = boundingRect?.height;
|
this._height = boundingRect?.height;
|
||||||
}
|
}
|
||||||
@ -525,11 +526,8 @@ class DialogAddAutomationElement extends LitElement implements HassDialog {
|
|||||||
)}
|
)}
|
||||||
></search-input>
|
></search-input>
|
||||||
</div>
|
</div>
|
||||||
<mwc-list
|
<ha-list-new
|
||||||
dialogInitialFocus=${ifDefined(this._fullScreen ? "" : undefined)}
|
dialogInitialFocus=${ifDefined(this._fullScreen ? "" : undefined)}
|
||||||
innerRole="listbox"
|
|
||||||
itemRoles="option"
|
|
||||||
rootTabbable
|
|
||||||
style=${styleMap({
|
style=${styleMap({
|
||||||
width: this._width ? `${this._width}px` : "auto",
|
width: this._width ? `${this._width}px` : "auto",
|
||||||
height: this._height ? `${Math.min(468, this._height)}px` : "auto",
|
height: this._height ? `${Math.min(468, this._height)}px` : "auto",
|
||||||
@ -539,13 +537,10 @@ class DialogAddAutomationElement extends LitElement implements HassDialog {
|
|||||||
!this._filter &&
|
!this._filter &&
|
||||||
(!this._group ||
|
(!this._group ||
|
||||||
items.find((item) => item.key === this._params!.clipboardItem))
|
items.find((item) => item.key === this._params!.clipboardItem))
|
||||||
? html`<ha-list-item
|
? html`<ha-list-item-new
|
||||||
twoline
|
|
||||||
class="paste"
|
class="paste"
|
||||||
.value=${PASTE_VALUE}
|
.value=${PASTE_VALUE}
|
||||||
graphic="icon"
|
@click=${this._selected}
|
||||||
hasMeta
|
|
||||||
@request-selected=${this._selected}
|
|
||||||
>
|
>
|
||||||
${this.hass.localize(
|
${this.hass.localize(
|
||||||
`ui.panel.config.automation.editor.${this._params.type}s.paste`
|
`ui.panel.config.automation.editor.${this._params.type}s.paste`
|
||||||
@ -557,49 +552,48 @@ class DialogAddAutomationElement extends LitElement implements HassDialog {
|
|||||||
)}</span
|
)}</span
|
||||||
>
|
>
|
||||||
<ha-svg-icon
|
<ha-svg-icon
|
||||||
slot="graphic"
|
slot="start"
|
||||||
.path=${mdiContentPaste}
|
.path=${mdiContentPaste}
|
||||||
></ha-svg-icon
|
></ha-svg-icon
|
||||||
><ha-svg-icon slot="meta" .path=${mdiPlus}></ha-svg-icon>
|
><ha-svg-icon slot="end" .path=${mdiPlus}></ha-svg-icon>
|
||||||
</ha-list-item>
|
</ha-list-item-new>
|
||||||
<li divider role="separator"></li>`
|
<md-divider></md-divider>`
|
||||||
: ""}
|
: ""}
|
||||||
${repeat(
|
${repeat(
|
||||||
items,
|
items,
|
||||||
(item) => item.key,
|
(item) => item.key,
|
||||||
(item) => html`
|
(item) => html`
|
||||||
<ha-list-item
|
<ha-list-item-new
|
||||||
.twoline=${Boolean(item.description)}
|
interactive
|
||||||
|
type="button"
|
||||||
.value=${item.key}
|
.value=${item.key}
|
||||||
.group=${item.group}
|
.group=${item.group}
|
||||||
graphic="icon"
|
@click=${this._selected}
|
||||||
hasMeta
|
|
||||||
@request-selected=${this._selected}
|
|
||||||
>
|
>
|
||||||
${item.name}
|
<div slot="headline">${item.name}</div>
|
||||||
<span slot="secondary">${item.description}</span>
|
<div slot="supporting-text">${item.description}</div>
|
||||||
${item.icon
|
${item.icon
|
||||||
? html`<ha-svg-icon
|
? html`<ha-svg-icon
|
||||||
slot="graphic"
|
slot="start"
|
||||||
.path=${item.icon}
|
.path=${item.icon}
|
||||||
></ha-svg-icon>`
|
></ha-svg-icon>`
|
||||||
: html`<img
|
: html`<img
|
||||||
alt=""
|
alt=""
|
||||||
slot="graphic"
|
slot="start"
|
||||||
src=${item.image}
|
src=${item.image}
|
||||||
crossorigin="anonymous"
|
crossorigin="anonymous"
|
||||||
referrerpolicy="no-referrer"
|
referrerpolicy="no-referrer"
|
||||||
/>`}
|
/>`}
|
||||||
${item.group
|
${item.group
|
||||||
? html`<ha-icon-next slot="meta"></ha-icon-next>`
|
? html`<ha-icon-next slot="end"></ha-icon-next>`
|
||||||
: html`<ha-svg-icon
|
: html`<ha-svg-icon
|
||||||
slot="meta"
|
slot="end"
|
||||||
.path=${mdiPlus}
|
.path=${mdiPlus}
|
||||||
></ha-svg-icon>`}
|
></ha-svg-icon>`}
|
||||||
</ha-list-item>
|
</ha-list-item-new>
|
||||||
`
|
`
|
||||||
)}
|
)}
|
||||||
</mwc-list>
|
</ha-list-new>
|
||||||
</ha-dialog>
|
</ha-dialog>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
@ -619,9 +613,6 @@ class DialogAddAutomationElement extends LitElement implements HassDialog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _selected(ev) {
|
private _selected(ev) {
|
||||||
if (!shouldHandleRequestSelectedEvent(ev)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this._dialog!.scrollToPos(0, 0);
|
this._dialog!.scrollToPos(0, 0);
|
||||||
const item = ev.currentTarget;
|
const item = ev.currentTarget;
|
||||||
if (item.group) {
|
if (item.group) {
|
||||||
@ -654,9 +645,14 @@ class DialogAddAutomationElement extends LitElement implements HassDialog {
|
|||||||
ha-icon-next {
|
ha-icon-next {
|
||||||
width: 24px;
|
width: 24px;
|
||||||
}
|
}
|
||||||
mwc-list {
|
ha-list-new {
|
||||||
max-height: 468px;
|
max-height: 468px;
|
||||||
max-width: 100vw;
|
max-width: 100vw;
|
||||||
|
--md-list-item-leading-space: 24px;
|
||||||
|
--md-list-item-trailing-space: 24px;
|
||||||
|
}
|
||||||
|
ha-list-item-new img {
|
||||||
|
width: 24px;
|
||||||
}
|
}
|
||||||
search-input {
|
search-input {
|
||||||
display: block;
|
display: block;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user