import * as interfaces from './interfaces'; import { DeesElement, TemplateResult, property, customElement, html, } from '@designestate/dees-element'; import * as domtools from '@designestate/dees-domtools'; import '@designestate/dees-catalog'; @customElement('deap-mainmenu') export class DeapMainmenu extends DeesElement { public static demo = () => html``; // INSTANCE // INSTANCE @property() public tabs: interfaces.ITab[] = [ {key: 'option 1', iconName: 'visibility', action: () => {}}, {key: 'option 2', iconName: 'alarm', action: () => {}}, {key: 'option 3', iconName: 'alarm', action: () => {}}, {key: 'option 4', iconName: 'alarm', action: () => {}} ]; @property() public selectedTab: interfaces.ITab; public render(): TemplateResult { return html` ${domtools.elementBasic.styles}
${this.tabs.map(tabArg => { return html`
${tabArg.key}
`; })}
`; } private async updateTabIndicator() { let selectedTab = this.selectedTab; if (!selectedTab) { selectedTab = this.tabs[0]; } const tabIndex = this.tabs.indexOf(selectedTab); const selectedTabElement: HTMLElement = this.shadowRoot.querySelector(`.tabsContainer .tab:nth-child(${tabIndex + 1})`); const tabIndicator: HTMLElement = this.shadowRoot.querySelector('.tabIndicator'); tabIndicator.style.top = selectedTabElement.offsetTop + 10 + 'px'; } updateTab(tabArg: interfaces.ITab) { this.selectedTab = tabArg; this.updateTabIndicator(); this.selectedTab.action(); } firstUpdated() { this.updateTab(this.tabs[0]); } }