popover-manager.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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.82
  5. */
  6. import { Component, h, Prop, Element, Watch } from "@stencil/core";
  7. import { createObserver } from "../../utils/observers";
  8. /**
  9. * @slot - A slot for adding elements that reference a 'calcite-popover' by the 'selector' property.
  10. * @deprecated No longer required for popover usage.
  11. */
  12. export class PopoverManager {
  13. constructor() {
  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. * @default `[data-calcite-popover-reference]`
  23. */
  24. this.selector = "[data-calcite-popover-reference]";
  25. /**
  26. * Automatically closes any currently open popovers when clicking outside of a popover.
  27. */
  28. this.autoClose = false;
  29. }
  30. autoCloseHandler() {
  31. this.setAutoClose();
  32. }
  33. // --------------------------------------------------------------------------
  34. //
  35. // Lifecycle
  36. //
  37. // --------------------------------------------------------------------------
  38. connectedCallback() {
  39. var _a;
  40. this.setAutoClose();
  41. (_a = this.mutationObserver) === null || _a === void 0 ? void 0 : _a.observe(this.el, { childList: true, subtree: true });
  42. }
  43. disconnectedCallback() {
  44. var _a;
  45. (_a = this.mutationObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
  46. }
  47. // --------------------------------------------------------------------------
  48. //
  49. // Render Methods
  50. //
  51. // --------------------------------------------------------------------------
  52. render() {
  53. return h("slot", null);
  54. }
  55. // --------------------------------------------------------------------------
  56. //
  57. // Private Methods
  58. //
  59. // --------------------------------------------------------------------------
  60. setAutoClose() {
  61. const { autoClose, el } = this;
  62. el.querySelectorAll("calcite-popover").forEach((popover) => (popover.autoClose = autoClose));
  63. }
  64. static get is() { return "calcite-popover-manager"; }
  65. static get encapsulation() { return "shadow"; }
  66. static get originalStyleUrls() { return {
  67. "$": ["popover-manager.scss"]
  68. }; }
  69. static get styleUrls() { return {
  70. "$": ["popover-manager.css"]
  71. }; }
  72. static get properties() { return {
  73. "selector": {
  74. "type": "string",
  75. "mutable": false,
  76. "complexType": {
  77. "original": "string",
  78. "resolved": "string",
  79. "references": {}
  80. },
  81. "required": false,
  82. "optional": false,
  83. "docs": {
  84. "tags": [{
  85. "name": "default",
  86. "text": "`[data-calcite-popover-reference]`"
  87. }],
  88. "text": "CSS Selector to match reference elements for popovers. Reference elements will be identified by this selector in order to open their associated popover."
  89. },
  90. "attribute": "selector",
  91. "reflect": false,
  92. "defaultValue": "\"[data-calcite-popover-reference]\""
  93. },
  94. "autoClose": {
  95. "type": "boolean",
  96. "mutable": false,
  97. "complexType": {
  98. "original": "boolean",
  99. "resolved": "boolean",
  100. "references": {}
  101. },
  102. "required": false,
  103. "optional": false,
  104. "docs": {
  105. "tags": [],
  106. "text": "Automatically closes any currently open popovers when clicking outside of a popover."
  107. },
  108. "attribute": "auto-close",
  109. "reflect": true,
  110. "defaultValue": "false"
  111. }
  112. }; }
  113. static get elementRef() { return "el"; }
  114. static get watchers() { return [{
  115. "propName": "autoClose",
  116. "methodName": "autoCloseHandler"
  117. }]; }
  118. }