import { t } from "@lingui/macro"; import { CSSResult, LitElement, TemplateResult, css, html } from "lit"; import { customElement, property } from "lit/decorators.js"; import { ifDefined } from "lit/directives/if-defined.js"; import AKGlobal from "../authentik.css"; import PFTabs from "@patternfly/patternfly/components/Tabs/tabs.css"; import PFGlobal from "@patternfly/patternfly/patternfly-base.css"; import { CURRENT_CLASS, EVENT_REFRESH, ROUTE_SEPARATOR } from "../constants"; import { getURLParams, updateURLParams } from "./router/RouteMatch"; @customElement("ak-tabs") export class Tabs extends LitElement { @property() pageIdentifier = "page"; @property() currentPage?: string; @property({ type: Boolean }) vertical = false; static get styles(): CSSResult[] { return [ PFGlobal, PFTabs, AKGlobal, css` ::slotted(*) { flex-grow: 2; } :host([vertical]) { display: flex; } :host([vertical]) .pf-c-tabs { width: auto !important; } :host([vertical]) .pf-c-tabs__list { height: 100%; } `, ]; } observer: MutationObserver; constructor() { super(); this.observer = new MutationObserver(() => { this.requestUpdate(); }); } connectedCallback(): void { super.connectedCallback(); this.observer.observe(this, { attributes: true, childList: true, subtree: true, }); } disconnectedCallback(): void { this.observer.disconnect(); super.disconnectedCallback(); } onClick(slot?: string): void { this.currentPage = slot; const params: { [key: string]: string | undefined } = {}; params[this.pageIdentifier] = slot; updateURLParams(params); const page = this.querySelector(`[slot='${this.currentPage}']`); if (!page) return; page.dispatchEvent( new CustomEvent(EVENT_REFRESH, { bubbles: true, composed: true, }), ); } renderTab(page: Element): TemplateResult { const slot = page.attributes.getNamedItem("slot")?.value; return html`