diff --git a/src/panels/lovelace/common/create-row-element.js b/src/panels/lovelace/common/create-row-element.js index eaff2bdce1..af3d91269f 100644 --- a/src/panels/lovelace/common/create-row-element.js +++ b/src/panels/lovelace/common/create-row-element.js @@ -15,7 +15,7 @@ import "../entity-rows/hui-timer-entity-row.js"; import "../entity-rows/hui-toggle-entity-row.js"; import "../special-rows/hui-call-service-row.js"; -import "../special-rows/hui-divider-row.js"; +import "../special-rows/hui-divider-row"; import "../special-rows/hui-section-row.js"; import "../special-rows/hui-weblink-row.js"; diff --git a/src/panels/lovelace/special-rows/hui-divider-row.js b/src/panels/lovelace/special-rows/hui-divider-row.js deleted file mode 100644 index 453ee8b538..0000000000 --- a/src/panels/lovelace/special-rows/hui-divider-row.js +++ /dev/null @@ -1,43 +0,0 @@ -import { html } from "@polymer/polymer/lib/utils/html-tag.js"; -import { PolymerElement } from "@polymer/polymer/polymer-element.js"; - -class HuiDividerRow extends PolymerElement { - static get template() { - return html``; - } - - setConfig(config) { - if (!config) { - throw new Error("Error in card configuration."); - } - this._config = config; - this._createDivider(); - } - - ready() { - super.ready(); - this._createDivider(); - } - - _createDivider() { - const root = this.shadowRoot; - if (root === null) return; - - while (root.lastChild) { - root.removeChild(root.lastChild); - } - - const style = this._config.style || { - height: "1px", - "background-color": "var(--secondary-text-color)", - }; - - const el = document.createElement("div"); - Object.keys(style).forEach((prop) => { - el.style.setProperty(prop, style[prop]); - }); - - root.appendChild(el); - } -} -customElements.define("hui-divider-row", HuiDividerRow); diff --git a/src/panels/lovelace/special-rows/hui-divider-row.ts b/src/panels/lovelace/special-rows/hui-divider-row.ts new file mode 100644 index 0000000000..1720063db7 --- /dev/null +++ b/src/panels/lovelace/special-rows/hui-divider-row.ts @@ -0,0 +1,53 @@ +import { html, LitElement } from "@polymer/lit-element"; +import { EntityRow, DividerConfig } from "../entity-rows/types"; +import { HomeAssistant } from "../../../types"; +import { TemplateResult } from "lit-html"; + +class HuiDividerRow extends LitElement implements EntityRow { + public hass?: HomeAssistant; + private _config?: DividerConfig; + + static get properties() { + return { + _config: {}, + }; + } + + public setConfig(config): void { + if (!config) { + throw new Error("Error in card configuration."); + } + + this._config = { + style: { + height: "1px", + "background-color": "var(--secondary-text-color)", + }, + ...config, + }; + } + + protected render(): TemplateResult { + if (!this._config) { + return html``; + } + + const el = document.createElement("div"); + + Object.keys(this._config.style).forEach((prop) => { + el.style.setProperty(prop, this._config!.style[prop]); + }); + + return html` + ${el} + `; + } +} + +declare global { + interface HTMLElementTagNameMap { + "hui-divider-row": HuiDividerRow; + } +} + +customElements.define("hui-divider-row", HuiDividerRow);