Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove ha-icon from ha-label-badge #10182

Merged
merged 4 commits into from
Oct 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions src/components/entity/ha-state-label-badge.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { mdiAlert } from "@mdi/js";
import { HassEntity } from "home-assistant-js-websocket";
import {
css,
Expand All @@ -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 {
Expand Down Expand Up @@ -58,25 +60,27 @@ 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({
[domain]: true,
"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
Expand All @@ -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>
`;
}

Expand Down Expand Up @@ -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);
}
Expand Down
35 changes: 8 additions & 27 deletions src/components/ha-label-badge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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`
Expand All @@ -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>
`;
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions src/panels/lovelace/badges/hui-error-badge.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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>
`;
}

Expand Down