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

138 lines
3.4 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,
2023-09-06 22:18:00 +00:00
type TemplateResult,
2021-03-06 17:07:06 +00:00
property,
customElement,
html,
2022-01-31 13:07:15 +00:00
css,
cssManager,
2023-09-06 16:43:33 +00:00
} from '@design.estate/dees-element';
2021-03-05 16:01:54 +00:00
2023-09-06 16:43:33 +00:00
import * as domtools from '@design.estate/dees-domtools';
import '@design.estate/dees-catalog';
2021-03-05 16:01:54 +00:00
2023-01-19 11:41:14 +00:00
/**
* the most left menu
* usually used as organization selector
*/
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[] = [
2023-01-11 23:29:23 +00:00
{ key: 'option 1', iconName: 'building', action: () => {} },
{ key: 'option 2', iconName: 'building', action: () => {} },
{ key: 'option 3', iconName: 'building', action: () => {} },
{ key: 'option 4', iconName: 'building', action: () => {} },
2022-01-31 13:07:15 +00:00
];
@property()
public selectedTab: interfaces.ITab;
public static styles = [
cssManager.defaultStyles,
css`
:host {
2023-09-06 16:43:33 +00:00
--menuSize: 60px;
2022-01-31 13:07:15 +00:00
color: #ccc;
z-index: 10;
display: block;
position: relative;
2023-09-06 16:43:33 +00:00
width: var(--menuSize);
2022-01-31 13:07:15 +00:00
height: 100%;
2023-09-06 16:43:33 +00:00
background: #000000;
2022-01-31 13:07:15 +00:00
box-shadow: 0px 0px 5px rgba(0, 0, 0, 0.5);
user-select: none;
2023-09-06 16:43:33 +00:00
border-right: 1px solid #202020;
2022-01-31 13:07:15 +00:00
}
.tabsContainer {
}
.tab {
2022-06-10 14:26:12 +00:00
padding-top: 18px;
font-size: 24px;
2023-09-06 16:43:33 +00:00
width: var(--menuSize);
height: var(--menuSize);
2022-01-31 13:07:15 +00:00
text-align: center;
cursor: pointer;
transition: color 0.1s, background 0.2s;
}
.tab:hover {
2023-09-06 16:43:33 +00:00
background: rgba(255, 255, 255, 0.15);
2022-01-31 13:07:15 +00:00
}
.tab.selectedTab {
color: #fff;
2023-09-06 16:43:33 +00:00
background: rgba(255, 255, 255, 0.1);
2022-01-31 13:07:15 +00:00
}
.tabIndicator {
2023-09-06 16:43:33 +00:00
opacity: 0;
2022-01-31 13:07:15 +00:00
background: #4e729a;
position: absolute;
2023-09-06 16:43:33 +00:00
width: 5px;
height: calc((var(--menuSize) / 3) * 2);
2022-01-31 13:07:15 +00:00
left: 0px;
2023-09-06 16:43:33 +00:00
top: calc(var(--menuSize) - (((var(--menuSize) / 3) * 2) / 2));
2022-01-31 13:07:15 +00:00
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="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);
}}"
>
2023-09-06 16:43:33 +00:00
<dees-icon iconFA="${tabArg.iconName as any}"></dees-icon>
2021-03-06 17:07:06 +00:00
</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');
2023-09-06 16:43:33 +00:00
const offsetTop = selectedTabElement.offsetTop;
tabIndicator.style.opacity = `1`;
tabIndicator.style.top = `calc(${offsetTop}px + (var(--menuSize) / 6))`;
2021-03-06 17:07:06 +00:00
}
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
}
}