ion-tab-bar.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*!
  2. * (C) Ionic http://ionicframework.com - MIT License
  3. */
  4. import { proxyCustomElement, HTMLElement, createEvent, h, Host } from '@stencil/core/internal/client';
  5. import { c as createKeyboardController } from './keyboard-controller.js';
  6. import { c as createColorClasses } from './theme.js';
  7. import { b as getIonMode } from './ionic-global.js';
  8. const tabBarIosCss = ":host{display:-ms-flexbox;display:flex;-ms-flex-align:center;align-items:center;-ms-flex-pack:center;justify-content:center;width:auto;padding-right:var(--ion-safe-area-right);padding-bottom:var(--ion-safe-area-bottom, 0);padding-left:var(--ion-safe-area-left);border-top:var(--border);background:var(--background);color:var(--color);text-align:center;contain:strict;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;z-index:10;-webkit-box-sizing:content-box !important;box-sizing:content-box !important}:host(.ion-color) ::slotted(ion-tab-button){--background-focused:var(--ion-color-shade);--color-selected:var(--ion-color-contrast)}:host(.ion-color) ::slotted(.tab-selected){color:var(--ion-color-contrast)}:host(.ion-color),:host(.ion-color) ::slotted(ion-tab-button){color:rgba(var(--ion-color-contrast-rgb), 0.7)}:host(.ion-color),:host(.ion-color) ::slotted(ion-tab-button){background:var(--ion-color-base)}:host(.ion-color) ::slotted(ion-tab-button.ion-focused),:host(.tab-bar-translucent) ::slotted(ion-tab-button.ion-focused){background:var(--background-focused)}:host(.tab-bar-translucent) ::slotted(ion-tab-button){background:transparent}:host([slot=top]){padding-top:var(--ion-safe-area-top, 0);padding-bottom:0;border-top:0;border-bottom:var(--border)}:host(.tab-bar-hidden){display:none !important}:host{--background:var(--ion-tab-bar-background, var(--ion-color-step-50, var(--ion-background-color-step-50, #f7f7f7)));--background-focused:var(--ion-tab-bar-background-focused, #e0e0e0);--border:0.55px solid var(--ion-tab-bar-border-color, var(--ion-border-color, var(--ion-color-step-150, var(--ion-background-color-step-150, rgba(0, 0, 0, 0.2)))));--color:var(--ion-tab-bar-color, var(--ion-color-step-600, var(--ion-text-color-step-400, #666666)));--color-selected:var(--ion-tab-bar-color-selected, var(--ion-color-primary, #0054e9));height:50px}@supports ((-webkit-backdrop-filter: blur(0)) or (backdrop-filter: blur(0))){:host(.tab-bar-translucent){--background:rgba(var(--ion-background-color-rgb, 255, 255, 255), 0.8);-webkit-backdrop-filter:saturate(210%) blur(20px);backdrop-filter:saturate(210%) blur(20px)}:host(.ion-color.tab-bar-translucent){background:rgba(var(--ion-color-base-rgb), 0.8)}:host(.tab-bar-translucent) ::slotted(ion-tab-button.ion-focused){background:rgba(var(--ion-background-color-rgb, 255, 255, 255), 0.6)}}";
  9. const IonTabBarIosStyle0 = tabBarIosCss;
  10. const tabBarMdCss = ":host{display:-ms-flexbox;display:flex;-ms-flex-align:center;align-items:center;-ms-flex-pack:center;justify-content:center;width:auto;padding-right:var(--ion-safe-area-right);padding-bottom:var(--ion-safe-area-bottom, 0);padding-left:var(--ion-safe-area-left);border-top:var(--border);background:var(--background);color:var(--color);text-align:center;contain:strict;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;z-index:10;-webkit-box-sizing:content-box !important;box-sizing:content-box !important}:host(.ion-color) ::slotted(ion-tab-button){--background-focused:var(--ion-color-shade);--color-selected:var(--ion-color-contrast)}:host(.ion-color) ::slotted(.tab-selected){color:var(--ion-color-contrast)}:host(.ion-color),:host(.ion-color) ::slotted(ion-tab-button){color:rgba(var(--ion-color-contrast-rgb), 0.7)}:host(.ion-color),:host(.ion-color) ::slotted(ion-tab-button){background:var(--ion-color-base)}:host(.ion-color) ::slotted(ion-tab-button.ion-focused),:host(.tab-bar-translucent) ::slotted(ion-tab-button.ion-focused){background:var(--background-focused)}:host(.tab-bar-translucent) ::slotted(ion-tab-button){background:transparent}:host([slot=top]){padding-top:var(--ion-safe-area-top, 0);padding-bottom:0;border-top:0;border-bottom:var(--border)}:host(.tab-bar-hidden){display:none !important}:host{--background:var(--ion-tab-bar-background, var(--ion-background-color, #fff));--background-focused:var(--ion-tab-bar-background-focused, #e0e0e0);--border:1px solid var(--ion-tab-bar-border-color, var(--ion-border-color, var(--ion-color-step-150, var(--ion-background-color-step-150, rgba(0, 0, 0, 0.07)))));--color:var(--ion-tab-bar-color, var(--ion-color-step-650, var(--ion-text-color-step-350, #595959)));--color-selected:var(--ion-tab-bar-color-selected, var(--ion-color-primary, #0054e9));height:56px}";
  11. const IonTabBarMdStyle0 = tabBarMdCss;
  12. const TabBar = /*@__PURE__*/ proxyCustomElement(class TabBar extends HTMLElement {
  13. constructor() {
  14. super();
  15. this.__registerHost();
  16. this.__attachShadow();
  17. this.ionTabBarChanged = createEvent(this, "ionTabBarChanged", 7);
  18. this.ionTabBarLoaded = createEvent(this, "ionTabBarLoaded", 7);
  19. this.keyboardCtrl = null;
  20. this.keyboardVisible = false;
  21. this.color = undefined;
  22. this.selectedTab = undefined;
  23. this.translucent = false;
  24. }
  25. selectedTabChanged() {
  26. if (this.selectedTab !== undefined) {
  27. this.ionTabBarChanged.emit({
  28. tab: this.selectedTab,
  29. });
  30. }
  31. }
  32. componentWillLoad() {
  33. this.selectedTabChanged();
  34. }
  35. async connectedCallback() {
  36. this.keyboardCtrl = await createKeyboardController(async (keyboardOpen, waitForResize) => {
  37. /**
  38. * If the keyboard is hiding, then we need to wait
  39. * for the webview to resize. Otherwise, the tab bar
  40. * will flicker before the webview resizes.
  41. */
  42. if (keyboardOpen === false && waitForResize !== undefined) {
  43. await waitForResize;
  44. }
  45. this.keyboardVisible = keyboardOpen; // trigger re-render by updating state
  46. });
  47. }
  48. disconnectedCallback() {
  49. if (this.keyboardCtrl) {
  50. this.keyboardCtrl.destroy();
  51. }
  52. }
  53. componentDidLoad() {
  54. this.ionTabBarLoaded.emit();
  55. }
  56. render() {
  57. const { color, translucent, keyboardVisible } = this;
  58. const mode = getIonMode(this);
  59. const shouldHide = keyboardVisible && this.el.getAttribute('slot') !== 'top';
  60. return (h(Host, { key: '62303a7f9d8c98ffab51a5900c144c5117b9c543', role: "tablist", "aria-hidden": shouldHide ? 'true' : null, class: createColorClasses(color, {
  61. [mode]: true,
  62. 'tab-bar-translucent': translucent,
  63. 'tab-bar-hidden': shouldHide,
  64. }) }, h("slot", { key: '5771a9828f748c2bd6b5e26758b9723c6b3de5ff' })));
  65. }
  66. get el() { return this; }
  67. static get watchers() { return {
  68. "selectedTab": ["selectedTabChanged"]
  69. }; }
  70. static get style() { return {
  71. ios: IonTabBarIosStyle0,
  72. md: IonTabBarMdStyle0
  73. }; }
  74. }, [33, "ion-tab-bar", {
  75. "color": [513],
  76. "selectedTab": [1, "selected-tab"],
  77. "translucent": [4],
  78. "keyboardVisible": [32]
  79. }, undefined, {
  80. "selectedTab": ["selectedTabChanged"]
  81. }]);
  82. function defineCustomElement$1() {
  83. if (typeof customElements === "undefined") {
  84. return;
  85. }
  86. const components = ["ion-tab-bar"];
  87. components.forEach(tagName => { switch (tagName) {
  88. case "ion-tab-bar":
  89. if (!customElements.get(tagName)) {
  90. customElements.define(tagName, TabBar);
  91. }
  92. break;
  93. } });
  94. }
  95. const IonTabBar = TabBar;
  96. const defineCustomElement = defineCustomElement$1;
  97. export { IonTabBar, defineCustomElement };