calcite-action-bar.cjs.entry.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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. 'use strict';
  7. Object.defineProperty(exports, '__esModule', { value: true });
  8. const index = require('./index-a0010f96.js');
  9. const ExpandToggle = require('./ExpandToggle-e41acdfc.js');
  10. const dom = require('./dom-2ec8c9ed.js');
  11. const observers = require('./observers-5706326b.js');
  12. const conditionalSlot = require('./conditionalSlot-ef852d9d.js');
  13. const debounce = require('./debounce-2c8b61fb.js');
  14. require('./resources-bd2202e9.js');
  15. require('./resources-199140b3.js');
  16. require('./resources-b5a5f8a7.js');
  17. require('./guid-f4f03a7a.js');
  18. const CSS = {
  19. actionGroupBottom: "action-group--bottom"
  20. };
  21. const SLOTS = {
  22. bottomActions: "bottom-actions",
  23. expandTooltip: "expand-tooltip"
  24. };
  25. const TEXT = {
  26. expand: "Expand",
  27. collapse: "Collapse"
  28. };
  29. const actionBarCss = "@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}}:host{box-sizing:border-box;background-color:var(--calcite-ui-foreground-1);color:var(--calcite-ui-text-2);font-size:var(--calcite-font-size--1)}:host *{box-sizing:border-box}:root{--calcite-floating-ui-transition:var(--calcite-animation-timing)}:host([hidden]){display:none}:host{pointer-events:auto;display:inline-flex;align-self:stretch;background:transparent;--calcite-action-bar-expanded-max-width:auto}:host([layout=vertical]){flex-direction:column}:host([layout=horizontal]){flex-direction:row}:host([layout=vertical][overflow-actions-disabled]){overflow-y:auto}:host([layout=horizontal][overflow-actions-disabled]){overflow-x:auto}:host([layout=vertical][expanded]){max-inline-size:var(--calcite-action-bar-expanded-max-width)}::slotted(calcite-action-group){border-width:0px;border-block-end-width:1px;border-style:solid;border-color:var(--calcite-ui-border-3)}:host([layout=horizontal]) ::slotted(calcite-action-group){border-width:0px;border-inline-end-width:1px;border-style:solid}::slotted(calcite-action-group:last-child){border-block-end-width:0px;border-inline-end-width:0px}.action-group--bottom{flex-grow:1;justify-content:flex-end;padding-block-end:0px;padding-inline-end:0px}";
  30. const ActionBar = class {
  31. constructor(hostRef) {
  32. index.registerInstance(this, hostRef);
  33. this.calciteActionBarToggle = index.createEvent(this, "calciteActionBarToggle", 6);
  34. // --------------------------------------------------------------------------
  35. //
  36. // Properties
  37. //
  38. // --------------------------------------------------------------------------
  39. /**
  40. * When `true`, the expand-toggling behavior is disabled.
  41. */
  42. this.expandDisabled = false;
  43. /**
  44. * When `true`, the component is expanded.
  45. */
  46. this.expanded = false;
  47. /**
  48. * The layout direction of the actions.
  49. */
  50. this.layout = "vertical";
  51. /**
  52. * Disables automatically overflowing `calcite-action`s that won't fit into menus.
  53. */
  54. this.overflowActionsDisabled = false;
  55. this.mutationObserver = observers.createObserver("mutation", () => {
  56. const { el, expanded } = this;
  57. ExpandToggle.toggleChildActionText({ parent: el, expanded });
  58. this.conditionallyOverflowActions();
  59. });
  60. this.resizeObserver = observers.createObserver("resize", (entries) => this.resizeHandlerEntries(entries));
  61. // --------------------------------------------------------------------------
  62. //
  63. // Private Methods
  64. //
  65. // --------------------------------------------------------------------------
  66. this.actionMenuOpenChangeHandler = (event) => {
  67. if (event.detail) {
  68. const composedPath = event.composedPath();
  69. Array.from(this.el.querySelectorAll("calcite-action-group")).forEach((group) => {
  70. if (!composedPath.includes(group)) {
  71. group.menuOpen = false;
  72. }
  73. });
  74. }
  75. };
  76. this.resizeHandlerEntries = (entries) => {
  77. entries.forEach(this.resizeHandler);
  78. };
  79. this.resizeHandler = (entry) => {
  80. const { width, height } = entry.contentRect;
  81. this.resize({ width, height });
  82. };
  83. this.resize = debounce.debounce(({ width, height }) => {
  84. const { el, expanded, expandDisabled, layout } = this;
  85. if ((layout === "vertical" && !height) || (layout === "horizontal" && !width)) {
  86. return;
  87. }
  88. const actions = ExpandToggle.queryActions(el);
  89. const actionCount = expandDisabled ? actions.length : actions.length + 1;
  90. const actionGroups = Array.from(el.querySelectorAll("calcite-action-group"));
  91. const groupCount = dom.getSlotted(el, SLOTS.bottomActions) || !expandDisabled
  92. ? actionGroups.length + 1
  93. : actionGroups.length;
  94. const { actionHeight, actionWidth } = ExpandToggle.geActionDimensions(actions);
  95. const overflowCount = ExpandToggle.getOverflowCount({
  96. layout,
  97. actionCount,
  98. actionHeight,
  99. actionWidth,
  100. height,
  101. width,
  102. groupCount
  103. });
  104. ExpandToggle.overflowActions({
  105. actionGroups,
  106. expanded,
  107. overflowCount
  108. });
  109. }, ExpandToggle.overflowActionsDebounceInMs);
  110. this.conditionallyOverflowActions = () => {
  111. if (!this.overflowActionsDisabled) {
  112. this.overflowActions();
  113. }
  114. };
  115. this.toggleExpand = () => {
  116. this.expanded = !this.expanded;
  117. this.calciteActionBarToggle.emit();
  118. };
  119. this.setExpandToggleRef = (el) => {
  120. this.expandToggleEl = el;
  121. };
  122. }
  123. expandHandler() {
  124. this.conditionallyOverflowActions();
  125. }
  126. expandedHandler(expanded) {
  127. ExpandToggle.toggleChildActionText({ parent: this.el, expanded });
  128. this.conditionallyOverflowActions();
  129. }
  130. overflowDisabledHandler(overflowActionsDisabled) {
  131. overflowActionsDisabled
  132. ? this.resizeObserver.disconnect()
  133. : this.resizeObserver.observe(this.el);
  134. }
  135. // --------------------------------------------------------------------------
  136. //
  137. // Lifecycle
  138. //
  139. // --------------------------------------------------------------------------
  140. componentDidLoad() {
  141. this.conditionallyOverflowActions();
  142. }
  143. connectedCallback() {
  144. var _a, _b;
  145. const { el, expanded } = this;
  146. ExpandToggle.toggleChildActionText({ parent: el, expanded });
  147. (_a = this.mutationObserver) === null || _a === void 0 ? void 0 : _a.observe(el, { childList: true, subtree: true });
  148. if (!this.overflowActionsDisabled) {
  149. (_b = this.resizeObserver) === null || _b === void 0 ? void 0 : _b.observe(el);
  150. }
  151. this.conditionallyOverflowActions();
  152. conditionalSlot.connectConditionalSlotComponent(this);
  153. }
  154. disconnectedCallback() {
  155. var _a, _b;
  156. (_a = this.mutationObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
  157. (_b = this.resizeObserver) === null || _b === void 0 ? void 0 : _b.disconnect();
  158. conditionalSlot.disconnectConditionalSlotComponent(this);
  159. }
  160. // --------------------------------------------------------------------------
  161. //
  162. // Methods
  163. //
  164. // --------------------------------------------------------------------------
  165. /**
  166. * Overflows actions that won't fit into menus.
  167. *
  168. * @internal
  169. */
  170. async overflowActions() {
  171. this.resize({ width: this.el.clientWidth, height: this.el.clientHeight });
  172. }
  173. /**
  174. * Sets focus on the component.
  175. *
  176. * @param focusId
  177. */
  178. async setFocus(focusId) {
  179. var _a;
  180. if (focusId === "expand-toggle") {
  181. await dom.focusElement(this.expandToggleEl);
  182. return;
  183. }
  184. (_a = this.el) === null || _a === void 0 ? void 0 : _a.focus();
  185. }
  186. // --------------------------------------------------------------------------
  187. //
  188. // Render Methods
  189. //
  190. // --------------------------------------------------------------------------
  191. renderBottomActionGroup() {
  192. const { expanded, expandDisabled, intlExpand, intlCollapse, el, position, toggleExpand, scale, layout } = this;
  193. const tooltip = dom.getSlotted(el, SLOTS.expandTooltip);
  194. const expandLabel = intlExpand || TEXT.expand;
  195. const collapseLabel = intlCollapse || TEXT.collapse;
  196. const expandToggleNode = !expandDisabled ? (index.h(ExpandToggle.ExpandToggle, { el: el, expanded: expanded, intlCollapse: collapseLabel, intlExpand: expandLabel, position: position, ref: this.setExpandToggleRef, scale: scale, toggle: toggleExpand, tooltip: tooltip })) : null;
  197. return dom.getSlotted(el, SLOTS.bottomActions) || expandToggleNode ? (index.h("calcite-action-group", { class: CSS.actionGroupBottom, layout: layout, scale: scale }, index.h("slot", { name: SLOTS.bottomActions }), index.h("slot", { name: SLOTS.expandTooltip }), expandToggleNode)) : null;
  198. }
  199. render() {
  200. return (index.h(index.Host, { onCalciteActionMenuOpenChange: this.actionMenuOpenChangeHandler }, index.h("slot", null), this.renderBottomActionGroup()));
  201. }
  202. get el() { return index.getElement(this); }
  203. static get watchers() { return {
  204. "expandDisabled": ["expandHandler"],
  205. "expanded": ["expandedHandler"],
  206. "overflowActionsDisabled": ["overflowDisabledHandler"]
  207. }; }
  208. };
  209. ActionBar.style = actionBarCss;
  210. exports.calcite_action_bar = ActionBar;