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

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