calcite-action-bar.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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 { proxyCustomElement, HTMLElement, createEvent, h, Host } from '@stencil/core/internal/client';
  7. import { t as toggleChildActionText, E as ExpandToggle, o as overflowActionsDebounceInMs, q as queryActions, a as overflowActions, g as getOverflowCount } from './ExpandToggle.js';
  8. import { f as focusElement, b as getSlotted } from './dom.js';
  9. import { c as createObserver } from './observers.js';
  10. import { c as connectConditionalSlotComponent, d as disconnectConditionalSlotComponent } from './conditionalSlot.js';
  11. import { d as defineCustomElement$7 } from './action.js';
  12. import { d as defineCustomElement$6 } from './action-group.js';
  13. import { d as defineCustomElement$5 } from './action-menu.js';
  14. import { d as defineCustomElement$4 } from './icon.js';
  15. import { d as defineCustomElement$3 } from './loader.js';
  16. import { d as defineCustomElement$2 } from './popover.js';
  17. import { d as debounce } from './debounce.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 = "@-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}";
  30. const ActionBar = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
  31. constructor() {
  32. super();
  33. this.__registerHost();
  34. this.__attachShadow();
  35. this.calciteActionBarToggle = createEvent(this, "calciteActionBarToggle", 7);
  36. // --------------------------------------------------------------------------
  37. //
  38. // Properties
  39. //
  40. // --------------------------------------------------------------------------
  41. /**
  42. * When set to true, the expand-toggling behavior will be disabled.
  43. */
  44. this.expandDisabled = false;
  45. /**
  46. * Indicates whether widget is expanded.
  47. */
  48. this.expanded = false;
  49. /**
  50. * Disables automatically overflowing actions 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 { height } = entry.contentRect;
  79. this.resize(height);
  80. };
  81. this.resize = debounce((height) => {
  82. var _a;
  83. const { el, expanded, expandDisabled } = this;
  84. if (!height) {
  85. return;
  86. }
  87. const actions = queryActions(el);
  88. const actionCount = expandDisabled ? actions.length : actions.length + 1;
  89. const actionGroups = Array.from(el.querySelectorAll("calcite-action-group"));
  90. const groupCount = getSlotted(el, SLOTS.bottomActions) || !expandDisabled
  91. ? actionGroups.length + 1
  92. : actionGroups.length;
  93. const overflowCount = getOverflowCount({
  94. actionCount,
  95. actionHeight: (_a = actions[0]) === null || _a === void 0 ? void 0 : _a.clientHeight,
  96. height,
  97. groupCount
  98. });
  99. overflowActions({
  100. actionGroups,
  101. expanded,
  102. overflowCount
  103. });
  104. }, overflowActionsDebounceInMs);
  105. this.conditionallyOverflowActions = () => {
  106. if (!this.overflowActionsDisabled) {
  107. this.overflowActions();
  108. }
  109. };
  110. this.toggleExpand = () => {
  111. this.expanded = !this.expanded;
  112. this.calciteActionBarToggle.emit();
  113. };
  114. this.setExpandToggleRef = (el) => {
  115. this.expandToggleEl = el;
  116. };
  117. }
  118. expandHandler() {
  119. this.conditionallyOverflowActions();
  120. }
  121. expandedHandler(expanded) {
  122. toggleChildActionText({ parent: this.el, expanded });
  123. }
  124. overflowDisabledHandler(overflowActionsDisabled) {
  125. overflowActionsDisabled
  126. ? this.resizeObserver.disconnect()
  127. : this.resizeObserver.observe(this.el);
  128. }
  129. // --------------------------------------------------------------------------
  130. //
  131. // Lifecycle
  132. //
  133. // --------------------------------------------------------------------------
  134. componentDidLoad() {
  135. this.conditionallyOverflowActions();
  136. }
  137. connectedCallback() {
  138. var _a, _b;
  139. const { el, expanded } = this;
  140. toggleChildActionText({ parent: el, expanded });
  141. (_a = this.mutationObserver) === null || _a === void 0 ? void 0 : _a.observe(el, { childList: true, subtree: true });
  142. if (!this.overflowActionsDisabled) {
  143. (_b = this.resizeObserver) === null || _b === void 0 ? void 0 : _b.observe(el);
  144. }
  145. this.conditionallyOverflowActions();
  146. connectConditionalSlotComponent(this);
  147. }
  148. disconnectedCallback() {
  149. var _a, _b;
  150. (_a = this.mutationObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
  151. (_b = this.resizeObserver) === null || _b === void 0 ? void 0 : _b.disconnect();
  152. disconnectConditionalSlotComponent(this);
  153. }
  154. // --------------------------------------------------------------------------
  155. //
  156. // Methods
  157. //
  158. // --------------------------------------------------------------------------
  159. /**
  160. * Overflows actions that won't fit into menus.
  161. * @internal
  162. */
  163. async overflowActions() {
  164. this.resize(this.el.clientHeight);
  165. }
  166. /** Sets focus on the component. */
  167. async setFocus(focusId) {
  168. if (focusId === "expand-toggle") {
  169. await focusElement(this.expandToggleEl);
  170. return;
  171. }
  172. this.el.focus();
  173. }
  174. // --------------------------------------------------------------------------
  175. //
  176. // Render Methods
  177. //
  178. // --------------------------------------------------------------------------
  179. renderBottomActionGroup() {
  180. const { expanded, expandDisabled, intlExpand, intlCollapse, el, position, toggleExpand, scale } = this;
  181. const tooltip = getSlotted(el, SLOTS.expandTooltip);
  182. const expandLabel = intlExpand || TEXT.expand;
  183. const collapseLabel = intlCollapse || TEXT.collapse;
  184. 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;
  185. return getSlotted(el, SLOTS.bottomActions) || expandToggleNode ? (h("calcite-action-group", { class: CSS.actionGroupBottom, scale: scale }, h("slot", { name: SLOTS.bottomActions }), h("slot", { name: SLOTS.expandTooltip }), expandToggleNode)) : null;
  186. }
  187. render() {
  188. return (h(Host, { onCalciteActionMenuOpenChange: this.actionMenuOpenChangeHandler }, h("slot", null), this.renderBottomActionGroup()));
  189. }
  190. get el() { return this; }
  191. static get watchers() { return {
  192. "expandDisabled": ["expandHandler"],
  193. "expanded": ["expandedHandler"],
  194. "overflowActionsDisabled": ["overflowDisabledHandler"]
  195. }; }
  196. static get style() { return actionBarCss; }
  197. }, [1, "calcite-action-bar", {
  198. "expandDisabled": [516, "expand-disabled"],
  199. "expanded": [1540],
  200. "intlExpand": [1, "intl-expand"],
  201. "intlCollapse": [1, "intl-collapse"],
  202. "overflowActionsDisabled": [4, "overflow-actions-disabled"],
  203. "position": [513],
  204. "scale": [513],
  205. "overflowActions": [64],
  206. "setFocus": [64]
  207. }]);
  208. function defineCustomElement$1() {
  209. if (typeof customElements === "undefined") {
  210. return;
  211. }
  212. const components = ["calcite-action-bar", "calcite-action", "calcite-action-group", "calcite-action-menu", "calcite-icon", "calcite-loader", "calcite-popover"];
  213. components.forEach(tagName => { switch (tagName) {
  214. case "calcite-action-bar":
  215. if (!customElements.get(tagName)) {
  216. customElements.define(tagName, ActionBar);
  217. }
  218. break;
  219. case "calcite-action":
  220. if (!customElements.get(tagName)) {
  221. defineCustomElement$7();
  222. }
  223. break;
  224. case "calcite-action-group":
  225. if (!customElements.get(tagName)) {
  226. defineCustomElement$6();
  227. }
  228. break;
  229. case "calcite-action-menu":
  230. if (!customElements.get(tagName)) {
  231. defineCustomElement$5();
  232. }
  233. break;
  234. case "calcite-icon":
  235. if (!customElements.get(tagName)) {
  236. defineCustomElement$4();
  237. }
  238. break;
  239. case "calcite-loader":
  240. if (!customElements.get(tagName)) {
  241. defineCustomElement$3();
  242. }
  243. break;
  244. case "calcite-popover":
  245. if (!customElements.get(tagName)) {
  246. defineCustomElement$2();
  247. }
  248. break;
  249. } });
  250. }
  251. defineCustomElement$1();
  252. const CalciteActionBar = ActionBar;
  253. const defineCustomElement = defineCustomElement$1;
  254. export { CalciteActionBar, defineCustomElement };