Use slot for tile card info (#27046)

This commit is contained in:
Paul Bottein
2025-09-15 10:29:48 +02:00
committed by GitHub
parent f71d8f4367
commit c6c4f91b0e
2 changed files with 16 additions and 13 deletions

View File

@@ -1,20 +1,21 @@
import type { TemplateResult } from "lit";
import { html, css, LitElement, nothing } from "lit";
import { css, html, LitElement } from "lit";
import { customElement, property } from "lit/decorators";
@customElement("ha-tile-info")
export class HaTileInfo extends LitElement {
@property() public primary?: string;
@property() public secondary?: string | TemplateResult<1>;
@property() public secondary?: string;
protected render() {
return html`
<div class="info">
<span class="primary">${this.primary}</span>
${this.secondary
? html`<span class="secondary">${this.secondary}</span>`
: nothing}
<slot name="primary" class="primary">
<span>${this.primary}</span>
</slot>
<slot name="secondary" class="secondary">
<span>${this.secondary}</span>
</slot>
</div>
`;
}
@@ -27,7 +28,8 @@ export class HaTileInfo extends LitElement {
align-items: flex-start;
justify-content: center;
}
span {
span,
::slotted(*) {
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;

View File

@@ -325,11 +325,12 @@ export class HuiTileCard extends LitElement implements LovelaceCard {
></ha-state-icon>
${renderTileBadge(stateObj, this.hass)}
</ha-tile-icon>
<ha-tile-info
id="info"
.primary=${name}
.secondary=${stateDisplay}
></ha-tile-info>
<ha-tile-info id="info">
<span slot="primary" class="primary">${name}</span>
${stateDisplay
? html`<span slot="secondary">${stateDisplay}</span>`
: nothing}
</ha-tile-info>
</div>
${features.length > 0
? html`