import { Constructor } from "../types"; import "@polymer/iron-icon/iron-icon"; // Not duplicate, this is for typing. // tslint:disable-next-line import { IronIconElement } from "@polymer/iron-icon/iron-icon"; import { html } from "@polymer/polymer/lib/utils/html-tag.js"; const ironIconClass = customElements.get("iron-icon") as Constructor< IronIconElement >; let loaded = false; export class HaIcon extends ironIconClass { public _template = html` ${super._template} `; public _iconName?: string; public _iconsetName?: string; private _iconEffect?: string; public listen( node: EventTarget | null, eventName: string, methodName: string ): void { super.listen(node, eventName, methodName); if (!loaded && this._iconsetName === "mdi") { loaded = true; import(/* webpackChunkName: "mdi-icons" */ "../resources/mdi-icons"); } } public _iconChanged(icon) { const parts = (icon || "").split(":"); if (parts.length === 3) { this._iconEffect = parts.pop(); } this._iconName = parts.pop(); this._iconsetName = parts.pop() || this._DEFAULT_ICONSET; if (this._iconEffect) { this.setAttribute("effect", this._iconEffect); } else { this.removeAttribute("effect"); } this._updateIcon(); } } declare global { interface HTMLElementTagNameMap { "ha-icon": HaIcon; } } customElements.define("ha-icon", HaIcon);