calcite-action.entry.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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, f as forceUpdate } from './index-1f9b54dc.js';
  7. import { c as createObserver } from './observers-9f44e9b3.js';
  8. import { u as updateHostInteraction } from './interactive-5db230e8.js';
  9. import { t as toAriaBoolean } from './dom-8f0a9ff2.js';
  10. import './resources-9c476cb6.js';
  11. import './guid-9f15e57a.js';
  12. const CSS = {
  13. button: "button",
  14. buttonTextVisible: "button--text-visible",
  15. buttonCompact: "button--compact",
  16. iconContainer: "icon-container",
  17. slotContainer: "slot-container",
  18. slotContainerHidden: "slot-container--hidden",
  19. textContainer: "text-container",
  20. textContainerVisible: "text-container--visible"
  21. };
  22. const TEXT = {
  23. loading: "Loading"
  24. };
  25. const SLOTS = {
  26. tooltip: "tooltip"
  27. };
  28. const actionCss = "@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([disabled]){pointer-events:none;cursor:default;-webkit-user-select:none;user-select:none;opacity:var(--calcite-ui-opacity-disabled)}:host{display:flex;background-color:transparent;--calcite-action-indicator-color:var(--calcite-ui-brand)}:host([disabled]) ::slotted([calcite-hydrated][disabled]),:host([disabled]) [calcite-hydrated][disabled]{opacity:1}.button{position:relative;margin:0px;display:flex;inline-size:auto;cursor:pointer;align-items:center;justify-content:flex-start;border-style:none;background-color:var(--calcite-ui-foreground-1);fill:var(--calcite-ui-text-3);font-family:var(--calcite-sans-family);font-size:var(--calcite-font-size--2);line-height:1rem;font-weight:var(--calcite-font-weight-medium);color:var(--calcite-ui-text-3);outline-color:transparent;text-align:unset;flex:1 0 auto}.button:hover{background-color:var(--calcite-ui-foreground-2);fill:var(--calcite-ui-text-1);color:var(--calcite-ui-text-1)}.button:focus{background-color:var(--calcite-ui-foreground-2);fill:var(--calcite-ui-text-1);color:var(--calcite-ui-text-1);outline:2px solid var(--calcite-ui-brand);outline-offset:-2px}.button:active{background-color:var(--calcite-ui-foreground-3)}.button .icon-container{pointer-events:none;margin:0px;display:flex;align-items:center;justify-content:center;min-inline-size:1rem;min-block-size:1rem}.button .text-container{margin:0px;inline-size:0px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;line-height:1.5rem;opacity:0;transition-property:opacity;transition-duration:150ms;transition-timing-function:cubic-bezier(0.4, 0, 0.2, 1);transition-property:margin;transition-property:inline-size}.button .text-container--visible{inline-size:auto;flex:1 1 auto;opacity:1}:host([scale=s]) .button{padding-inline:0.5rem;padding-block:0.25rem;font-size:var(--calcite-font-size--2);line-height:1rem;font-weight:var(--calcite-font-weight-normal)}:host([scale=s]) .button--text-visible .icon-container{margin-inline-end:0.5rem}:host([scale=m]) .button{padding-inline:1rem;padding-block:0.75rem;font-size:var(--calcite-font-size--1);line-height:1rem;font-weight:var(--calcite-font-weight-normal)}:host([scale=m]) .button--text-visible .icon-container{margin-inline-end:0.75rem}:host([scale=l]) .button{padding:1.25rem;font-size:var(--calcite-font-size-0);line-height:1.25rem;font-weight:var(--calcite-font-weight-normal)}:host([scale=l]) .button--text-visible .icon-container{margin-inline-end:1rem}:host([alignment=center]) .button{justify-content:center}:host([alignment=end]) .button{justify-content:flex-end}:host([alignment=center]) .button .text-container--visible,:host([alignment=end]) .button .text-container--visible{flex:0 1 auto}:host([scale=s][compact]) .button,:host([scale=m][compact]) .button,:host([scale=l][compact]) .button{padding-inline:0px}.slot-container{display:flex}.slot-container--hidden{display:none}.button--text-visible{inline-size:100%}:host([active]) .button,:host([active]) .button:hover,:host([active]) .button:focus,:host([active][loading]) .button{background-color:var(--calcite-ui-foreground-3);fill:var(--calcite-ui-text-1);color:var(--calcite-ui-text-1)}:host([active]) .button:active{background-color:var(--calcite-ui-foreground-1)}:host([appearance=clear]) .button,:host([appearance=transparent]) .button{background-color:transparent;transition-property:box-shadow;transition-duration:150ms;transition-timing-function:cubic-bezier(0.4, 0, 0.2, 1)}:host([appearance=clear]) .button:hover,:host([appearance=clear]) .button:focus,:host([appearance=transparent]) .button:hover,:host([appearance=transparent]) .button:focus{background-color:transparent;box-shadow:0 0 0 2px var(--calcite-ui-border-1) inset}:host([active][appearance=clear]) .button,:host([active][appearance=clear]) .button:hover,:host([active][appearance=clear]) .button:focus,:host([active][appearance=transparent]) .button,:host([active][appearance=transparent]) .button:hover,:host([active][appearance=transparent]) .button:focus{background-color:var(--calcite-ui-foreground-3);fill:var(--calcite-ui-text-1);color:var(--calcite-ui-text-1)}:host([appearance=clear][loading]) .button,:host([appearance=clear][disabled]) .button,:host([appearance=transparent][loading]) .button,:host([appearance=transparent][disabled]) .button{background-color:transparent}:host([loading]) .button,:host([loading]) .button:hover,:host([loading]) .button:focus{background-color:var(--calcite-ui-foreground-1)}:host([loading]) .button .text-container,:host([loading]) .button:hover .text-container,:host([loading]) .button:focus .text-container{opacity:var(--calcite-ui-opacity-disabled)}:host([loading]) calcite-loader[inline]{color:var(--calcite-ui-text-3);margin-inline-end:0px}:host([disabled]) .button,:host([disabled]) .button:hover,:host([disabled]) .button:focus{cursor:default;background-color:var(--calcite-ui-foreground-1);opacity:var(--calcite-ui-opacity-disabled)}:host([disabled][active]) .button,:host([disabled][active]) .button:hover,:host([disabled][active]) .button:focus{background-color:var(--calcite-ui-foreground-3);opacity:var(--calcite-ui-opacity-disabled)}:host([indicator]) .button::after{content:\"\";position:absolute;block-size:0.5rem;inline-size:0.5rem;border-radius:9999px;border-width:2px;background-color:var(--calcite-action-indicator-color);border-color:var(--calcite-ui-foreground-1);inset-block-end:0.75rem;inset-inline-end:0.75rem}:host([indicator]) .button--text-visible::after{inset-block-end:auto}:host([indicator]) .button--text-visible .text-container--visible{margin-inline-end:1rem}:host([indicator]) .button:hover::after,:host([indicator]) .button:focus::after{border-color:var(--calcite-ui-foreground-1)}:host([indicator][scale=s]) .button::after{inset-block-end:0.25rem;inset-inline-end:0.25rem}:host([indicator][scale=s]) .button--text-visible::after{inset-block-end:auto;inset-inline-end:0.5rem}:host([indicator][active]) .button::after{border-color:var(--calcite-ui-foreground-3)}";
  29. const Action = class {
  30. constructor(hostRef) {
  31. registerInstance(this, hostRef);
  32. this.calciteActionClick = createEvent(this, "calciteActionClick", 6);
  33. // --------------------------------------------------------------------------
  34. //
  35. // Properties
  36. //
  37. // --------------------------------------------------------------------------
  38. /**
  39. * When `true`, the component is highlighted.
  40. */
  41. this.active = false;
  42. /** Specifies the appearance of the component. */
  43. this.appearance = "solid";
  44. /**
  45. * When `true`, the side padding of the component is reduced. Compact mode is used internally by components, e.g. `calcite-block-section`.
  46. */
  47. this.compact = false;
  48. /**
  49. * When `true`, interaction is prevented and the component is displayed with lower opacity.
  50. */
  51. this.disabled = false;
  52. /**
  53. * When `true`, indicates unread changes.
  54. */
  55. this.indicator = false;
  56. /**
  57. * Specifies the text label to display while loading.
  58. *
  59. * @default "Loading"
  60. */
  61. this.intlLoading = TEXT.loading;
  62. /**
  63. * When `true`, a busy indicator is displayed.
  64. */
  65. this.loading = false;
  66. /**
  67. * Specifies the size of the component.
  68. */
  69. this.scale = "m";
  70. /**
  71. * Indicates whether the text is displayed.
  72. */
  73. this.textEnabled = false;
  74. this.mutationObserver = createObserver("mutation", () => forceUpdate(this));
  75. // --------------------------------------------------------------------------
  76. //
  77. // Private Methods
  78. //
  79. // --------------------------------------------------------------------------
  80. this.handleTooltipSlotChange = (event) => {
  81. const tooltips = event.target
  82. .assignedElements({
  83. flatten: true
  84. })
  85. .filter((el) => el === null || el === void 0 ? void 0 : el.matches("calcite-tooltip"));
  86. const tooltip = tooltips[0];
  87. if (tooltip) {
  88. tooltip.referenceElement = this.buttonEl;
  89. }
  90. };
  91. this.calciteActionClickHandler = () => {
  92. if (!this.disabled) {
  93. this.calciteActionClick.emit();
  94. }
  95. };
  96. }
  97. // --------------------------------------------------------------------------
  98. //
  99. // Lifecycle
  100. //
  101. // --------------------------------------------------------------------------
  102. connectedCallback() {
  103. var _a;
  104. (_a = this.mutationObserver) === null || _a === void 0 ? void 0 : _a.observe(this.el, { childList: true, subtree: true });
  105. }
  106. disconnectedCallback() {
  107. var _a;
  108. (_a = this.mutationObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
  109. }
  110. componentDidRender() {
  111. updateHostInteraction(this);
  112. }
  113. // --------------------------------------------------------------------------
  114. //
  115. // Methods
  116. //
  117. // --------------------------------------------------------------------------
  118. /** Sets focus on the component. */
  119. async setFocus() {
  120. var _a;
  121. (_a = this.buttonEl) === null || _a === void 0 ? void 0 : _a.focus();
  122. }
  123. // --------------------------------------------------------------------------
  124. //
  125. // Render Methods
  126. //
  127. // --------------------------------------------------------------------------
  128. renderTextContainer() {
  129. const { text, textEnabled } = this;
  130. const textContainerClasses = {
  131. [CSS.textContainer]: true,
  132. [CSS.textContainerVisible]: textEnabled
  133. };
  134. return text ? (h("div", { class: textContainerClasses, key: "text-container" }, text)) : null;
  135. }
  136. renderIconContainer() {
  137. var _a;
  138. const { loading, icon, scale, el, intlLoading } = this;
  139. const iconScale = scale === "l" ? "m" : "s";
  140. const loaderScale = scale === "l" ? "l" : "m";
  141. const calciteLoaderNode = loading ? (h("calcite-loader", { active: true, inline: true, label: intlLoading, scale: loaderScale })) : null;
  142. const calciteIconNode = icon ? h("calcite-icon", { icon: icon, scale: iconScale }) : null;
  143. const iconNode = calciteLoaderNode || calciteIconNode;
  144. const hasIconToDisplay = iconNode || ((_a = el.children) === null || _a === void 0 ? void 0 : _a.length);
  145. const slotContainerNode = (h("div", { class: {
  146. [CSS.slotContainer]: true,
  147. [CSS.slotContainerHidden]: loading
  148. } }, h("slot", null)));
  149. return hasIconToDisplay ? (h("div", { "aria-hidden": "true", class: CSS.iconContainer, key: "icon-container" }, iconNode, slotContainerNode)) : null;
  150. }
  151. render() {
  152. const { compact, disabled, loading, textEnabled, label, text } = this;
  153. const ariaLabel = label || text;
  154. const buttonClasses = {
  155. [CSS.button]: true,
  156. [CSS.buttonTextVisible]: textEnabled,
  157. [CSS.buttonCompact]: compact
  158. };
  159. return (h(Host, { onClick: this.calciteActionClickHandler }, h("button", { "aria-busy": toAriaBoolean(loading), "aria-disabled": toAriaBoolean(disabled), "aria-label": ariaLabel, class: buttonClasses, disabled: disabled, ref: (buttonEl) => (this.buttonEl = buttonEl) }, this.renderIconContainer(), this.renderTextContainer()), h("slot", { name: SLOTS.tooltip, onSlotchange: this.handleTooltipSlotChange })));
  160. }
  161. get el() { return getElement(this); }
  162. };
  163. Action.style = actionCss;
  164. export { Action as calcite_action };