Convert ha-menu-button to TS (#2825)

* Convert ha-menu-button to TS

* Address comments

* Fix icon searcher
This commit is contained in:
Paulus Schoutsen 2019-02-25 11:53:46 -08:00 committed by GitHub
parent 6d2e480ed5
commit 3e28b6f2e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 50 deletions

View File

@ -1,50 +0,0 @@
import "@polymer/paper-icon-button/paper-icon-button";
import { html } from "@polymer/polymer/lib/utils/html-tag";
import { PolymerElement } from "@polymer/polymer/polymer-element";
import EventsMixin from "../mixins/events-mixin";
/*
* @appliesMixin EventsMixin
*/
class HaMenuButton extends EventsMixin(PolymerElement) {
static get template() {
return html`
<paper-icon-button
icon="[[_getIcon(hassio)]]"
on-click="toggleMenu"
></paper-icon-button>
`;
}
static get properties() {
return {
narrow: {
type: Boolean,
value: false,
},
showMenu: {
type: Boolean,
value: false,
},
hassio: {
type: Boolean,
value: false,
},
};
}
toggleMenu(ev) {
ev.stopPropagation();
this.fire(this.showMenu ? "hass-close-menu" : "hass-open-menu");
}
_getIcon(hassio) {
// hass:menu
return `${hassio ? "hassio" : "hass"}:menu`;
}
}
customElements.define("ha-menu-button", HaMenuButton);

View File

@ -0,0 +1,44 @@
import "@polymer/paper-icon-button/paper-icon-button";
import {
property,
TemplateResult,
LitElement,
html,
customElement,
} from "lit-element";
import { fireEvent } from "../common/dom/fire_event";
@customElement("ha-menu-button")
class HaMenuButton extends LitElement {
@property({ type: Boolean })
public showMenu = false;
@property({ type: Boolean })
public hassio = false;
protected render(): TemplateResult | void {
return html`
<paper-icon-button
.icon=${this.hassio ? "hassio:menu" : "hass:menu"}
@click=${this._toggleMenu}
></paper-icon-button>
`;
}
// We are not going to use ShadowDOM as we're rendering a single element
// without any CSS used.
protected createRenderRoot(): Element | ShadowRoot {
return this;
}
private _toggleMenu(): void {
fireEvent(this, this.showMenu ? "hass-close-menu" : "hass-open-menu");
}
}
declare global {
interface HTMLElementTagNameMap {
"ha-menu-button": HaMenuButton;
}
}