mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-21 16:26:43 +00:00
Remove ha-icon from ha-label-badge (#10182)
This commit is contained in:
parent
066a0771b3
commit
d5ca7e1719
@ -1,3 +1,4 @@
|
|||||||
|
import { mdiAlert } from "@mdi/js";
|
||||||
import { HassEntity } from "home-assistant-js-websocket";
|
import { HassEntity } from "home-assistant-js-websocket";
|
||||||
import {
|
import {
|
||||||
css,
|
css,
|
||||||
@ -14,11 +15,12 @@ import { computeStateDisplay } from "../../common/entity/compute_state_display";
|
|||||||
import { computeStateDomain } from "../../common/entity/compute_state_domain";
|
import { computeStateDomain } from "../../common/entity/compute_state_domain";
|
||||||
import { computeStateName } from "../../common/entity/compute_state_name";
|
import { computeStateName } from "../../common/entity/compute_state_name";
|
||||||
import { stateIcon } from "../../common/entity/state_icon";
|
import { stateIcon } from "../../common/entity/state_icon";
|
||||||
import { timerTimeRemaining } from "../../data/timer";
|
|
||||||
import { formatNumber } from "../../common/number/format_number";
|
import { formatNumber } from "../../common/number/format_number";
|
||||||
import { UNAVAILABLE, UNKNOWN } from "../../data/entity";
|
import { UNAVAILABLE, UNKNOWN } from "../../data/entity";
|
||||||
|
import { timerTimeRemaining } from "../../data/timer";
|
||||||
import { HomeAssistant } from "../../types";
|
import { HomeAssistant } from "../../types";
|
||||||
import "../ha-label-badge";
|
import "../ha-label-badge";
|
||||||
|
import "../ha-icon";
|
||||||
|
|
||||||
@customElement("ha-state-label-badge")
|
@customElement("ha-state-label-badge")
|
||||||
export class HaStateLabelBadge extends LitElement {
|
export class HaStateLabelBadge extends LitElement {
|
||||||
@ -58,16 +60,20 @@ export class HaStateLabelBadge extends LitElement {
|
|||||||
<ha-label-badge
|
<ha-label-badge
|
||||||
class="warning"
|
class="warning"
|
||||||
label=${this.hass!.localize("state_badge.default.error")}
|
label=${this.hass!.localize("state_badge.default.error")}
|
||||||
icon="hass:alert"
|
|
||||||
description=${this.hass!.localize(
|
description=${this.hass!.localize(
|
||||||
"state_badge.default.entity_not_found"
|
"state_badge.default.entity_not_found"
|
||||||
)}
|
)}
|
||||||
></ha-label-badge>
|
>
|
||||||
|
<ha-svg-icon .path=${mdiAlert}></ha-svg-icon>
|
||||||
|
</ha-label-badge>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const domain = computeStateDomain(entityState);
|
const domain = computeStateDomain(entityState);
|
||||||
|
|
||||||
|
const value = this._computeValue(domain, entityState);
|
||||||
|
const icon = this.icon ? this.icon : this._computeIcon(domain, entityState);
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
<ha-label-badge
|
<ha-label-badge
|
||||||
class=${classMap({
|
class=${classMap({
|
||||||
@ -75,8 +81,6 @@ export class HaStateLabelBadge extends LitElement {
|
|||||||
"has-unit_of_measurement":
|
"has-unit_of_measurement":
|
||||||
"unit_of_measurement" in entityState.attributes,
|
"unit_of_measurement" in entityState.attributes,
|
||||||
})}
|
})}
|
||||||
.value=${this._computeValue(domain, entityState)}
|
|
||||||
.icon=${this.icon ? this.icon : this._computeIcon(domain, entityState)}
|
|
||||||
.image=${this.icon
|
.image=${this.icon
|
||||||
? ""
|
? ""
|
||||||
: this.image
|
: this.image
|
||||||
@ -89,7 +93,14 @@ export class HaStateLabelBadge extends LitElement {
|
|||||||
this._timerTimeRemaining
|
this._timerTimeRemaining
|
||||||
)}
|
)}
|
||||||
.description=${this.name ?? computeStateName(entityState)}
|
.description=${this.name ?? computeStateName(entityState)}
|
||||||
></ha-label-badge>
|
>
|
||||||
|
${icon ? html`<ha-icon .icon=${icon}></ha-icon>` : ""}
|
||||||
|
${value && (this.icon || !this.image)
|
||||||
|
? html`<span class=${value && value.length > 4 ? "big" : ""}
|
||||||
|
>${value}</span
|
||||||
|
>`
|
||||||
|
: ""}
|
||||||
|
</ha-label-badge>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -208,7 +219,9 @@ export class HaStateLabelBadge extends LitElement {
|
|||||||
:host {
|
:host {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
.big {
|
||||||
|
font-size: 70%;
|
||||||
|
}
|
||||||
ha-label-badge {
|
ha-label-badge {
|
||||||
--ha-label-badge-color: var(--label-badge-red, #df4c1e);
|
--ha-label-badge-color: var(--label-badge-red, #df4c1e);
|
||||||
}
|
}
|
||||||
|
@ -8,13 +8,9 @@ import {
|
|||||||
} from "lit";
|
} from "lit";
|
||||||
import { property } from "lit/decorators";
|
import { property } from "lit/decorators";
|
||||||
import { classMap } from "lit/directives/class-map";
|
import { classMap } from "lit/directives/class-map";
|
||||||
import "./ha-icon";
|
import "./ha-svg-icon";
|
||||||
|
|
||||||
class HaLabelBadge extends LitElement {
|
class HaLabelBadge extends LitElement {
|
||||||
@property() public value?: string;
|
|
||||||
|
|
||||||
@property() public icon?: string;
|
|
||||||
|
|
||||||
@property() public label?: string;
|
@property() public label?: string;
|
||||||
|
|
||||||
@property() public description?: string;
|
@property() public description?: string;
|
||||||
@ -25,20 +21,8 @@ class HaLabelBadge extends LitElement {
|
|||||||
return html`
|
return html`
|
||||||
<div class="badge-container">
|
<div class="badge-container">
|
||||||
<div class="label-badge" id="badge">
|
<div class="label-badge" id="badge">
|
||||||
<div
|
<div class="value">
|
||||||
class=${classMap({
|
<slot></slot>
|
||||||
value: true,
|
|
||||||
big: Boolean(this.value && this.value.length > 4),
|
|
||||||
})}
|
|
||||||
>
|
|
||||||
<slot>
|
|
||||||
${this.icon && !this.value && !this.image
|
|
||||||
? html`<ha-icon .icon=${this.icon}></ha-icon>`
|
|
||||||
: ""}
|
|
||||||
${this.value && !this.image
|
|
||||||
? html`<span>${this.value}</span>`
|
|
||||||
: ""}
|
|
||||||
</slot>
|
|
||||||
</div>
|
</div>
|
||||||
${this.label
|
${this.label
|
||||||
? html`
|
? html`
|
||||||
@ -54,7 +38,7 @@ class HaLabelBadge extends LitElement {
|
|||||||
: ""}
|
: ""}
|
||||||
</div>
|
</div>
|
||||||
${this.description
|
${this.description
|
||||||
? html` <div class="title">${this.description}</div> `
|
? html`<div class="title">${this.description}</div>`
|
||||||
: ""}
|
: ""}
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
@ -87,14 +71,15 @@ class HaLabelBadge extends LitElement {
|
|||||||
background-size: cover;
|
background-size: cover;
|
||||||
transition: border 0.3s ease-in-out;
|
transition: border 0.3s ease-in-out;
|
||||||
}
|
}
|
||||||
|
.label-badge .label.big span {
|
||||||
|
font-size: 90%;
|
||||||
|
padding: 10% 12% 7% 12%; /* push smaller text a bit down to center vertically */
|
||||||
|
}
|
||||||
.label-badge .value {
|
.label-badge .value {
|
||||||
font-size: 90%;
|
font-size: 90%;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
}
|
}
|
||||||
.label-badge .value.big {
|
|
||||||
font-size: 70%;
|
|
||||||
}
|
|
||||||
.label-badge .label {
|
.label-badge .label {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
bottom: -1em;
|
bottom: -1em;
|
||||||
@ -119,10 +104,6 @@ class HaLabelBadge extends LitElement {
|
|||||||
transition: background-color 0.3s ease-in-out;
|
transition: background-color 0.3s ease-in-out;
|
||||||
text-transform: var(--ha-label-badge-label-text-transform, uppercase);
|
text-transform: var(--ha-label-badge-label-text-transform, uppercase);
|
||||||
}
|
}
|
||||||
.label-badge .label.big span {
|
|
||||||
font-size: 90%;
|
|
||||||
padding: 10% 12% 7% 12%; /* push smaller text a bit down to center vertically */
|
|
||||||
}
|
|
||||||
.badge-container .title {
|
.badge-container .title {
|
||||||
margin-top: 1em;
|
margin-top: 1em;
|
||||||
font-size: var(--ha-label-badge-title-font-size, 0.9em);
|
font-size: var(--ha-label-badge-title-font-size, 0.9em);
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
|
import { mdiAlert } from "@mdi/js";
|
||||||
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
|
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
|
||||||
import { customElement, state } from "lit/decorators";
|
import { customElement, state } from "lit/decorators";
|
||||||
import "../../../components/ha-label-badge";
|
import "../../../components/ha-label-badge";
|
||||||
|
import "../../../components/ha-svg-icon";
|
||||||
import { HomeAssistant } from "../../../types";
|
import { HomeAssistant } from "../../../types";
|
||||||
import { LovelaceBadge } from "../types";
|
import { LovelaceBadge } from "../types";
|
||||||
import { ErrorBadgeConfig } from "./types";
|
import { ErrorBadgeConfig } from "./types";
|
||||||
@ -32,11 +34,9 @@ export class HuiErrorBadge extends LitElement implements LovelaceBadge {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
<ha-label-badge
|
<ha-label-badge label="Error" description=${this._config.error}>
|
||||||
label="Error"
|
<ha-svg-icon .path=${mdiAlert}></ha-svg-icon>
|
||||||
icon="hass:alert"
|
</ha-label-badge>
|
||||||
description=${this._config.error}
|
|
||||||
></ha-label-badge>
|
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user