diff --git a/src/panels/lovelace/components/notifications/hui-notifications-button.js b/src/panels/lovelace/components/notifications/hui-notifications-button.js deleted file mode 100644 index 6ecf1ec920..0000000000 --- a/src/panels/lovelace/components/notifications/hui-notifications-button.js +++ /dev/null @@ -1,68 +0,0 @@ -import "@material/mwc-button"; -import "@polymer/paper-icon-button/paper-icon-button"; -import "@polymer/app-layout/app-toolbar/app-toolbar"; - -import { html } from "@polymer/polymer/lib/utils/html-tag"; -import { PolymerElement } from "@polymer/polymer/polymer-element"; - -import EventsMixin from "../../../../mixins/events-mixin"; - -/* - * @appliesMixin EventsMixin - */ -export class HuiNotificationsButton extends EventsMixin(PolymerElement) { - static get template() { - return html` - - - - `; - } - - static get properties() { - return { - open: { - type: Boolean, - notify: true, - }, - notifications: { - type: Array, - value: [], - }, - }; - } - - _clicked() { - this.open = true; - } - - _hasNotifications(notifications) { - return notifications.length > 0; - } -} -customElements.define("hui-notifications-button", HuiNotificationsButton); diff --git a/src/panels/lovelace/components/notifications/hui-notifications-button.ts b/src/panels/lovelace/components/notifications/hui-notifications-button.ts new file mode 100644 index 0000000000..c56d2931a1 --- /dev/null +++ b/src/panels/lovelace/components/notifications/hui-notifications-button.ts @@ -0,0 +1,80 @@ +import { + html, + LitElement, + TemplateResult, + css, + CSSResult, + property, +} from "lit-element"; +import "@polymer/paper-icon-button/paper-icon-button"; +import { fireEvent } from "../../../../common/dom/fire_event"; + +declare global { + // tslint:disable-next-line + interface HASSDomEvents { + "opened-changed": { value: boolean }; + } +} + +class HuiNotificationsButton extends LitElement { + @property() public notifications?: string[]; + @property() public opened?: boolean; + + protected render(): TemplateResult | void { + return html` + + ${this.notifications && this.notifications.length > 0 + ? html` + +
${this.notifications.length}
+
+ ` + : ""} + `; + } + + static get styles(): CSSResult[] { + return [ + css` + :host { + position: relative; + } + + .indicator { + position: absolute; + top: 0px; + right: -3px; + width: 20px; + height: 20px; + border-radius: 50%; + background: var(--accent-color); + pointer-events: none; + z-index: 1; + } + + .indicator > div { + right: 7px; + top: 3px; + position: absolute; + font-size: 0.55em; + } + `, + ]; + } + + private _clicked() { + this.opened = true; + fireEvent(this, "opened-changed", { value: this.opened }); + } +} + +declare global { + interface HTMLElementTagNameMap { + "hui-notifications-button": HuiNotificationsButton; + } +} + +customElements.define("hui-notifications-button", HuiNotificationsButton); diff --git a/src/panels/lovelace/hui-root.ts b/src/panels/lovelace/hui-root.ts index b2f38df842..6529481648 100644 --- a/src/panels/lovelace/hui-root.ts +++ b/src/panels/lovelace/hui-root.ts @@ -186,8 +186,8 @@ class HUIRoot extends LitElement {
${this.config.title || "Home Assistant"}