calcite-action-bar.entry.js 10 KB

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