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

123 lines
3.1 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.tab[] = [
{key: 'option 1', iconName: 'visibility', action: () => {alert('hello')}},
{key: 'option 2', iconName: 'alarm', action: () => {}},
{key: 'option 3', iconName: 'alarm', action: () => {}},
{key: 'option 4', iconName: 'alarm', action: () => {}}
];
@property()
public selectedTab: interfaces.tab;
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.2);
}
.tabsContainer {
}
.tab {
padding-top: 16px;
font-size: 25px;
width: 80px;
height: 80px;
text-align: center;
cursor: pointer;
transition: color 0.1s;
}
.tab:hover {
background: #222222;
}
.tab.selectedTab {
color: #fff;
}
.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.3s;
}
</style>
<div class="mainlogo"></div>
<div class="tabsContainer">
${this.tabs.map(tabArg => {
return html`
<div class="tab ${tabArg === this.selectedTab ? 'selectedTab': null}" @click="${() => {this.selectedTab = tabArg; this.updateTabIndicator(); tabArg.action()}}">
<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';
}
firstUpdated() {
this.selectedTab = this.tabs[0];
this.updateTabIndicator();
}
}