@salla.sa/twilight-components
Version:
Salla Web Component
4 lines • 2.68 kB
JavaScript
/*!
* Crafted with ❤ by Salla
*/
import{r as s,h as t,c as e,a}from"./p-CFtXUFT2.js";const c=class{constructor(t){s(this,t),this.isSelected=!1}async getChild(){return{selected:this.selected.bind(this),unselect:this.unselect.bind(this),name:this.name}}unselect(){this.isSelected=!1}selected(){this.isSelected=!0}render(){return t("div",{key:"59729323fd707b74b2b1fd8707fcb122ee21ed9f",class:{"s-tabs-content":!0,"s-tabs-content-selected":this.isSelected}},t("slot",{key:"a273156c8bbb3dbf25dc2e556d060c4402a8a394"}))}};c.style="";const i=class{constructor(t){s(this,t),this.tabSelected=e(this,"tabSelected"),this.id=Math.random().toString(36).slice(2,10),this.activeClass=void 0,this.height=void 0,this.centered=!1,this.isSelected=!1}async getChild(){return{selected:this.selected.bind(this),unselect:this.unselect.bind(this),name:this.name,id:this.id}}unselect(){this.isSelected=!1}selected(){this.isSelected=!0}onClick(){this.getChild().then((s=>{this.tabSelected.emit(s)}))}render(){return[t("div",{key:"cdeff834ff1a1e4a5cd19c52e5c36bcc51491064",class:{"s-tabs-header-item":!0,"s-tabs-bg-normal":!0,"s-tabs-active":this.isSelected},onClick:this.onClick.bind(this)},t("slot",{key:"5aeedafb3c074f588cd2a343fe48fc5b8807821d"}))]}};i.style="";const h=class{constructor(t){s(this,t),this.backgroundColor=void 0,this.vertical=!1}componentWillLoad(){this.createGroup().then((()=>{const[s]=this.tabGroup;this.selectGroup(s)}))}onSelectedTab(s){const t=this.tabGroup.find((t=>t.header.id===s.detail.id));this.selectGroup(t)}async createGroup(){const s=Array.from(this.host.querySelectorAll("salla-tab-header"));this.tabsHeader=await Promise.all(s.map((async s=>await s.getChild())));const t=Array.from(this.host.querySelectorAll("salla-tab-content"));this.tabsContent=await Promise.all(t.map((async s=>await s.getChild()))),this.tabGroup=this.tabsHeader.map((s=>{const t=this.tabsContent.find((t=>t.name===s.name));return{header:s,content:t}}))}selectGroup(s){this.tabGroup.map((s=>{s.header.unselect(),s.content.unselect()})),s.header.selected(),s.content.selected()}render(){return[t("div",{key:"1d2c28a8025c9c9c1d988dbded489263794cb92e",class:"s-tabs"},t("div",{key:"54f011017f5378e7053b4f3a135d6a050e08479c",class:"s-tabs-header"},t("slot",{key:"efd25fb8dd73b9296015be1e224b84fc53ab9082",name:"header"})),t("div",{key:"f80582281746ae231092360e26d65331cc98f480",class:"s-tabs-content-wrapper"},t("slot",{key:"c97cde11dcbd37124dc1c24559c918111c57e6fe",name:"content"})))]}get host(){return a(this)}};h.style=".s-tabs-header{-ms-overflow-style:none;scrollbar-width:none;}.s-tabs-header::-webkit-scrollbar{display:none}";export{c as salla_tab_content,i as salla_tab_header,h as salla_tabs}