dees-appui-catalog/ts_web/elements/deap-mainmenu.ts

129 lines
3.2 KiB
TypeScript
Raw Normal View History

2021-03-06 17:07:06 +00:00
import * as interfaces from './interfaces';
import {
DeesElement,
TemplateResult,
property,
customElement,
html,
} from '@designestate/dees-element';
2021-03-05 16:01:54 +00:00
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
2021-03-06 17:07:06 +00:00
// INSTANCE
@property()
2021-03-06 18:59:00 +00:00
public tabs: interfaces.ITab[] = [
{key: 'option 1', iconName: 'visibility', action: () => {}},
2021-03-06 17:07:06 +00:00
{key: 'option 2', iconName: 'alarm', action: () => {}},
{key: 'option 3', iconName: 'alarm', action: () => {}},
{key: 'option 4', iconName: 'alarm', action: () => {}}
];
@property()
2021-03-06 18:59:00 +00:00
public selectedTab: interfaces.ITab;
2021-03-06 17:07:06 +00:00
public render(): TemplateResult {
2021-03-05 16:01:54 +00:00
return html`
${domtools.elementBasic.styles}
<style>
:host {
2021-03-06 17:07:06 +00:00
color: #CCC;
2021-03-05 16:01:54 +00:00
z-index: 10;
display: block;
position: relative;
width: 80px;
height: 100%;
background: #3c3c3c;
2021-03-06 17:07:06 +00:00
box-shadow: 0px 0px 5px rgba(0, 0, 0, 0.5);
user-select: none;
2021-03-05 16:01:54 +00:00
}
2021-03-06 17:07:06 +00:00
.mainlogo {
width: 80px;
height: 80px;
2021-03-06 18:59:00 +00:00
background: rgba(0, 0, 0, 0.4);
2021-03-05 16:01:54 +00:00
}
2021-03-06 17:07:06 +00:00
.tabsContainer {
}
.tab {
padding-top: 16px;
font-size: 25px;
2021-03-05 16:01:54 +00:00
width: 80px;
height: 80px;
2021-03-06 17:07:06 +00:00
text-align: center;
cursor: pointer;
2021-03-06 18:59:00 +00:00
transition: color 0.1s, background 0.2s;
2021-03-05 16:01:54 +00:00
}
2021-03-06 17:07:06 +00:00
.tab:hover {
2021-03-06 18:59:00 +00:00
background: rgba(0, 0, 0, 0.3);
2021-03-06 17:07:06 +00:00
}
.tab.selectedTab {
color: #fff;
2021-03-06 18:59:00 +00:00
background: rgba(0, 0, 0, 0.2);
2021-03-06 17:07:06 +00:00
}
2021-03-05 16:01:54 +00:00
2021-03-06 17:07:06 +00:00
.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;
2021-03-06 18:59:00 +00:00
transition: all 0.1s;
2021-03-06 17:07:06 +00:00
}
</style>
<div class="mainlogo"></div>
<div class="tabsContainer">
${this.tabs.map(tabArg => {
return html`
2021-03-06 18:59:00 +00:00
<div class="tab ${tabArg === this.selectedTab ? 'selectedTab': null}" @click="${() => {this.updateTab(tabArg)}}">
2021-03-06 17:07:06 +00:00
<dees-icon iconName="${tabArg.iconName}"></dees-icon>
<div class="label">${tabArg.key}</div>
</div>
`;
})}
2021-03-05 16:01:54 +00:00
</div>
2021-03-06 17:07:06 +00:00
<div class="tabIndicator"></div>
2021-03-05 16:01:54 +00:00
`;
}
2021-03-06 17:07:06 +00:00
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';
}
2021-03-06 18:59:00 +00:00
updateTab(tabArg: interfaces.ITab) {
this.selectedTab = tabArg;
2021-03-06 17:07:06 +00:00
this.updateTabIndicator();
2021-03-06 18:59:00 +00:00
this.selectedTab.action();
}
firstUpdated() {
this.updateTab(this.tabs[0]);
2021-03-06 17:07:06 +00:00
}
}