calcite-action-pad.js 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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 { proxyCustomElement, HTMLElement, createEvent, h, Host } from '@stencil/core/internal/client/index.js';
  7. import { t as toggleChildActionText, E as ExpandToggle } from './ExpandToggle.js';
  8. import { f as focusElement, b as getSlotted } from './dom.js';
  9. import { c as connectConditionalSlotComponent, d as disconnectConditionalSlotComponent } from './conditionalSlot.js';
  10. import { d as defineCustomElement$7 } from './action.js';
  11. import { d as defineCustomElement$6 } from './action-group.js';
  12. import { d as defineCustomElement$5 } from './action-menu.js';
  13. import { d as defineCustomElement$4 } from './icon.js';
  14. import { d as defineCustomElement$3 } from './loader.js';
  15. import { d as defineCustomElement$2 } from './popover.js';
  16. const CSS = {
  17. actionGroupBottom: "action-group--bottom",
  18. container: "container"
  19. };
  20. const TEXT = {
  21. expand: "Expand",
  22. collapse: "Collapse"
  23. };
  24. const SLOTS = {
  25. expandTooltip: "expand-tooltip"
  26. };
  27. const actionPadCss = "@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{display:block}@keyframes in{0%{opacity:0}100%{opacity:1}}:host{animation:in var(--calcite-internal-animation-timing-slow) ease-in-out;border-radius:0.125rem;--calcite-action-pad-expanded-max-width:auto;background:transparent}:host([expanded][layout=vertical]) .container{max-inline-size:var(--calcite-action-pad-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);padding-block:0px}.container{display:inline-flex;flex-direction:column;overflow-y:auto;border-radius:0.25rem;background-color:var(--calcite-ui-background);--tw-shadow:0 6px 20px -4px rgba(0, 0, 0, 0.1), 0 4px 12px -2px rgba(0, 0, 0, 0.08);--tw-shadow-colored:0 6px 20px -4px var(--tw-shadow-color), 0 4px 12px -2px var(--tw-shadow-color);box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow)}.action-group--bottom{flex-grow:1;justify-content:flex-end;padding-block-end:0px}:host([layout=horizontal]) .container{flex-direction:row}:host([layout=horizontal]) .container .action-group--bottom{padding:0px}:host([layout=horizontal]) .container ::slotted(calcite-action-group){border-width:0px;padding:0px;border-inline-end-width:1px}::slotted(calcite-action-group:last-child){border-block-end-width:0px}";
  28. const ActionPad = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
  29. constructor() {
  30. super();
  31. this.__registerHost();
  32. this.__attachShadow();
  33. this.calciteActionPadToggle = createEvent(this, "calciteActionPadToggle", 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. * Indicates the layout of the component.
  49. */
  50. this.layout = "vertical";
  51. // --------------------------------------------------------------------------
  52. //
  53. // Private Methods
  54. //
  55. // --------------------------------------------------------------------------
  56. this.actionMenuOpenChangeHandler = (event) => {
  57. if (event.detail) {
  58. const composedPath = event.composedPath();
  59. Array.from(this.el.querySelectorAll("calcite-action-group")).forEach((group) => {
  60. if (!composedPath.includes(group)) {
  61. group.menuOpen = false;
  62. }
  63. });
  64. }
  65. };
  66. this.toggleExpand = () => {
  67. this.expanded = !this.expanded;
  68. this.calciteActionPadToggle.emit();
  69. };
  70. this.setExpandToggleRef = (el) => {
  71. this.expandToggleEl = el;
  72. };
  73. }
  74. expandedHandler(expanded) {
  75. toggleChildActionText({ parent: this.el, expanded });
  76. }
  77. // --------------------------------------------------------------------------
  78. //
  79. // Lifecycle
  80. //
  81. // --------------------------------------------------------------------------
  82. connectedCallback() {
  83. connectConditionalSlotComponent(this);
  84. }
  85. disconnectedCallback() {
  86. disconnectConditionalSlotComponent(this);
  87. }
  88. componentWillLoad() {
  89. const { el, expanded } = this;
  90. toggleChildActionText({ parent: el, expanded });
  91. }
  92. // --------------------------------------------------------------------------
  93. //
  94. // Methods
  95. //
  96. // --------------------------------------------------------------------------
  97. /**
  98. * Sets focus on the component.
  99. *
  100. * @param focusId
  101. */
  102. async setFocus(focusId) {
  103. var _a;
  104. if (focusId === "expand-toggle") {
  105. await focusElement(this.expandToggleEl);
  106. return;
  107. }
  108. (_a = this.el) === null || _a === void 0 ? void 0 : _a.focus();
  109. }
  110. // --------------------------------------------------------------------------
  111. //
  112. // Component Methods
  113. //
  114. // --------------------------------------------------------------------------
  115. renderBottomActionGroup() {
  116. const { expanded, expandDisabled, intlExpand, intlCollapse, el, position, toggleExpand, scale, layout } = this;
  117. const tooltip = getSlotted(el, SLOTS.expandTooltip);
  118. const expandLabel = intlExpand || TEXT.expand;
  119. const collapseLabel = intlCollapse || TEXT.collapse;
  120. 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;
  121. return expandToggleNode ? (h("calcite-action-group", { class: CSS.actionGroupBottom, layout: layout, scale: scale }, h("slot", { name: SLOTS.expandTooltip }), expandToggleNode)) : null;
  122. }
  123. render() {
  124. return (h(Host, { onCalciteActionMenuOpenChange: this.actionMenuOpenChangeHandler }, h("div", { class: CSS.container }, h("slot", null), this.renderBottomActionGroup())));
  125. }
  126. get el() { return this; }
  127. static get watchers() { return {
  128. "expanded": ["expandedHandler"]
  129. }; }
  130. static get style() { return actionPadCss; }
  131. }, [1, "calcite-action-pad", {
  132. "expandDisabled": [516, "expand-disabled"],
  133. "expanded": [1540],
  134. "layout": [513],
  135. "intlExpand": [1, "intl-expand"],
  136. "intlCollapse": [1, "intl-collapse"],
  137. "position": [513],
  138. "scale": [513],
  139. "setFocus": [64]
  140. }]);
  141. function defineCustomElement$1() {
  142. if (typeof customElements === "undefined") {
  143. return;
  144. }
  145. const components = ["calcite-action-pad", "calcite-action", "calcite-action-group", "calcite-action-menu", "calcite-icon", "calcite-loader", "calcite-popover"];
  146. components.forEach(tagName => { switch (tagName) {
  147. case "calcite-action-pad":
  148. if (!customElements.get(tagName)) {
  149. customElements.define(tagName, ActionPad);
  150. }
  151. break;
  152. case "calcite-action":
  153. if (!customElements.get(tagName)) {
  154. defineCustomElement$7();
  155. }
  156. break;
  157. case "calcite-action-group":
  158. if (!customElements.get(tagName)) {
  159. defineCustomElement$6();
  160. }
  161. break;
  162. case "calcite-action-menu":
  163. if (!customElements.get(tagName)) {
  164. defineCustomElement$5();
  165. }
  166. break;
  167. case "calcite-icon":
  168. if (!customElements.get(tagName)) {
  169. defineCustomElement$4();
  170. }
  171. break;
  172. case "calcite-loader":
  173. if (!customElements.get(tagName)) {
  174. defineCustomElement$3();
  175. }
  176. break;
  177. case "calcite-popover":
  178. if (!customElements.get(tagName)) {
  179. defineCustomElement$2();
  180. }
  181. break;
  182. } });
  183. }
  184. defineCustomElement$1();
  185. const CalciteActionPad = ActionPad;
  186. const defineCustomElement = defineCustomElement$1;
  187. export { CalciteActionPad, defineCustomElement };