dees-appui-catalog/ts_web/elements/deap-mainmenu.ts
2021-03-06 18:59:00 +00:00

129 lines
3.2 KiB
TypeScript

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`<deap-mainmenu></deap-mainmenu>`;
// 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}
<style>
:host {
color: #CCC;
z-index: 10;
display: block;
position: relative;
width: 80px;
height: 100%;
background: #3c3c3c;
box-shadow: 0px 0px 5px rgba(0, 0, 0, 0.5);
user-select: none;
}
.mainlogo {
width: 80px;
height: 80px;
background: rgba(0, 0, 0, 0.4);
}
.tabsContainer {
}
.tab {
padding-top: 16px;
font-size: 25px;
width: 80px;
height: 80px;
text-align: center;
cursor: pointer;
transition: color 0.1s, background 0.2s;
}
.tab:hover {
background: rgba(0, 0, 0, 0.3);
}
.tab.selectedTab {
color: #fff;
background: rgba(0, 0, 0, 0.2);
}
.tab .label {
font-size: 12px;
margin-top: 5px;
}
.tabIndicator {
background: #4E729A;
position: absolute;
width: 7px;
height: 60px;
left: 0px;
top: 90px;
border-top-right-radius: 7px;
border-bottom-right-radius: 7px;
transition: all 0.1s;
}
</style>
<div class="mainlogo"></div>
<div class="tabsContainer">
${this.tabs.map(tabArg => {
return html`
<div class="tab ${tabArg === this.selectedTab ? 'selectedTab': null}" @click="${() => {this.updateTab(tabArg)}}">
<dees-icon iconName="${tabArg.iconName}"></dees-icon>
<div class="label">${tabArg.key}</div>
</div>
`;
})}
</div>
<div class="tabIndicator"></div>
`;
}
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]);
}
}