diff --git a/src/panels/lovelace/cards/hui-vertical-stack-card.js b/src/panels/lovelace/cards/hui-vertical-stack-card.js deleted file mode 100644 index 5b213c157c..0000000000 --- a/src/panels/lovelace/cards/hui-vertical-stack-card.js +++ /dev/null @@ -1,92 +0,0 @@ -import { html } from "@polymer/polymer/lib/utils/html-tag.js"; -import { PolymerElement } from "@polymer/polymer/polymer-element.js"; - -import computeCardSize from "../common/compute-card-size.js"; -import createCardElement from "../common/create-card-element.js"; - -class HuiVerticalStackCard extends PolymerElement { - static get template() { - return html` - -
- `; - } - - static get properties() { - return { - hass: { - type: Object, - observer: "_hassChanged", - }, - }; - } - - constructor() { - super(); - this._elements = []; - } - - ready() { - super.ready(); - if (this._config) this._buildConfig(); - } - - getCardSize() { - let totalSize = 0; - this._elements.forEach((element) => { - totalSize += computeCardSize(element); - }); - return totalSize; - } - - setConfig(config) { - if (!config || !config.cards || !Array.isArray(config.cards)) { - throw new Error("Card config incorrect"); - } - - this._config = config; - if (this.$) this._buildConfig(); - } - - _buildConfig() { - const config = this._config; - - this._elements = []; - const root = this.$.root; - - while (root.lastChild) { - root.removeChild(root.lastChild); - } - - const elements = []; - config.cards.forEach((card) => { - const element = createCardElement(card); - element.hass = this.hass; - elements.push(element); - root.appendChild(element); - }); - this._elements = elements; - } - - _hassChanged(hass) { - this._elements.forEach((element) => { - element.hass = hass; - }); - } -} - -customElements.define("hui-vertical-stack-card", HuiVerticalStackCard); diff --git a/src/panels/lovelace/cards/hui-vertical-stack-card.ts b/src/panels/lovelace/cards/hui-vertical-stack-card.ts new file mode 100644 index 0000000000..4629552a2f --- /dev/null +++ b/src/panels/lovelace/cards/hui-vertical-stack-card.ts @@ -0,0 +1,93 @@ +import { html, LitElement } from "@polymer/lit-element"; + +import computeCardSize from "../common/compute-card-size.js"; +import createCardElement from "../common/create-card-element.js"; + +import { LovelaceCard, LovelaceConfig } from "../types"; +import { HomeAssistant } from "../../../types"; + +interface Config extends LovelaceConfig { + cards: LovelaceConfig[]; +} + +class HuiVerticalStackCard extends LitElement implements LovelaceCard { + protected config?: Config; + private _hass?: HomeAssistant; + + static get properties() { + return { + config: {}, + }; + } + + set hass(hass: HomeAssistant) { + this._hass = hass; + for (const el of this.shadowRoot!.querySelectorAll("#root > *")) { + const element = el as LovelaceCard; + element.hass = this._hass; + } + } + + public getCardSize() { + let totalSize = 0; + for (const element of this.shadowRoot!.querySelectorAll("#root > *")) { + totalSize += computeCardSize(element); + } + + return totalSize; + } + + public setConfig(config: Config) { + if (!config || !config.cards || !Array.isArray(config.cards)) { + throw new Error("Card config incorrect"); + } + this.config = config; + } + + protected render() { + if (!this.config) { + return html``; + } + + return html` + ${this.renderStyle()} +