Skip to content

Commit

Permalink
Support multiple CSS classes (#262)
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieudutour authored Nov 22, 2023
1 parent 685a1d2 commit 1c802ed
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 5 deletions.
7 changes: 6 additions & 1 deletion src/patch/ha-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ customElements.whenDefined("ha-card").then(() => {

const config = findConfig(this);

if (config?.card_mod?.class) this.classList.add(config.card_mod.class);
if (config?.card_mod?.class)
this.classList.add(
...(Array.isArray(config.card_mod.class)
? config.card_mod.class
: config.card_mod.class.split(" "))
);
if (config?.type)
this.classList.add(`type-${config.type.replace(":", "-")}`);

Expand Down
7 changes: 6 additions & 1 deletion src/patch/hui-entities-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ customElements.whenDefined("hui-entities-card").then(() => {
if (!row) return retval;
if (config?.type === "custom:mod-card") return retval;

if (config?.card_mod?.class) row.classList.add(config.card_mod.class);
if (config?.card_mod?.class)
row.classList.add(
...(Array.isArray(config.card_mod.class)
? config.card_mod.class
: config.card_mod.class.split(" "))
);
if (config?.type)
row.classList.add(`type-${config.type.replace(":", "-")}`);

Expand Down
7 changes: 6 additions & 1 deletion src/patch/hui-glance-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ customElements.whenDefined("hui-glance-card").then(() => {
}

const config = e.config || e.entityConf;
if (config?.card_mod?.class) e.classList.add(config.card_mod.class);
if (config?.card_mod?.class)
e.classList.add(
...(Array.isArray(config.card_mod.class)
? config.card_mod.class
: config.card_mod.class.split(" "))
);

applyToElement(
e,
Expand Down
7 changes: 6 additions & 1 deletion src/patch/hui-picture-elements-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ customElements.whenDefined("hui-picture-elements-card").then(() => {

for (const [i, el] of this._elements.entries()) {
const config = this._config.elements[i];
if (config?.card_mod?.class) el.classList.add(config.card_mod.class);
if (config?.card_mod?.class)
el.classList.add(
...(Array.isArray(config.card_mod.class)
? config.card_mod.class
: config.card_mod.class.split(" "))
);
if (config?.type)
el.classList.add(`type-${config.type.replace(":", "-")}`);
applyToElement(el, "element", config?.card_mod?.style, { config });
Expand Down
7 changes: 6 additions & 1 deletion src/patch/hui-state-label-badge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ customElements.whenDefined("hui-state-label-badge").then(() => {

const config = this._config;

if (config?.card_mod?.class) this.classList.add(config.card_mod.class);
if (config?.card_mod?.class)
this.classList.add(
...(Array.isArray(config.card_mod.class)
? config.card_mod.class
: config.card_mod.class.split(" "))
);

applyToElement(
this,
Expand Down

0 comments on commit 1c802ed

Please sign in to comment.