UNPKG

@salla.sa/twilight-components

Version:
79 lines (75 loc) 2.97 kB
/*! * Crafted with ❤ by Salla */ import { proxyCustomElement, HTMLElement, h } from '@stencil/core/internal/client'; const sallaTabsCss = ".s-tabs-header{-ms-overflow-style:none;scrollbar-width:none;}.s-tabs-header::-webkit-scrollbar{display:none}"; const SallaTabs = /*@__PURE__*/ proxyCustomElement(class SallaTabs extends HTMLElement { constructor() { super(); this.__registerHost(); /** * Background color */ this.backgroundColor = undefined; /** * Align tabs vertically. */ this.vertical = false; } componentWillLoad() { this.createGroup().then(() => { const [group] = this.tabGroup; this.selectGroup(group); }); } onSelectedTab(event) { const group = this.tabGroup.find(group => group.header.id === event.detail.id); this.selectGroup(group); } async createGroup() { const tabsHeaderEl = Array.from(this.host.querySelectorAll('salla-tab-header')); this.tabsHeader = await Promise.all(tabsHeaderEl.map(async (el) => await el.getChild())); const tabsContentEl = Array.from(this.host.querySelectorAll('salla-tab-content')); this.tabsContent = await Promise.all(tabsContentEl.map(async (el) => await el.getChild())); this.tabGroup = this.tabsHeader.map(header => { const content = this.tabsContent.find(content => content.name === header.name); return { header: header, content: content }; }); } selectGroup(group) { this.tabGroup.map(g => { g.header.unselect(); g.content.unselect(); }); group.header.selected(); group.content.selected(); } render() { return [ h("div", { key: '1d2c28a8025c9c9c1d988dbded489263794cb92e', class: "s-tabs" }, h("div", { key: '54f011017f5378e7053b4f3a135d6a050e08479c', class: "s-tabs-header" }, h("slot", { key: 'efd25fb8dd73b9296015be1e224b84fc53ab9082', name: "header" })), h("div", { key: 'f80582281746ae231092360e26d65331cc98f480', class: "s-tabs-content-wrapper" }, h("slot", { key: 'c97cde11dcbd37124dc1c24559c918111c57e6fe', name: "content" }))) ]; } get host() { return this; } static get style() { return sallaTabsCss; } }, [4, "salla-tabs", { "backgroundColor": [1, "background-color"], "vertical": [4] }, [[0, "tabSelected", "onSelectedTab"]]]); function defineCustomElement() { if (typeof customElements === "undefined") { return; } const components = ["salla-tabs"]; components.forEach(tagName => { switch (tagName) { case "salla-tabs": if (!customElements.get(tagName)) { customElements.define(tagName, SallaTabs); } break; } }); } defineCustomElement(); export { SallaTabs as S, defineCustomElement as d };