calcite-popover-manager.js 4.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*!
  2. * All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  3. * See https://github.com/Esri/calcite-components/blob/master/LICENSE.md for details.
  4. * v1.0.0-beta.97
  5. */
  6. import { proxyCustomElement, HTMLElement, h } from '@stencil/core/internal/client/index.js';
  7. import { c as createObserver } from './observers.js';
  8. const popoverManagerCss = "@keyframes in{0%{opacity:0}100%{opacity:1}}@keyframes in-down{0%{opacity:0;transform:translate3D(0, -5px, 0)}100%{opacity:1;transform:translate3D(0, 0, 0)}}@keyframes in-up{0%{opacity:0;transform:translate3D(0, 5px, 0)}100%{opacity:1;transform:translate3D(0, 0, 0)}}@keyframes in-scale{0%{opacity:0;transform:scale3D(0.95, 0.95, 1)}100%{opacity:1;transform:scale3D(1, 1, 1)}}:root{--calcite-animation-timing:calc(150ms * var(--calcite-internal-duration-factor));--calcite-internal-duration-factor:var(--calcite-duration-factor, 1);--calcite-internal-animation-timing-fast:calc(100ms * var(--calcite-internal-duration-factor));--calcite-internal-animation-timing-medium:calc(200ms * var(--calcite-internal-duration-factor));--calcite-internal-animation-timing-slow:calc(300ms * var(--calcite-internal-duration-factor))}.calcite-animate{opacity:0;animation-fill-mode:both;animation-duration:var(--calcite-animation-timing)}.calcite-animate__in{animation-name:in}.calcite-animate__in-down{animation-name:in-down}.calcite-animate__in-up{animation-name:in-up}.calcite-animate__in-scale{animation-name:in-scale}@media (prefers-reduced-motion: reduce){:root{--calcite-internal-duration-factor:0.01}}:root{--calcite-floating-ui-transition:var(--calcite-animation-timing)}:host([hidden]){display:none}:host{position:relative;display:block}";
  9. const PopoverManager = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
  10. constructor() {
  11. super();
  12. this.__registerHost();
  13. this.__attachShadow();
  14. this.mutationObserver = createObserver("mutation", () => this.setAutoClose());
  15. // --------------------------------------------------------------------------
  16. //
  17. // Properties
  18. //
  19. // --------------------------------------------------------------------------
  20. /**
  21. * CSS Selector to match reference elements for popovers. Reference elements will be identified by this selector in order to open their associated popover.
  22. *
  23. * @default `[data-calcite-popover-reference]`
  24. */
  25. this.selector = "[data-calcite-popover-reference]";
  26. /**
  27. * Automatically closes any currently open popovers when clicking outside of a popover.
  28. */
  29. this.autoClose = false;
  30. }
  31. autoCloseHandler() {
  32. this.setAutoClose();
  33. }
  34. // --------------------------------------------------------------------------
  35. //
  36. // Lifecycle
  37. //
  38. // --------------------------------------------------------------------------
  39. connectedCallback() {
  40. var _a;
  41. this.setAutoClose();
  42. (_a = this.mutationObserver) === null || _a === void 0 ? void 0 : _a.observe(this.el, { childList: true, subtree: true });
  43. }
  44. disconnectedCallback() {
  45. var _a;
  46. (_a = this.mutationObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
  47. }
  48. // --------------------------------------------------------------------------
  49. //
  50. // Render Methods
  51. //
  52. // --------------------------------------------------------------------------
  53. render() {
  54. return h("slot", null);
  55. }
  56. // --------------------------------------------------------------------------
  57. //
  58. // Private Methods
  59. //
  60. // --------------------------------------------------------------------------
  61. setAutoClose() {
  62. const { autoClose, el } = this;
  63. el.querySelectorAll("calcite-popover").forEach((popover) => (popover.autoClose = autoClose));
  64. }
  65. get el() { return this; }
  66. static get watchers() { return {
  67. "autoClose": ["autoCloseHandler"]
  68. }; }
  69. static get style() { return popoverManagerCss; }
  70. }, [1, "calcite-popover-manager", {
  71. "selector": [513],
  72. "autoClose": [516, "auto-close"]
  73. }]);
  74. function defineCustomElement$1() {
  75. if (typeof customElements === "undefined") {
  76. return;
  77. }
  78. const components = ["calcite-popover-manager"];
  79. components.forEach(tagName => { switch (tagName) {
  80. case "calcite-popover-manager":
  81. if (!customElements.get(tagName)) {
  82. customElements.define(tagName, PopoverManager);
  83. }
  84. break;
  85. } });
  86. }
  87. defineCustomElement$1();
  88. const CalcitePopoverManager = PopoverManager;
  89. const defineCustomElement = defineCustomElement$1;
  90. export { CalcitePopoverManager, defineCustomElement };