Skip to content

Commit

Permalink
Fix and improve canary-card style option
Browse files Browse the repository at this point in the history
  • Loading branch information
jcwillox committed Jul 6, 2020
1 parent 1d26931 commit 1d37abc
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/modules/canary-card.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { html, LitElement } from "card-tools/src/lit-element";
import { LitElement } from "card-tools/src/lit-element";
import { createCard } from "card-tools/src/lovelace-element";
import { hass } from "card-tools/src/hass";
import { applyTheme } from "../styles";
Expand All @@ -13,12 +13,7 @@ class CanaryCard extends LitElement {
}

render() {
return html`
${this._card}
<style>
${this._config.style}
</style>
`;
return this._card;
}

setConfig(config) {
Expand All @@ -27,6 +22,19 @@ class CanaryCard extends LitElement {
this._hass = this._card.hass = hass();
}

firstUpdated() {
if (typeof this._config.style === "object") {
Object.assign(this._card.style, this._config.style);
} else {
let styleEl = document.createElement("style");
styleEl.innerHTML = this._config.style;

this._card.updateComplete.then(() => {
(this._card.shadowRoot || this._card).appendChild(styleEl);
});
}
}

set hass(hass) {
this._hass = hass;
this._card.hass = hass;
Expand Down

0 comments on commit 1d37abc

Please sign in to comment.