@ionic/core
Version:
Base components for Ionic
4 lines • 4.19 kB
JavaScript
/*!
* (C) Ionic http://ionicframework.com - MIT License
*/
import{r as t,j as i,h as s,d as e,g as o,c as a}from"./p-C8IsBmNU.js";import{a as n}from"./p-D-eFFUkA.js";import"./p-CTfR9YZG.js";const h=class{constructor(i){t(this,i),this.loaded=!1,this.active=!1}async componentWillLoad(){this.active&&await this.setActive()}async setActive(){await this.prepareLazyLoaded(),this.active=!0}changeActive(t){t&&this.prepareLazyLoaded()}prepareLazyLoaded(){if(!this.loaded&&null!=this.component){this.loaded=!0;try{return n(this.delegate,this.el,this.component,["ion-page"])}catch(t){i("[ion-tab] - Exception in prepareLazyLoaded:",t)}}return Promise.resolve(void 0)}render(){const{tab:t,active:i,component:o}=this;return s(e,{key:"dbad8fe9f1566277d14647626308eaf1601ab01f",role:"tabpanel","aria-hidden":i?null:"true","aria-labelledby":`tab-button-${t}`,class:{"ion-page":void 0===o,"tab-hidden":!i}},s("slot",{key:"3be64f4e7161f6769aaf8e4dcb5293fcaa09af45"}))}get el(){return o(this)}static get watchers(){return{active:["changeActive"]}}};h.style=":host(.tab-hidden){display:none !important}";const r=class{constructor(i){t(this,i),this.ionNavWillLoad=a(this,"ionNavWillLoad",7),this.ionTabsWillChange=a(this,"ionTabsWillChange",3),this.ionTabsDidChange=a(this,"ionTabsDidChange",3),this.transitioning=!1,this.useRouter=!1,this.onTabClicked=t=>{const{href:i,tab:s}=t.detail;if(this.useRouter&&void 0!==i){const t=document.querySelector("ion-router");t&&t.push(i)}else this.select(s)}}async componentWillLoad(){if(this.useRouter||(this.useRouter=!(!this.el.querySelector("ion-router-outlet")&&!document.querySelector("ion-router")||this.el.closest("[no-router]"))),!this.useRouter){const t=this.tabs;t.length>0&&await this.select(t[0])}this.ionNavWillLoad.emit()}componentDidLoad(){this.updateTabBar()}componentDidUpdate(){this.updateTabBar()}updateTabBar(){const t=this.el.querySelector("ion-tab-bar");if(!t)return;const i=this.selectedTab?this.selectedTab.tab:void 0;void 0!==i&&t.selectedTab!==i&&(t.selectedTab=i)}async select(t){const i=c(this.tabs,t);return!!this.shouldSwitch(i)&&(await this.setActive(i),await this.notifyRouter(),this.tabSwitch(),!0)}async getTab(t){return c(this.tabs,t)}getSelected(){return Promise.resolve(this.selectedTab?this.selectedTab.tab:void 0)}async setRouteId(t){const i=c(this.tabs,t);return this.shouldSwitch(i)?(await this.setActive(i),{changed:!0,element:this.selectedTab,markVisible:()=>this.tabSwitch()}):{changed:!1,element:this.selectedTab}}async getRouteId(){var t;const i=null===(t=this.selectedTab)||void 0===t?void 0:t.tab;return void 0!==i?{id:i,element:this.selectedTab}:void 0}setActive(t){return this.transitioning?Promise.reject("transitioning already happening"):(this.transitioning=!0,this.leavingTab=this.selectedTab,this.selectedTab=t,this.ionTabsWillChange.emit({tab:t.tab}),t.active=!0,this.updateTabBar(),Promise.resolve())}tabSwitch(){const t=this.selectedTab,i=this.leavingTab;this.leavingTab=void 0,this.transitioning=!1,t&&i!==t&&(i&&(i.active=!1),this.ionTabsDidChange.emit({tab:t.tab}))}notifyRouter(){if(this.useRouter){const t=document.querySelector("ion-router");if(t)return t.navChanged("forward")}return Promise.resolve(!1)}shouldSwitch(t){return void 0!==t&&t!==this.selectedTab&&!this.transitioning}get tabs(){return Array.from(this.el.querySelectorAll("ion-tab"))}render(){return s(e,{key:"7b4b302f2942d8d131f6fc24e817989a8be08867",onIonTabButtonClick:this.onTabClicked},s("slot",{key:"2c51cf14c0f17a8ddf2d879858c984cdf8fd3147",name:"top"}),s("div",{key:"7e9d6055092d41bd9bc80ae15965f77e216feb84",class:"tabs-inner"},s("slot",{key:"c308a787e37ff7f6653531d70deca597a7602d26"})),s("slot",{key:"d5f5e693710c853570811602f859cf3e88272684",name:"bottom"}))}get el(){return o(this)}},c=(t,s)=>{const e="string"==typeof s?t.find((t=>t.tab===s)):s;return e||i(`[ion-tabs] - Tab with id: "${e}" does not exist`),e};r.style=":host{left:0;right:0;top:0;bottom:0;display:-ms-flexbox;display:flex;position:absolute;-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}";export{h as ion_tab,r as ion_tabs}