@stories-js/core
Version:
Stories web components to build stories
5 lines • 1.69 kB
JavaScript
/*!
* (C) StoriesJS https://storiesjs.org - GPL-2.0 License
*/
import{r as t,h as s,c as i,g as e}from"./p-dea5a230.js";const n=":host{display:-ms-flexbox;display:flex;position:relative;-ms-flex-direction:column;flex-direction:column;width:100%;height:100%;contain:layout size style;z-index:0}.tabs-inner{position:relative;-ms-flex:1;flex:1;contain:layout size style}";const o=(t,s)=>{const i=typeof s==="string"?t.find((t=>t.tab===s)):s;if(!i){console.error(`tab with id: "${i}" does not exist`)}return i};const r=class{constructor(s){t(this,s);this.onTabClicked=t=>{const{tab:s}=t.detail;this.select(s)}}async componentWillLoad(){const t=this.tabs;if(t.length>0){await this.select(t[0])}}componentWillRender(){const t=this.el.querySelector("stories-tab-bar");if(t){const s=this.selectedTab?this.selectedTab.tab:undefined;t.selectedTab=s}}async select(t){const s=o(this.tabs,t);if(!this.shouldSwitch(s)){return false}await this.setActive(s);this.tabSwitch();return true}async getTab(t){return o(this.tabs,t)}getSelected(){return Promise.resolve(this.selectedTab?this.selectedTab.tab:undefined)}setActive(t){this.leavingTab=this.selectedTab;this.selectedTab=t;t.active=true;return Promise.resolve()}tabSwitch(){const t=this.selectedTab;const s=this.leavingTab;this.leavingTab=undefined;if(!t){return}if(s!==t){if(s){s.active=false}}}shouldSwitch(t){const s=this.selectedTab;return t!==undefined&&t!==s}get tabs(){return Array.from(this.el.querySelectorAll("stories-tab"))}render(){return s(i,{onStoriesTabButtonClick:this.onTabClicked},s("div",{class:"tabs-inner"},s("slot",null)))}get el(){return e(this)}};r.style=n;export{r as stories_tabs};
//# sourceMappingURL=p-72c27c6c.entry.js.map