This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
authentik/web/src/elements/Tabs.ts

44 lines
1.6 KiB
TypeScript
Raw Normal View History

import { LitElement, html, customElement, property, CSSResult, TemplateResult } from "lit-element";
// @ts-ignore
import TabsStyle from "@patternfly/patternfly/components/Tabs/tabs.css";
// @ts-ignore
import GlobalsStyle from "@patternfly/patternfly/base/patternfly-globals.css";
import { CURRENT_CLASS } from "../constants";
2020-11-08 21:43:46 +00:00
@customElement("pb-tabs")
export class Tabs extends LitElement {
@property()
currentPage?: string;
2020-11-08 21:43:46 +00:00
static get styles(): CSSResult[] {
return [GlobalsStyle, TabsStyle];
2020-11-08 21:43:46 +00:00
}
renderTab(page: Element): TemplateResult {
const slot = page.attributes.getNamedItem("slot")?.value;
return html` <li class="pf-c-tabs__item ${slot === this.currentPage ? CURRENT_CLASS : ""}">
<button class="pf-c-tabs__link" @click=${() => { this.currentPage = slot; }}>
<span class="pf-c-tabs__item-text">
${page.attributes.getNamedItem("tab-title")?.value}
</span>
</button>
</li>`;
}
render(): TemplateResult {
const pages = Array.from(this.querySelectorAll("[slot]"));
if (!this.currentPage) {
if (pages.length < 1) {
return html`<h1>no tabs defined</h1>`;
}
this.currentPage = pages[0].attributes.getNamedItem("slot")?.value;
2020-11-08 21:43:46 +00:00
}
return html`<div class="pf-c-tabs">
<ul class="pf-c-tabs__list">
${pages.map((page) => this.renderTab(page))}
</ul>
</div>
<slot name="${this.currentPage}"></slot>`;
2020-11-08 21:43:46 +00:00
}
}