Skip to content

Commit 39c2bee

Browse files
committed
Render entity labels as badges
1 parent cf35543 commit 39c2bee

1 file changed

Lines changed: 43 additions & 7 deletions

File tree

src/dialogs/more-info/ha-more-info-details.ts

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import "../../components/ha-attribute-value";
1515
import "../../components/ha-floor-icon";
1616
import "../../components/ha-icon";
1717
import "../../components/ha-icon-next";
18+
import "../../components/ha-label";
1819
import "../../components/ha-svg-icon";
1920
import "../../components/item/ha-list-item-button";
2021
import "../../components/item/ha-list-item-value";
@@ -42,6 +43,7 @@ interface DetailsViewParams {
4243
interface DetailEntry {
4344
translationKey: LocalizeKeys;
4445
value: string;
46+
displayValue?: TemplateResult;
4547
href?: string;
4648
icon?: TemplateResult;
4749
copyable?: boolean;
@@ -104,12 +106,12 @@ class HaMoreInfoDetails extends LitElement {
104106
? this.hass.localize(`component.${this.entry.platform}.title`) ||
105107
this.entry.platform
106108
: undefined;
107-
const labelNames =
108-
this.entry?.labels.map(
109-
(labelId) =>
110-
this._labels?.find((label) => label.label_id === labelId)?.name ??
111-
labelId
112-
) ?? [];
109+
const labels =
110+
this.entry?.labels.map((labelId) => ({
111+
id: labelId,
112+
entry: this._labels?.find((label) => label.label_id === labelId),
113+
})) ?? [];
114+
const labelNames = labels.map(({ id, entry }) => entry?.name ?? id);
113115
const contextEntries: DetailEntry[] = [];
114116

115117
if (floor && floorName) {
@@ -171,6 +173,28 @@ class HaMoreInfoDetails extends LitElement {
171173
{
172174
translationKey: "ui.dialogs.more_info_control.labels",
173175
value: labelNames.join(", ") || this.hass.localize("ui.common.none"),
176+
displayValue: labels.length
177+
? html`<div class="labels">
178+
${labels.map(
179+
({ id, entry }) => html`
180+
<ha-label
181+
.color=${entry?.color ?? undefined}
182+
.description=${entry?.description ?? undefined}
183+
>
184+
${
185+
entry?.icon
186+
? html`<ha-icon
187+
slot="icon"
188+
.icon=${entry.icon}
189+
></ha-icon>`
190+
: nothing
191+
}
192+
${entry?.name ?? id}
193+
</ha-label>
194+
`
195+
)}
196+
</div>`
197+
: undefined,
174198
}
175199
);
176200
const yamlData = {
@@ -299,7 +323,7 @@ class HaMoreInfoDetails extends LitElement {
299323
if (!entry.href && !entry.copyable) {
300324
return html`
301325
<ha-list-item-value .label=${label}
302-
>${entry.value}</ha-list-item-value
326+
>${entry.displayValue ?? entry.value}</ha-list-item-value
303327
>
304328
`;
305329
}
@@ -443,6 +467,18 @@ class HaMoreInfoDetails extends LitElement {
443467
overflow-wrap: anywhere;
444468
}
445469
470+
.labels {
471+
display: flex;
472+
justify-content: flex-end;
473+
flex-wrap: wrap;
474+
gap: var(--ha-space-1);
475+
}
476+
477+
.labels ha-label {
478+
min-width: 0;
479+
max-width: 100%;
480+
}
481+
446482
ha-icon-next {
447483
color: var(--secondary-text-color);
448484
}

0 commit comments

Comments
 (0)