ion-fab.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*!
  2. * (C) Ionic http://ionicframework.com - MIT License
  3. */
  4. import { proxyCustomElement, HTMLElement, h, Host } from '@stencil/core/internal/client';
  5. import { b as getIonMode } from './ionic-global.js';
  6. const fabCss = ":host{position:absolute;width:-webkit-fit-content;width:-moz-fit-content;width:fit-content;height:-webkit-fit-content;height:-moz-fit-content;height:fit-content;z-index:999}:host(.fab-horizontal-center){left:0px;right:0px;-webkit-margin-start:auto;margin-inline-start:auto;-webkit-margin-end:auto;margin-inline-end:auto}:host(.fab-horizontal-start){left:calc(10px + var(--ion-safe-area-left, 0px));}:host-context([dir=rtl]):host(.fab-horizontal-start),:host-context([dir=rtl]).fab-horizontal-start{right:calc(10px + var(--ion-safe-area-right, 0px));left:unset}@supports selector(:dir(rtl)){:host(.fab-horizontal-start:dir(rtl)){right:calc(10px + var(--ion-safe-area-right, 0px));left:unset}}:host(.fab-horizontal-end){right:calc(10px + var(--ion-safe-area-right, 0px));}:host-context([dir=rtl]):host(.fab-horizontal-end),:host-context([dir=rtl]).fab-horizontal-end{left:calc(10px + var(--ion-safe-area-left, 0px));right:unset}@supports selector(:dir(rtl)){:host(.fab-horizontal-end:dir(rtl)){left:calc(10px + var(--ion-safe-area-left, 0px));right:unset}}:host(.fab-vertical-top){top:10px}:host(.fab-vertical-top.fab-edge){top:0}:host(.fab-vertical-top.fab-edge) ::slotted(ion-fab-button){margin-top:-50%}:host(.fab-vertical-top.fab-edge) ::slotted(ion-fab-button.fab-button-small){margin-top:calc((-100% + 16px) / 2)}:host(.fab-vertical-top.fab-edge) ::slotted(ion-fab-list.fab-list-side-start),:host(.fab-vertical-top.fab-edge) ::slotted(ion-fab-list.fab-list-side-end){margin-top:-50%}:host(.fab-vertical-top.fab-edge) ::slotted(ion-fab-list.fab-list-side-top),:host(.fab-vertical-top.fab-edge) ::slotted(ion-fab-list.fab-list-side-bottom){margin-top:calc(50% + 10px)}:host(.fab-vertical-bottom){bottom:10px}:host(.fab-vertical-bottom.fab-edge){bottom:0}:host(.fab-vertical-bottom.fab-edge) ::slotted(ion-fab-button){margin-bottom:-50%}:host(.fab-vertical-bottom.fab-edge) ::slotted(ion-fab-button.fab-button-small){margin-bottom:calc((-100% + 16px) / 2)}:host(.fab-vertical-bottom.fab-edge) ::slotted(ion-fab-list.fab-list-side-start),:host(.fab-vertical-bottom.fab-edge) ::slotted(ion-fab-list.fab-list-side-end){margin-bottom:-50%}:host(.fab-vertical-bottom.fab-edge) ::slotted(ion-fab-list.fab-list-side-top),:host(.fab-vertical-bottom.fab-edge) ::slotted(ion-fab-list.fab-list-side-bottom){margin-bottom:calc(50% + 10px)}:host(.fab-vertical-center){top:0px;bottom:0px;margin-top:auto;margin-bottom:auto}";
  7. const IonFabStyle0 = fabCss;
  8. const Fab = /*@__PURE__*/ proxyCustomElement(class Fab extends HTMLElement {
  9. constructor() {
  10. super();
  11. this.__registerHost();
  12. this.__attachShadow();
  13. this.horizontal = undefined;
  14. this.vertical = undefined;
  15. this.edge = false;
  16. this.activated = false;
  17. }
  18. activatedChanged() {
  19. const activated = this.activated;
  20. const fab = this.getFab();
  21. if (fab) {
  22. fab.activated = activated;
  23. }
  24. Array.from(this.el.querySelectorAll('ion-fab-list')).forEach((list) => {
  25. list.activated = activated;
  26. });
  27. }
  28. componentDidLoad() {
  29. if (this.activated) {
  30. this.activatedChanged();
  31. }
  32. }
  33. /**
  34. * Close an active FAB list container.
  35. */
  36. async close() {
  37. this.activated = false;
  38. }
  39. getFab() {
  40. return this.el.querySelector('ion-fab-button');
  41. }
  42. /**
  43. * Opens/Closes the FAB list container.
  44. * @internal
  45. */
  46. async toggle() {
  47. const hasList = !!this.el.querySelector('ion-fab-list');
  48. if (hasList) {
  49. this.activated = !this.activated;
  50. }
  51. }
  52. render() {
  53. const { horizontal, vertical, edge } = this;
  54. const mode = getIonMode(this);
  55. return (h(Host, { key: '8a310806d0e748d7ebb0ed3d9a2652038e0f2960', class: {
  56. [mode]: true,
  57. [`fab-horizontal-${horizontal}`]: horizontal !== undefined,
  58. [`fab-vertical-${vertical}`]: vertical !== undefined,
  59. 'fab-edge': edge,
  60. } }, h("slot", { key: '9394ef6d6e5b0410fa6ba212171f687fb178ce2d' })));
  61. }
  62. get el() { return this; }
  63. static get watchers() { return {
  64. "activated": ["activatedChanged"]
  65. }; }
  66. static get style() { return IonFabStyle0; }
  67. }, [1, "ion-fab", {
  68. "horizontal": [1],
  69. "vertical": [1],
  70. "edge": [4],
  71. "activated": [1028],
  72. "close": [64],
  73. "toggle": [64]
  74. }, undefined, {
  75. "activated": ["activatedChanged"]
  76. }]);
  77. function defineCustomElement$1() {
  78. if (typeof customElements === "undefined") {
  79. return;
  80. }
  81. const components = ["ion-fab"];
  82. components.forEach(tagName => { switch (tagName) {
  83. case "ion-fab":
  84. if (!customElements.get(tagName)) {
  85. customElements.define(tagName, Fab);
  86. }
  87. break;
  88. } });
  89. }
  90. const IonFab = Fab;
  91. const defineCustomElement = defineCustomElement$1;
  92. export { IonFab, defineCustomElement };