ion-tab.js 3.2 KB

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