UNPKG

2.56 kBJavaScriptView Raw
1/*!
2 * (C) Ionic http://ionicframework.com - MIT License
3 */
4import { proxyCustomElement, HTMLElement, Build, h, Host } from '@stencil/core/internal/client';
5import { a as attachComponent } from './framework-delegate.js';
6
7const tabCss = ":host(.tab-hidden){display:none !important}";
8
9const Tab = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
10 constructor() {
11 super();
12 this.__registerHost();
13 this.__attachShadow();
14 this.loaded = false;
15 /** @internal */
16 this.active = false;
17 }
18 async componentWillLoad() {
19 if (Build.isDev) {
20 if (this.component !== undefined && this.el.childElementCount > 0) {
21 console.error('You can not use a lazy-loaded component in a tab and inlined content at the same time.' +
22 `- Remove the component attribute in: <ion-tab component="${this.component}">` +
23 ` or` +
24 `- Remove the embedded content inside the ion-tab: <ion-tab></ion-tab>`);
25 }
26 }
27 if (this.active) {
28 await this.setActive();
29 }
30 }
31 /** Set the active component for the tab */
32 async setActive() {
33 await this.prepareLazyLoaded();
34 this.active = true;
35 }
36 changeActive(isActive) {
37 if (isActive) {
38 this.prepareLazyLoaded();
39 }
40 }
41 prepareLazyLoaded() {
42 if (!this.loaded && this.component != null) {
43 this.loaded = true;
44 try {
45 return attachComponent(this.delegate, this.el, this.component, ['ion-page']);
46 }
47 catch (e) {
48 console.error(e);
49 }
50 }
51 return Promise.resolve(undefined);
52 }
53 render() {
54 const { tab, active, component } = this;
55 return (h(Host, { role: "tabpanel", "aria-hidden": !active ? 'true' : null, "aria-labelledby": `tab-button-${tab}`, class: {
56 'ion-page': component === undefined,
57 'tab-hidden': !active
58 } }, h("slot", null)));
59 }
60 get el() { return this; }
61 static get watchers() { return {
62 "active": ["changeActive"]
63 }; }
64 static get style() { return tabCss; }
65}, [1, "ion-tab", {
66 "active": [1028],
67 "delegate": [16],
68 "tab": [1],
69 "component": [1],
70 "setActive": [64]
71 }]);
72function defineCustomElement$1() {
73 if (typeof customElements === "undefined") {
74 return;
75 }
76 const components = ["ion-tab"];
77 components.forEach(tagName => { switch (tagName) {
78 case "ion-tab":
79 if (!customElements.get(tagName)) {
80 customElements.define(tagName, Tab);
81 }
82 break;
83 } });
84}
85
86const IonTab = Tab;
87const defineCustomElement = defineCustomElement$1;
88
89export { IonTab, defineCustomElement };