mirror of
https://github.com/home-assistant/frontend.git
synced 2025-11-08 10:29:37 +00:00
Improve labels picker
This commit is contained in:
@@ -96,33 +96,38 @@ export class HaGenericPicker extends LitElement {
|
|||||||
? html`<label ?disabled=${this.disabled}>${this.label}</label>`
|
? html`<label ?disabled=${this.disabled}>${this.label}</label>`
|
||||||
: nothing}
|
: nothing}
|
||||||
<div class="container">
|
<div class="container">
|
||||||
${this.addButtonLabel && !this.value
|
<div id="picker">
|
||||||
? html`<ha-button
|
<slot name="field">
|
||||||
id="picker"
|
${this.addButtonLabel && !this.value
|
||||||
size="small"
|
? html`<ha-button
|
||||||
appearance="filled"
|
size="small"
|
||||||
@click=${this.open}
|
appearance="filled"
|
||||||
.disabled=${this.disabled}
|
@click=${this.open}
|
||||||
>
|
.disabled=${this.disabled}
|
||||||
<ha-svg-icon .path=${mdiPlaylistPlus} slot="start"></ha-svg-icon>
|
>
|
||||||
${this.addButtonLabel}
|
<ha-svg-icon
|
||||||
</ha-button>`
|
.path=${mdiPlaylistPlus}
|
||||||
: html`<ha-picker-field
|
slot="start"
|
||||||
id="picker"
|
></ha-svg-icon>
|
||||||
type="button"
|
${this.addButtonLabel}
|
||||||
class=${this._opened ? "opened" : ""}
|
</ha-button>`
|
||||||
compact
|
: html`<ha-picker-field
|
||||||
aria-label=${ifDefined(this.label)}
|
type="button"
|
||||||
@click=${this.open}
|
class=${this._opened ? "opened" : ""}
|
||||||
@clear=${this._clear}
|
compact
|
||||||
.placeholder=${this.placeholder}
|
aria-label=${ifDefined(this.label)}
|
||||||
.value=${this.value}
|
@click=${this.open}
|
||||||
.required=${this.required}
|
@clear=${this._clear}
|
||||||
.disabled=${this.disabled}
|
.placeholder=${this.placeholder}
|
||||||
.hideClearIcon=${this.hideClearIcon}
|
.value=${this.value}
|
||||||
.valueRenderer=${this.valueRenderer}
|
.required=${this.required}
|
||||||
>
|
.disabled=${this.disabled}
|
||||||
</ha-picker-field>`}
|
.hideClearIcon=${this.hideClearIcon}
|
||||||
|
.valueRenderer=${this.valueRenderer}
|
||||||
|
>
|
||||||
|
</ha-picker-field>`}
|
||||||
|
</slot>
|
||||||
|
</div>
|
||||||
${!this._openedNarrow && (this._pickerWrapperOpen || this._opened)
|
${!this._openedNarrow && (this._pickerWrapperOpen || this._opened)
|
||||||
? html`
|
? html`
|
||||||
<wa-popover
|
<wa-popover
|
||||||
@@ -234,7 +239,8 @@ export class HaGenericPicker extends LitElement {
|
|||||||
fireEvent(this, "value-changed", { value });
|
fireEvent(this, "value-changed", { value });
|
||||||
}
|
}
|
||||||
|
|
||||||
public async open() {
|
public async open(ev?: Event) {
|
||||||
|
ev?.stopPropagation();
|
||||||
if (this.disabled) {
|
if (this.disabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,13 @@ import { mdiLabel, mdiPlus } from "@mdi/js";
|
|||||||
import type { HassEntity, UnsubscribeFunc } from "home-assistant-js-websocket";
|
import type { HassEntity, UnsubscribeFunc } from "home-assistant-js-websocket";
|
||||||
import type { TemplateResult } from "lit";
|
import type { TemplateResult } from "lit";
|
||||||
import { LitElement, html } from "lit";
|
import { LitElement, html } from "lit";
|
||||||
import { customElement, property, query, state } from "lit/decorators";
|
import {
|
||||||
|
customElement,
|
||||||
|
property,
|
||||||
|
query,
|
||||||
|
queryAssignedElements,
|
||||||
|
state,
|
||||||
|
} from "lit/decorators";
|
||||||
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 type { LabelRegistryEntry } from "../data/label_registry";
|
import type { LabelRegistryEntry } from "../data/label_registry";
|
||||||
@@ -84,6 +90,9 @@ export class HaLabelPicker extends SubscribeMixin(LitElement) {
|
|||||||
|
|
||||||
@state() private _labels?: LabelRegistryEntry[];
|
@state() private _labels?: LabelRegistryEntry[];
|
||||||
|
|
||||||
|
@queryAssignedElements({ flatten: true })
|
||||||
|
private _slotNodes?: NodeListOf<HTMLElement>;
|
||||||
|
|
||||||
@query("ha-generic-picker") private _picker?: HaGenericPicker;
|
@query("ha-generic-picker") private _picker?: HaGenericPicker;
|
||||||
|
|
||||||
public async open() {
|
public async open() {
|
||||||
@@ -226,6 +235,7 @@ export class HaLabelPicker extends SubscribeMixin(LitElement) {
|
|||||||
.valueRenderer=${valueRenderer}
|
.valueRenderer=${valueRenderer}
|
||||||
@value-changed=${this._valueChanged}
|
@value-changed=${this._valueChanged}
|
||||||
>
|
>
|
||||||
|
<slot .slot=${this._slotNodes?.length ? "field" : undefined}></slot>
|
||||||
</ha-generic-picker>
|
</ha-generic-picker>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { mdiPlaylistPlus } from "@mdi/js";
|
||||||
import type { HassEntity, UnsubscribeFunc } from "home-assistant-js-websocket";
|
import type { HassEntity, UnsubscribeFunc } from "home-assistant-js-websocket";
|
||||||
import type { TemplateResult } from "lit";
|
import type { TemplateResult } from "lit";
|
||||||
import { LitElement, css, html, nothing } from "lit";
|
import { LitElement, css, html, nothing } from "lit";
|
||||||
@@ -123,42 +124,6 @@ export class HaLabelsPicker extends SubscribeMixin(LitElement) {
|
|||||||
);
|
);
|
||||||
return html`
|
return html`
|
||||||
${this.label ? html`<label>${this.label}</label>` : nothing}
|
${this.label ? html`<label>${this.label}</label>` : nothing}
|
||||||
<ha-chip-set
|
|
||||||
@click=${this._openPicker}
|
|
||||||
class=${!labels?.length ? "clickable" : ""}
|
|
||||||
>
|
|
||||||
${labels?.length
|
|
||||||
? repeat(
|
|
||||||
labels,
|
|
||||||
(label) => label?.label_id,
|
|
||||||
(label) => {
|
|
||||||
const color = label?.color
|
|
||||||
? computeCssColor(label.color)
|
|
||||||
: undefined;
|
|
||||||
return html`
|
|
||||||
<ha-input-chip
|
|
||||||
.item=${label}
|
|
||||||
@remove=${this._removeItem}
|
|
||||||
@click=${this._openDetail}
|
|
||||||
.disabled=${this.disabled}
|
|
||||||
.label=${label?.name}
|
|
||||||
selected
|
|
||||||
style=${color ? `--color: ${color}` : ""}
|
|
||||||
>
|
|
||||||
${label?.icon
|
|
||||||
? html`<ha-icon
|
|
||||||
slot="icon"
|
|
||||||
.icon=${label.icon}
|
|
||||||
></ha-icon>`
|
|
||||||
: nothing}
|
|
||||||
</ha-input-chip>
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
)
|
|
||||||
: html`<div class="placeholder">
|
|
||||||
${this.hass.localize("ui.components.label-picker.labels")}
|
|
||||||
</div>`}
|
|
||||||
</ha-chip-set>
|
|
||||||
<ha-label-picker
|
<ha-label-picker
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.helper=${this.helper}
|
.helper=${this.helper}
|
||||||
@@ -168,6 +133,47 @@ export class HaLabelsPicker extends SubscribeMixin(LitElement) {
|
|||||||
.excludeLabels=${this.value}
|
.excludeLabels=${this.value}
|
||||||
@value-changed=${this._labelChanged}
|
@value-changed=${this._labelChanged}
|
||||||
>
|
>
|
||||||
|
<ha-chip-set>
|
||||||
|
${labels?.length
|
||||||
|
? repeat(
|
||||||
|
labels,
|
||||||
|
(label) => label?.label_id,
|
||||||
|
(label) => {
|
||||||
|
const color = label?.color
|
||||||
|
? computeCssColor(label.color)
|
||||||
|
: undefined;
|
||||||
|
return html`
|
||||||
|
<ha-input-chip
|
||||||
|
.item=${label}
|
||||||
|
@remove=${this._removeItem}
|
||||||
|
@click=${this._openDetail}
|
||||||
|
.disabled=${this.disabled}
|
||||||
|
.label=${label?.name}
|
||||||
|
selected
|
||||||
|
style=${color ? `--color: ${color}` : ""}
|
||||||
|
>
|
||||||
|
${label?.icon
|
||||||
|
? html`<ha-icon
|
||||||
|
slot="icon"
|
||||||
|
.icon=${label.icon}
|
||||||
|
></ha-icon>`
|
||||||
|
: nothing}
|
||||||
|
</ha-input-chip>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
)
|
||||||
|
: nothing}
|
||||||
|
<ha-button
|
||||||
|
id="picker"
|
||||||
|
size="small"
|
||||||
|
appearance="filled"
|
||||||
|
@click=${this._openPicker}
|
||||||
|
.disabled=${this.disabled}
|
||||||
|
>
|
||||||
|
<ha-svg-icon .path=${mdiPlaylistPlus} slot="start"></ha-svg-icon>
|
||||||
|
${this.hass.localize("ui.components.label-picker.add")}
|
||||||
|
</ha-button>
|
||||||
|
</ha-chip-set>
|
||||||
</ha-label-picker>
|
</ha-label-picker>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
@@ -210,15 +216,8 @@ export class HaLabelsPicker extends SubscribeMixin(LitElement) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _openPicker(ev: Event) {
|
private _openPicker(ev: Event) {
|
||||||
const labels = this._sortedLabels(
|
ev.stopPropagation();
|
||||||
this.value,
|
this.labelPicker.open();
|
||||||
this._labels,
|
|
||||||
this.hass.locale.language
|
|
||||||
);
|
|
||||||
if (!labels?.length) {
|
|
||||||
ev.stopPropagation();
|
|
||||||
this.labelPicker.open();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static styles = css`
|
static styles = css`
|
||||||
@@ -230,9 +229,6 @@ export class HaLabelsPicker extends SubscribeMixin(LitElement) {
|
|||||||
border-top-left-radius: var(--ha-border-radius-sm);
|
border-top-left-radius: var(--ha-border-radius-sm);
|
||||||
padding: var(--ha-space-3);
|
padding: var(--ha-space-3);
|
||||||
}
|
}
|
||||||
ha-chip-set.clickable {
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
.placeholder {
|
.placeholder {
|
||||||
color: var(--mdc-text-field-label-ink-color);
|
color: var(--mdc-text-field-label-ink-color);
|
||||||
display: flex;
|
display: flex;
|
||||||
|
|||||||
@@ -1,34 +1,34 @@
|
|||||||
|
import type { HassEntity } from "home-assistant-js-websocket";
|
||||||
import type { CSSResultGroup } from "lit";
|
import type { CSSResultGroup } from "lit";
|
||||||
import { css, html, LitElement, nothing } from "lit";
|
import { css, html, LitElement, nothing } from "lit";
|
||||||
import { property, state } from "lit/decorators";
|
import { property, state } from "lit/decorators";
|
||||||
import type { HassEntity } from "home-assistant-js-websocket";
|
|
||||||
import { fireEvent } from "../../../common/dom/fire_event";
|
import { fireEvent } from "../../../common/dom/fire_event";
|
||||||
|
import "../../../components/entity/ha-entity-picker";
|
||||||
|
import type { HaEntityPicker } from "../../../components/entity/ha-entity-picker";
|
||||||
import "../../../components/ha-alert";
|
import "../../../components/ha-alert";
|
||||||
import "../../../components/ha-aliases-editor";
|
import "../../../components/ha-aliases-editor";
|
||||||
|
import { createCloseHeading } from "../../../components/ha-dialog";
|
||||||
|
import "../../../components/ha-floor-picker";
|
||||||
|
import "../../../components/ha-icon-picker";
|
||||||
|
import "../../../components/ha-labels-picker";
|
||||||
import "../../../components/ha-picture-upload";
|
import "../../../components/ha-picture-upload";
|
||||||
import type { HaPictureUpload } from "../../../components/ha-picture-upload";
|
import type { HaPictureUpload } from "../../../components/ha-picture-upload";
|
||||||
import "../../../components/ha-settings-row";
|
import "../../../components/ha-settings-row";
|
||||||
import "../../../components/ha-icon-picker";
|
|
||||||
import "../../../components/ha-floor-picker";
|
|
||||||
import "../../../components/entity/ha-entity-picker";
|
|
||||||
import type { HaEntityPicker } from "../../../components/entity/ha-entity-picker";
|
|
||||||
import "../../../components/ha-textfield";
|
import "../../../components/ha-textfield";
|
||||||
import "../../../components/ha-labels-picker";
|
|
||||||
import type {
|
import type {
|
||||||
AreaRegistryEntry,
|
AreaRegistryEntry,
|
||||||
AreaRegistryEntryMutableParams,
|
AreaRegistryEntryMutableParams,
|
||||||
} from "../../../data/area_registry";
|
} from "../../../data/area_registry";
|
||||||
import { deleteAreaRegistryEntry } from "../../../data/area_registry";
|
import { deleteAreaRegistryEntry } from "../../../data/area_registry";
|
||||||
import type { CropOptions } from "../../../dialogs/image-cropper-dialog/show-image-cropper-dialog";
|
|
||||||
import { haStyleDialog } from "../../../resources/styles";
|
|
||||||
import type { HomeAssistant, ValueChangedEvent } from "../../../types";
|
|
||||||
import type { AreaRegistryDetailDialogParams } from "./show-dialog-area-registry-detail";
|
|
||||||
import {
|
import {
|
||||||
SENSOR_DEVICE_CLASS_HUMIDITY,
|
SENSOR_DEVICE_CLASS_HUMIDITY,
|
||||||
SENSOR_DEVICE_CLASS_TEMPERATURE,
|
SENSOR_DEVICE_CLASS_TEMPERATURE,
|
||||||
} from "../../../data/sensor";
|
} from "../../../data/sensor";
|
||||||
import { showConfirmationDialog } from "../../../dialogs/generic/show-dialog-box";
|
import { showConfirmationDialog } from "../../../dialogs/generic/show-dialog-box";
|
||||||
import { createCloseHeading } from "../../../components/ha-dialog";
|
import type { CropOptions } from "../../../dialogs/image-cropper-dialog/show-image-cropper-dialog";
|
||||||
|
import { haStyleDialog } from "../../../resources/styles";
|
||||||
|
import type { HomeAssistant, ValueChangedEvent } from "../../../types";
|
||||||
|
import type { AreaRegistryDetailDialogParams } from "./show-dialog-area-registry-detail";
|
||||||
|
|
||||||
const cropOptions: CropOptions = {
|
const cropOptions: CropOptions = {
|
||||||
round: false,
|
round: false,
|
||||||
@@ -139,6 +139,7 @@ class DialogAreaDetail extends LitElement {
|
|||||||
></ha-floor-picker>
|
></ha-floor-picker>
|
||||||
|
|
||||||
<ha-labels-picker
|
<ha-labels-picker
|
||||||
|
.label=${this.hass.localize("ui.components.label-picker.labels")}
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.value=${this._labels}
|
.value=${this._labels}
|
||||||
@value-changed=${this._labelsChanged}
|
@value-changed=${this._labelsChanged}
|
||||||
|
|||||||
Reference in New Issue
Block a user