mirror of
https://github.com/home-assistant/frontend.git
synced 2025-12-20 10:48:44 +00:00
Generic picker: show a label for area, category, language (#28236)
Co-authored-by: Aidan Timson <aidan@timmo.dev>
This commit is contained in:
@@ -51,6 +51,9 @@ export class HaAreaPicker extends LitElement {
|
|||||||
@property({ type: Boolean, attribute: "no-add" })
|
@property({ type: Boolean, attribute: "no-add" })
|
||||||
public noAdd = false;
|
public noAdd = false;
|
||||||
|
|
||||||
|
@property({ type: Boolean, attribute: "show-label" })
|
||||||
|
public showLabel = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show only areas with entities from specific domains.
|
* Show only areas with entities from specific domains.
|
||||||
* @type {Array}
|
* @type {Array}
|
||||||
@@ -365,9 +368,17 @@ export class HaAreaPicker extends LitElement {
|
|||||||
protected render(): TemplateResult {
|
protected render(): TemplateResult {
|
||||||
const placeholder =
|
const placeholder =
|
||||||
this.placeholder ?? this.hass.localize("ui.components.area-picker.area");
|
this.placeholder ?? this.hass.localize("ui.components.area-picker.area");
|
||||||
|
|
||||||
const valueRenderer = this._computeValueRenderer(this.hass.areas);
|
const valueRenderer = this._computeValueRenderer(this.hass.areas);
|
||||||
|
|
||||||
|
let showLabel = this.showLabel;
|
||||||
|
if (this.value) {
|
||||||
|
const area = this.hass.areas[this.value];
|
||||||
|
if (area) {
|
||||||
|
const { floor } = getAreaContext(area, this.hass.floors);
|
||||||
|
showLabel = !floor && this.showLabel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
<ha-generic-picker
|
<ha-generic-picker
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
@@ -379,6 +390,7 @@ export class HaAreaPicker extends LitElement {
|
|||||||
.disabled=${this.disabled}
|
.disabled=${this.disabled}
|
||||||
.required=${this.required}
|
.required=${this.required}
|
||||||
.placeholder=${placeholder}
|
.placeholder=${placeholder}
|
||||||
|
.showLabel=${showLabel}
|
||||||
.value=${this.value}
|
.value=${this.value}
|
||||||
.getItems=${this._getItems}
|
.getItems=${this._getItems}
|
||||||
.getAdditionalItems=${this._getAdditionalItems}
|
.getAdditionalItems=${this._getAdditionalItems}
|
||||||
|
|||||||
@@ -20,6 +20,17 @@ export class HaComboBoxItem extends HaMdListItem {
|
|||||||
[slot="start"] {
|
[slot="start"] {
|
||||||
--state-icon-color: var(--secondary-text-color);
|
--state-icon-color: var(--secondary-text-color);
|
||||||
}
|
}
|
||||||
|
[slot="overline"] {
|
||||||
|
/* mimicing a floating label of mdc-select */
|
||||||
|
line-height: 1.15rem;
|
||||||
|
font-size: calc(var(--mdc-typography-subtitle1-font-size, 1rem) * 0.75);
|
||||||
|
font-weight: var(--mdc-typography-subtitle1-font-weight, 400);
|
||||||
|
font-family: var(
|
||||||
|
--mdc-typography-subtitle1-font-family,
|
||||||
|
var(--mdc-typography-font-family)
|
||||||
|
);
|
||||||
|
color: var(--mdc-select-label-ink-color, rgba(0, 0, 0, 0.6));
|
||||||
|
}
|
||||||
[slot="headline"] {
|
[slot="headline"] {
|
||||||
line-height: var(--ha-line-height-normal);
|
line-height: var(--ha-line-height-normal);
|
||||||
font-size: var(--ha-font-size-m);
|
font-size: var(--ha-font-size-m);
|
||||||
|
|||||||
@@ -48,6 +48,9 @@ export class HaGenericPicker extends LitElement {
|
|||||||
@property({ attribute: "hide-clear-icon", type: Boolean })
|
@property({ attribute: "hide-clear-icon", type: Boolean })
|
||||||
public hideClearIcon = false;
|
public hideClearIcon = false;
|
||||||
|
|
||||||
|
@property({ attribute: "show-label", type: Boolean })
|
||||||
|
public showLabel = false;
|
||||||
|
|
||||||
/** To prevent lags, getItems needs to be memoized */
|
/** To prevent lags, getItems needs to be memoized */
|
||||||
@property({ attribute: false })
|
@property({ attribute: false })
|
||||||
public getItems!: (
|
public getItems!: (
|
||||||
@@ -170,6 +173,7 @@ export class HaGenericPicker extends LitElement {
|
|||||||
@click=${this.open}
|
@click=${this.open}
|
||||||
@clear=${this._clear}
|
@clear=${this._clear}
|
||||||
.placeholder=${this.placeholder}
|
.placeholder=${this.placeholder}
|
||||||
|
.showLabel=${this.showLabel}
|
||||||
.value=${this.value}
|
.value=${this.value}
|
||||||
.required=${this.required}
|
.required=${this.required}
|
||||||
.disabled=${this.disabled}
|
.disabled=${this.disabled}
|
||||||
|
|||||||
@@ -132,6 +132,7 @@ export class HaLanguagePicker extends LitElement {
|
|||||||
.placeholder=${this.label ??
|
.placeholder=${this.label ??
|
||||||
(this.hass?.localize("ui.components.language-picker.language") ||
|
(this.hass?.localize("ui.components.language-picker.language") ||
|
||||||
"Language")}
|
"Language")}
|
||||||
|
show-label
|
||||||
.value=${value}
|
.value=${value}
|
||||||
.valueRenderer=${this._valueRenderer}
|
.valueRenderer=${this._valueRenderer}
|
||||||
.disabled=${this.disabled}
|
.disabled=${this.disabled}
|
||||||
|
|||||||
@@ -43,6 +43,9 @@ export class HaPickerField extends LitElement {
|
|||||||
@property({ attribute: "hide-clear-icon", type: Boolean })
|
@property({ attribute: "hide-clear-icon", type: Boolean })
|
||||||
public hideClearIcon = false;
|
public hideClearIcon = false;
|
||||||
|
|
||||||
|
@property({ attribute: "show-label", type: Boolean })
|
||||||
|
public showLabel = false;
|
||||||
|
|
||||||
@property({ attribute: false })
|
@property({ attribute: false })
|
||||||
public valueRenderer?: PickerValueRenderer;
|
public valueRenderer?: PickerValueRenderer;
|
||||||
|
|
||||||
@@ -60,13 +63,16 @@ export class HaPickerField extends LitElement {
|
|||||||
protected render() {
|
protected render() {
|
||||||
const showClearIcon =
|
const showClearIcon =
|
||||||
!!this.value && !this.required && !this.disabled && !this.hideClearIcon;
|
!!this.value && !this.required && !this.disabled && !this.hideClearIcon;
|
||||||
|
const placeholder = this.showLabel
|
||||||
|
? html`<span slot="overline">${this.placeholder}</span>`
|
||||||
|
: nothing;
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
<ha-combo-box-item .disabled=${this.disabled} type="button" compact>
|
<ha-combo-box-item .disabled=${this.disabled} type="button" compact>
|
||||||
${this.value
|
${this.value
|
||||||
? this.valueRenderer
|
? this.valueRenderer
|
||||||
? this.valueRenderer(this.value)
|
? html`${placeholder}${this.valueRenderer(this.value)}`
|
||||||
: html`<slot name="headline">${this.value}</slot>`
|
: html`${placeholder}<span slot="headline">${this.value}</span>`
|
||||||
: html`
|
: html`
|
||||||
<span slot="headline" class="placeholder">
|
<span slot="headline" class="placeholder">
|
||||||
${this.placeholder}
|
${this.placeholder}
|
||||||
|
|||||||
@@ -177,6 +177,7 @@ class DialogAutomationSave extends LitElement implements HassDialog {
|
|||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.scope=${this._params.domain}
|
.scope=${this._params.domain}
|
||||||
.value=${this._entryUpdates.category}
|
.value=${this._entryUpdates.category}
|
||||||
|
show-label
|
||||||
@value-changed=${this._registryEntryChanged}
|
@value-changed=${this._registryEntryChanged}
|
||||||
></ha-category-picker>`
|
></ha-category-picker>`
|
||||||
: nothing}
|
: nothing}
|
||||||
@@ -193,6 +194,7 @@ class DialogAutomationSave extends LitElement implements HassDialog {
|
|||||||
id="area"
|
id="area"
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.value=${this._entryUpdates.area}
|
.value=${this._entryUpdates.area}
|
||||||
|
show-label
|
||||||
@value-changed=${this._registryEntryChanged}
|
@value-changed=${this._registryEntryChanged}
|
||||||
></ha-area-picker>`
|
></ha-area-picker>`
|
||||||
: nothing}
|
: nothing}
|
||||||
|
|||||||
@@ -39,6 +39,9 @@ export class HaCategoryPicker extends SubscribeMixin(LitElement) {
|
|||||||
@property({ type: Boolean, attribute: "no-add" })
|
@property({ type: Boolean, attribute: "no-add" })
|
||||||
public noAdd = false;
|
public noAdd = false;
|
||||||
|
|
||||||
|
@property({ type: Boolean, attribute: "show-label" })
|
||||||
|
public showLabel = false;
|
||||||
|
|
||||||
@property({ type: Boolean }) public disabled = false;
|
@property({ type: Boolean }) public disabled = false;
|
||||||
|
|
||||||
@property({ type: Boolean }) public required = false;
|
@property({ type: Boolean }) public required = false;
|
||||||
@@ -196,6 +199,7 @@ export class HaCategoryPicker extends SubscribeMixin(LitElement) {
|
|||||||
"ui.components.category-picker.no_categories"
|
"ui.components.category-picker.no_categories"
|
||||||
)}
|
)}
|
||||||
.placeholder=${placeholder}
|
.placeholder=${placeholder}
|
||||||
|
.showLabel=${this.showLabel}
|
||||||
.value=${this.value}
|
.value=${this.value}
|
||||||
.getItems=${this._getItems}
|
.getItems=${this._getItems}
|
||||||
.getAdditionalItems=${this._getAdditionalItems}
|
.getAdditionalItems=${this._getAdditionalItems}
|
||||||
|
|||||||
@@ -80,6 +80,7 @@ class DialogDeviceRegistryDetail extends LitElement {
|
|||||||
<ha-area-picker
|
<ha-area-picker
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.value=${this._areaId}
|
.value=${this._areaId}
|
||||||
|
show-label
|
||||||
@value-changed=${this._areaPicked}
|
@value-changed=${this._areaPicked}
|
||||||
></ha-area-picker>
|
></ha-area-picker>
|
||||||
<ha-labels-picker
|
<ha-labels-picker
|
||||||
|
|||||||
@@ -778,6 +778,7 @@ export class EntityRegistrySettingsEditor extends LitElement {
|
|||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.value=${this._areaId}
|
.value=${this._areaId}
|
||||||
.disabled=${this.disabled}
|
.disabled=${this.disabled}
|
||||||
|
show-label
|
||||||
@value-changed=${this._areaPicked}
|
@value-changed=${this._areaPicked}
|
||||||
></ha-area-picker>`
|
></ha-area-picker>`
|
||||||
: ""}
|
: ""}
|
||||||
@@ -1012,6 +1013,7 @@ export class EntityRegistrySettingsEditor extends LitElement {
|
|||||||
? html`<ha-area-picker
|
? html`<ha-area-picker
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.value=${this._areaId}
|
.value=${this._areaId}
|
||||||
|
show-label
|
||||||
.disabled=${this.disabled}
|
.disabled=${this.disabled}
|
||||||
@value-changed=${this._areaPicked}
|
@value-changed=${this._areaPicked}
|
||||||
></ha-area-picker>`
|
></ha-area-picker>`
|
||||||
|
|||||||
Reference in New Issue
Block a user