UNPKG

@salla.sa/twilight-components

Version:
158 lines (148 loc) 4.96 kB
/*! * Crafted with ❤ by Salla */ 'use strict'; var index = require('./index-B99uI20k.js'); const sallaTabContentCss = ""; const SallaTabContent = class { constructor(hostRef) { index.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 (index.h("div", { key: '13737e2a7a7bce59e8ddc38b3b4d5159a4aa67be', class: classes }, index.h("slot", { key: '56dbae26f78adaf732311a06ec7f9f70e3d4eb2d' }))); } }; SallaTabContent.style = sallaTabContentCss; function generateRandomId() { return Math.random().toString(36).slice(2, 10); } const sallaTabHeaderCss = ""; const SallaTabHeader = class { constructor(hostRef) { index.registerInstance(this, hostRef); this.tabSelected = index.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 [ index.h("div", { key: '4c2cba9724d8f130fbf44e50f4dcb27e5a2b4a7c', class: classes, onClick: this.onClick.bind(this) }, index.h("slot", { key: 'e03cda2c201eef0f33ea21e99144b70beee4c998' })), ]; } }; 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) { index.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 [ index.h("div", { key: '49df0b08c12cc094afbcbdc106b02a9766a5b8e4', class: "s-tabs" }, index.h("div", { key: '02979fdfce4e6ada2caafd6a165b241b885e05b0', class: "s-tabs-header" }, index.h("slot", { key: '9919372225fd8be367648689337476f9dacc4ca4', name: "header" })), index.h("div", { key: '021f811beb02ebb93c788f989dfc39d994261caa', class: "s-tabs-content-wrapper" }, index.h("slot", { key: '5a5670d0be835306dfc29771b58d022bd092d057', name: "content" }))) ]; } get host() { return index.getElement(this); } }; SallaTabs.style = sallaTabsCss; exports.salla_tab_content = SallaTabContent; exports.salla_tab_header = SallaTabHeader; exports.salla_tabs = SallaTabs;