mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-21 08:16:36 +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 {
|
||||
css,
|
||||
@ -14,11 +15,12 @@ import { computeStateDisplay } from "../../common/entity/compute_state_display";
|
||||
import { computeStateDomain } from "../../common/entity/compute_state_domain";
|
||||
import { computeStateName } from "../../common/entity/compute_state_name";
|
||||
import { stateIcon } from "../../common/entity/state_icon";
|
||||
import { timerTimeRemaining } from "../../data/timer";
|
||||
import { formatNumber } from "../../common/number/format_number";
|
||||
import { UNAVAILABLE, UNKNOWN } from "../../data/entity";
|
||||
import { timerTimeRemaining } from "../../data/timer";
|
||||
import { HomeAssistant } from "../../types";
|
||||
import "../ha-label-badge";
|
||||
import "../ha-icon";
|
||||
|
||||
@customElement("ha-state-label-badge")
|
||||
export class HaStateLabelBadge extends LitElement {
|
||||
@ -58,16 +60,20 @@ export class HaStateLabelBadge extends LitElement {
|
||||
<ha-label-badge
|
||||
class="warning"
|
||||
label=${this.hass!.localize("state_badge.default.error")}
|
||||
icon="hass:alert"
|
||||
description=${this.hass!.localize(
|
||||
"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 value = this._computeValue(domain, entityState);
|
||||
const icon = this.icon ? this.icon : this._computeIcon(domain, entityState);
|
||||
|
||||
return html`
|
||||
<ha-label-badge
|
||||
class=${classMap({
|
||||
@ -75,8 +81,6 @@ export class HaStateLabelBadge extends LitElement {
|
||||
"has-unit_of_measurement":
|
||||
"unit_of_measurement" in entityState.attributes,
|
||||
})}
|
||||
.value=${this._computeValue(domain, entityState)}
|
||||
.icon=${this.icon ? this.icon : this._computeIcon(domain, entityState)}
|
||||
.image=${this.icon
|
||||
? ""
|
||||
: this.image
|
||||
@ -89,7 +93,14 @@ export class HaStateLabelBadge extends LitElement {
|
||||
this._timerTimeRemaining
|
||||
)}
|
||||
.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 {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.big {
|
||||
font-size: 70%;
|
||||
}
|
||||
ha-label-badge {
|
||||
--ha-label-badge-color: var(--label-badge-red, #df4c1e);
|
||||
}
|
||||
|
@ -8,13 +8,9 @@ import {
|
||||
} from "lit";
|
||||
import { property } from "lit/decorators";
|
||||
import { classMap } from "lit/directives/class-map";
|
||||
import "./ha-icon";
|
||||
import "./ha-svg-icon";
|
||||
|
||||
class HaLabelBadge extends LitElement {
|
||||
@property() public value?: string;
|
||||
|
||||
@property() public icon?: string;
|
||||
|
||||
@property() public label?: string;
|
||||
|
||||
@property() public description?: string;
|
||||
@ -25,20 +21,8 @@ class HaLabelBadge extends LitElement {
|
||||
return html`
|
||||
<div class="badge-container">
|
||||
<div class="label-badge" id="badge">
|
||||
<div
|
||||
class=${classMap({
|
||||
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 class="value">
|
||||
<slot></slot>
|
||||
</div>
|
||||
${this.label
|
||||
? html`
|
||||
@ -54,7 +38,7 @@ class HaLabelBadge extends LitElement {
|
||||
: ""}
|
||||
</div>
|
||||
${this.description
|
||||
? html` <div class="title">${this.description}</div> `
|
||||
? html`<div class="title">${this.description}</div>`
|
||||
: ""}
|
||||
</div>
|
||||
`;
|
||||
@ -87,14 +71,15 @@ class HaLabelBadge extends LitElement {
|
||||
background-size: cover;
|
||||
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 {
|
||||
font-size: 90%;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
.label-badge .value.big {
|
||||
font-size: 70%;
|
||||
}
|
||||
.label-badge .label {
|
||||
position: absolute;
|
||||
bottom: -1em;
|
||||
@ -119,10 +104,6 @@ class HaLabelBadge extends LitElement {
|
||||
transition: background-color 0.3s ease-in-out;
|
||||
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 {
|
||||
margin-top: 1em;
|
||||
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 { customElement, state } from "lit/decorators";
|
||||
import "../../../components/ha-label-badge";
|
||||
import "../../../components/ha-svg-icon";
|
||||
import { HomeAssistant } from "../../../types";
|
||||
import { LovelaceBadge } from "../types";
|
||||
import { ErrorBadgeConfig } from "./types";
|
||||
@ -32,11 +34,9 @@ export class HuiErrorBadge extends LitElement implements LovelaceBadge {
|
||||
}
|
||||
|
||||
return html`
|
||||
<ha-label-badge
|
||||
label="Error"
|
||||
icon="hass:alert"
|
||||
description=${this._config.error}
|
||||
></ha-label-badge>
|
||||
<ha-label-badge label="Error" description=${this._config.error}>
|
||||
<ha-svg-icon .path=${mdiAlert}></ha-svg-icon>
|
||||
</ha-label-badge>
|
||||
`;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user