2020-12-01 16:27:19 +00:00
|
|
|
import { LitElement, html, customElement, property, CSSResult, TemplateResult } from "lit-element";
|
2020-12-02 14:44:40 +00:00
|
|
|
import { ifDefined } from "lit-html/directives/if-defined";
|
2020-11-26 22:31:56 +00:00
|
|
|
// @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-12-05 21:08:42 +00:00
|
|
|
import { gettext } from "django";
|
2020-11-08 21:43:46 +00:00
|
|
|
|
2020-12-05 21:08:42 +00:00
|
|
|
@customElement("ak-tabs")
|
2020-11-20 21:08:00 +00:00
|
|
|
export class Tabs extends LitElement {
|
2020-11-26 22:31:56 +00:00
|
|
|
@property()
|
|
|
|
currentPage?: string;
|
2020-11-08 21:43:46 +00:00
|
|
|
|
2020-12-01 16:27:19 +00:00
|
|
|
static get styles(): CSSResult[] {
|
2020-11-26 22:31:56 +00:00
|
|
|
return [GlobalsStyle, TabsStyle];
|
2020-11-08 21:43:46 +00:00
|
|
|
}
|
|
|
|
|
2020-12-01 16:27:19 +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">
|
2020-12-05 21:08:42 +00:00
|
|
|
${page.getAttribute("data-tab-title")}
|
2020-12-01 16:27:19 +00:00
|
|
|
</span>
|
|
|
|
</button>
|
|
|
|
</li>`;
|
|
|
|
}
|
|
|
|
|
|
|
|
render(): TemplateResult {
|
2021-01-16 22:04:08 +00:00
|
|
|
const pages = Array.from(this.querySelectorAll("[slot^='page-']"));
|
2020-11-26 22:31:56 +00:00
|
|
|
if (!this.currentPage) {
|
|
|
|
if (pages.length < 1) {
|
2020-12-05 21:08:42 +00:00
|
|
|
return html`<h1>${gettext("no tabs defined")}</h1>`;
|
2020-11-26 22:31:56 +00:00
|
|
|
}
|
|
|
|
this.currentPage = pages[0].attributes.getNamedItem("slot")?.value;
|
2020-11-08 21:43:46 +00:00
|
|
|
}
|
2020-11-26 22:31:56 +00:00
|
|
|
return html`<div class="pf-c-tabs">
|
|
|
|
<ul class="pf-c-tabs__list">
|
2020-12-01 16:27:19 +00:00
|
|
|
${pages.map((page) => this.renderTab(page))}
|
2020-11-26 22:31:56 +00:00
|
|
|
</ul>
|
|
|
|
</div>
|
2020-12-02 14:44:40 +00:00
|
|
|
<slot name="${ifDefined(this.currentPage)}"></slot>`;
|
2020-11-08 21:43:46 +00:00
|
|
|
}
|
|
|
|
}
|