Skip to content

Commit

Permalink
Fix custom badges
Browse files Browse the repository at this point in the history
  • Loading branch information
piitaya committed Jul 15, 2024
1 parent 46b403c commit 733ce99
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/data/lovelace_custom_cards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ if (!("customCardFeatures" in customCardsWindow)) {
customCardsWindow.customCardFeatures = [];
}
if (!("customBadges" in customCardsWindow)) {
customCardsWindow.customCardFeatures = [];
customCardsWindow.customBadges = [];
}
if (!("customTileFeatures" in customCardsWindow)) {
customCardsWindow.customBadges = [];
customCardsWindow.customTileFeatures = [];
}

export const customCards = customCardsWindow.customCards!;
Expand Down
14 changes: 11 additions & 3 deletions src/panels/lovelace/badges/hui-entity-badge.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { HassEntity } from "home-assistant-js-websocket";
import { css, CSSResultGroup, html, LitElement, nothing } from "lit";
import { customElement, property, state } from "lit/decorators";
import { classMap } from "lit/directives/class-map";
import { ifDefined } from "lit/directives/if-defined";
import { styleMap } from "lit/directives/style-map";
import memoizeOne from "memoize-one";
Expand All @@ -14,11 +15,11 @@ import "../../../components/ha-state-icon";
import { ActionHandlerEvent } from "../../../data/lovelace/action_handler";
import { HomeAssistant } from "../../../types";
import { actionHandler } from "../common/directives/action-handler-directive";
import { findEntities } from "../common/find-entities";
import { handleAction } from "../common/handle-action";
import { hasAction } from "../common/has-action";
import { LovelaceBadge, LovelaceBadgeEditor } from "../types";
import { EntityBadgeConfig } from "./types";
import { findEntities } from "../common/find-entities";

@customElement("hui-entity-badge")
export class HuiEntityBadge extends LitElement implements LovelaceBadge {
Expand Down Expand Up @@ -108,6 +109,7 @@ export class HuiEntityBadge extends LitElement implements LovelaceBadge {
return nothing;
}

const active = stateActive(stateObj);
const color = this._computeStateColor(stateObj, this._config.color);

const style = {
Expand All @@ -126,7 +128,7 @@ export class HuiEntityBadge extends LitElement implements LovelaceBadge {
return html`
<div
style=${styleMap(style)}
class="badge"
class="badge ${classMap({ active })}"
@action=${this._handleAction}
.actionHandler=${actionHandler({
hasHold: hasAction(this._config!.hold_action),
Expand All @@ -152,8 +154,11 @@ export class HuiEntityBadge extends LitElement implements LovelaceBadge {

static get styles(): CSSResultGroup {
return css`
.badge {
:host() {
--badge-color: var(--state-inactive-color);
-webkit-tap-highlight-color: transparent;
}
.badge {
position: relative;
--ha-ripple-color: var(--badge-color);
--ha-ripple-hover-opacity: 0.04;
Expand Down Expand Up @@ -185,6 +190,9 @@ export class HuiEntityBadge extends LitElement implements LovelaceBadge {
line-height: 20px;
letter-spacing: 0.1px;
}
.badge.active {
--badge-color: var(--primary-color);
}
ha-state-icon {
color: var(--badge-color);
}
Expand Down
2 changes: 1 addition & 1 deletion src/panels/lovelace/views/hui-sections-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export class SectionsView extends LitElement implements LovelaceViewElement {
const badges = this.badges;

return html`
${badges?.length > 0
${badges?.length > 0 || editMode
? html`
<ha-sortable
.disabled=${!editMode}
Expand Down

0 comments on commit 733ce99

Please sign in to comment.