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

142 lines
3.3 KiB
TypeScript
Raw Normal View History

2022-05-02 11:43:55 +00:00
import * as interfaces from './interfaces/index.js';
2021-03-06 17:07:06 +00:00
import {
DeesElement,
TemplateResult,
property,
customElement,
html,
2022-01-31 13:07:15 +00:00
css,
cssManager,
2021-03-06 17:07:06 +00:00
} from '@designestate/dees-element';
2021-03-05 16:01:54 +00:00
import * as domtools from '@designestate/dees-domtools';
import '@designestate/dees-catalog';
2022-11-18 00:30:36 +00:00
@customElement('lele-appui-mainmenu')
2021-03-05 16:01:54 +00:00
export class DeapMainmenu extends DeesElement {
2022-11-18 00:30:36 +00:00
public static demo = () => html`<lele-appui-mainmenu></lele-appui-mainmenu>`;
2021-03-05 16:01:54 +00:00
// INSTANCE
2021-03-06 17:07:06 +00:00
2022-01-31 13:07:15 +00:00
// 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 static styles = [
cssManager.defaultStyles,
css`
: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 {
2022-06-10 14:26:12 +00:00
padding-top: 18px;
font-size: 24px;
2022-01-31 13:07:15 +00:00
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;
2022-06-10 14:26:12 +00:00
margin-top: 4px;
2022-01-31 13:07:15 +00:00
}
.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;
}
`,
];
2021-03-06 17:07:06 +00:00
public render(): TemplateResult {
2021-03-05 16:01:54 +00:00
return html`
2022-01-31 13:07:15 +00:00
<style></style>
2021-03-06 17:07:06 +00:00
<div class="mainlogo"></div>
<div class="tabsContainer">
2022-01-31 13:07:15 +00:00
${this.tabs.map((tabArg) => {
2021-03-06 17:07:06 +00:00
return html`
2022-01-31 13:07:15 +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);
2022-01-31 13:07:15 +00:00
const selectedTabElement: HTMLElement = this.shadowRoot.querySelector(
`.tabsContainer .tab:nth-child(${tabIndex + 1})`
);
2021-03-06 17:07:06 +00:00
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
}
}