2020-11-26 22:31:56 +00:00
|
|
|
import { LitElement, html, customElement, property } 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
|
|
|
|
2020-11-20 21:08:00 +00:00
|
|
|
@customElement("pb-tabs")
|
|
|
|
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-11-26 22:31:56 +00:00
|
|
|
static get styles() {
|
|
|
|
return [GlobalsStyle, TabsStyle];
|
2020-11-08 21:43:46 +00:00
|
|
|
}
|
|
|
|
|
2020-11-26 22:31:56 +00:00
|
|
|
render() {
|
2020-12-01 08:15:41 +00:00
|
|
|
const pages = Array.from(this.querySelectorAll("[slot]")!);
|
2020-11-26 22:31:56 +00:00
|
|
|
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
|
|
|
}
|
2020-11-26 22:31:56 +00:00
|
|
|
return html`<div class="pf-c-tabs">
|
|
|
|
<ul class="pf-c-tabs__list">
|
|
|
|
${pages.map((page) => {
|
2020-12-01 08:15:41 +00:00
|
|
|
const slot = page.attributes.getNamedItem("slot")?.value;
|
|
|
|
return html` <li
|
2020-11-26 22:31:56 +00:00
|
|
|
class="pf-c-tabs__item ${slot === this.currentPage
|
2020-12-01 08:15:41 +00:00
|
|
|
? CURRENT_CLASS
|
|
|
|
: ""}"
|
2020-11-26 22:31:56 +00:00
|
|
|
>
|
|
|
|
<button
|
|
|
|
class="pf-c-tabs__link"
|
|
|
|
@click=${() => {
|
2020-12-01 08:15:41 +00:00
|
|
|
this.currentPage = slot;
|
|
|
|
}}
|
2020-11-26 22:31:56 +00:00
|
|
|
>
|
|
|
|
<span class="pf-c-tabs__item-text">
|
2020-11-26 22:35:59 +00:00
|
|
|
${page.attributes.getNamedItem("tab-title")?.value}
|
2020-11-26 22:31:56 +00:00
|
|
|
</span>
|
|
|
|
</button>
|
|
|
|
</li>`;
|
2020-12-01 08:15:41 +00:00
|
|
|
})}
|
2020-11-26 22:31:56 +00:00
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
<slot name="${this.currentPage}"></slot>`;
|
2020-11-08 21:43:46 +00:00
|
|
|
}
|
|
|
|
}
|