import { DeesElement, TemplateResult, property, customElement, html } from '@designestate/dees-element'; import * as domtools from '@designestate/dees-domtools'; @customElement('deap-maincontent') export class DeapMaincontent extends DeesElement { public static demo = () => html``; // INSTANCE @property() public tabs: {key: string; action: () => void}[] = [ {key: 'option 1', action: () => {alert('hello')}}, {key: 'a very long option', action: () => {}}, {key: 'option 3', action: () => {}}, {key: 'option 4', action: () => {}} ]; @property() public selectedTab = null; public render(): TemplateResult { return html` ${domtools.elementBasic.styles}
lossless.com
${this.tabs.map(tabArg => { return html`
${tabArg.key}
`; })}
`; } firstUpdated() { this.updateIndicator(); } /** * updates the indicator */ private updateIndicator() { 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.width = selectedTabElement.clientWidth + 'px'; tabIndicator.style.left = selectedTabElement.offsetLeft + 'px'; } }