import "@material/mwc-list/mwc-list-item"; import { mdiDotsVertical } from "@mdi/js"; import "@polymer/paper-tooltip/paper-tooltip"; import { css, html, LitElement, TemplateResult } from "lit"; import { customElement, property } from "lit/decorators"; import { HomeAssistant } from "../types"; import "./ha-button-menu"; import "./ha-icon-button"; import "./ha-svg-icon"; export interface IconOverflowMenuItem { [key: string]: any; path: string; label: string; narrowOnly?: boolean; disabled?: boolean; tooltip?: string; onClick: CallableFunction; } @customElement("ha-icon-overflow-menu") export class HaIconOverflowMenu extends LitElement { @property({ attribute: false }) public hass!: HomeAssistant; @property({ type: Array }) public items: IconOverflowMenuItem[] = []; @property({ type: Boolean }) public narrow = false; protected render(): TemplateResult { return html` ${this.narrow ? html` ${this.items.map( (item) => html`
${item.label}
` )}
` : html` ${this.items.map((item) => item.narrowOnly ? "" : html`
${item.tooltip ? html` ${item.tooltip} ` : ""}
` )} `} `; } protected _handleIconOverflowMenuOpened() { // If this component is used inside a data table, the z-index of the row // needs to be increased. Otherwise the ha-button-menu would be displayed // underneath the next row in the table. const row = this.closest(".mdc-data-table__row") as HTMLDivElement | null; if (row) { row.style.zIndex = "1"; } } protected _handleIconOverflowMenuClosed() { const row = this.closest(".mdc-data-table__row") as HTMLDivElement | null; if (row) { row.style.zIndex = ""; } } static get styles() { return css` :host { display: flex; justify-content: flex-end; } `; } } declare global { interface HTMLElementTagNameMap { "ha-icon-overflow-menu": HaIconOverflowMenu; } }