UNPKG

@salla.sa/twilight-components

Version:
154 lines (145 loc) 4.91 kB
/*! * Crafted with ❤ by Salla */ import { r as registerInstance, h, c as createEvent, a as getElement } from './index-BQQ2x3w_.js'; const sallaTabContentCss = ""; const SallaTabContent = class { constructor(hostRef) { registerInstance(this, hostRef); this.isSelected = false; } /** * Expose self for the parent. */ async getChild() { return { selected: this.selected.bind(this), unselect: this.unselect.bind(this), name: this.name }; } unselect() { this.isSelected = false; } selected() { this.isSelected = true; } render() { const classes = { 's-tabs-content': true, 's-tabs-content-selected': this.isSelected }; return (h("div", { key: '6272014593c424e20e4fc9cc2c59dc5c4bd1abc1', class: classes }, h("slot", { key: 'd7a3c32021cc14da0d895b5830c0cf3c8a047529' }))); } }; SallaTabContent.style = sallaTabContentCss; function generateRandomId() { return Math.random().toString(36).slice(2, 10); } const sallaTabHeaderCss = ""; const SallaTabHeader = class { constructor(hostRef) { registerInstance(this, hostRef); this.tabSelected = createEvent(this, "tabSelected"); this.id = generateRandomId(); /** * The class applied to the currently active(selected) tab */ this.activeClass = undefined; /** * Set the height of the tab bar */ this.height = undefined; /** * Center tab items in the given flex. */ this.centered = false; this.isSelected = false; } /** * Expose self for the parent. */ async getChild() { return { selected: this.selected.bind(this), unselect: this.unselect.bind(this), name: this.name, id: this.id }; } unselect() { this.isSelected = false; } selected() { this.isSelected = true; } onClick() { this.getChild().then(child => { this.tabSelected.emit(child); }); } render() { const classes = { 's-tabs-header-item': true, 's-tabs-bg-normal': true, 's-tabs-active': this.isSelected, }; return [ h("div", { key: '5ac0d60331466d359ff0ba59d7702b177c96d95b', class: classes, onClick: this.onClick.bind(this) }, h("slot", { key: 'dc8ed7ec638ba1c24b355eedc831c67ab15ded62' })), ]; } }; SallaTabHeader.style = sallaTabHeaderCss; const sallaTabsCss = ".s-tabs-header{-ms-overflow-style:none;scrollbar-width:none;}.s-tabs-header::-webkit-scrollbar{display:none}"; const SallaTabs = class { constructor(hostRef) { registerInstance(this, hostRef); /** * 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: '32051cc4308a49527f424d2bd0ce42a1ae25b8d4', class: "s-tabs" }, h("div", { key: '5d99d5835d8f3686f38a51f2eb049887d9f7229b', class: "s-tabs-header" }, h("slot", { key: '5b78f92eb7ffe9ad56c235415ae4ea93b0ed3c1d', name: "header" })), h("div", { key: '8979a8c600d60ed79ae8ebb6894754ab3ab7be97', class: "s-tabs-content-wrapper" }, h("slot", { key: '629a4e9b7934a0074a6e7579645e08e0b37c7e61', name: "content" }))) ]; } get host() { return getElement(this); } }; SallaTabs.style = sallaTabsCss; export { SallaTabContent as salla_tab_content, SallaTabHeader as salla_tab_header, SallaTabs as salla_tabs };