calcite-alert.cjs.entry.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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. 'use strict';
  7. Object.defineProperty(exports, '__esModule', { value: true });
  8. const index = require('./index-a0010f96.js');
  9. const dom = require('./dom-2ec8c9ed.js');
  10. const interfaces = require('./interfaces-971ccc32.js');
  11. const openCloseComponent = require('./openCloseComponent-178191c0.js');
  12. const locale = require('./locale-678ce361.js');
  13. require('./resources-b5a5f8a7.js');
  14. require('./guid-f4f03a7a.js');
  15. require('./key-6a462411.js');
  16. require('./observers-5706326b.js');
  17. const TEXT = {
  18. intlClose: "Close"
  19. };
  20. const DURATIONS = {
  21. slow: 14000,
  22. medium: 10000,
  23. fast: 6000
  24. };
  25. const SLOTS = {
  26. title: "title",
  27. message: "message",
  28. link: "link"
  29. };
  30. const alertCss = "@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}}:root{--calcite-floating-ui-transition:var(--calcite-animation-timing)}:host([hidden]){display:none}:host([scale=s]){--calcite-alert-width:40em;--calcite-alert-spacing-token-small:0.5rem;--calcite-alert-spacing-token-large:0.75rem}:host([scale=s]) slot[name=title]::slotted(*),:host([scale=s]) *::slotted([slot=title]){font-size:var(--calcite-font-size--1);line-height:1.375}:host([scale=s]) slot[name=message]::slotted(*),:host([scale=s]) *::slotted([slot=message]){font-size:var(--calcite-font-size--2);line-height:1.375}:host([scale=s]) slot[name=link]::slotted(*),:host([scale=s]) *::slotted([slot=link]){font-size:var(--calcite-font-size--2);line-height:1.375}:host([scale=s]) .alert-queue-count{margin-inline:0.5rem}:host([scale=s]) .container{--calcite-alert-min-height:3.5rem}:host([scale=s]) .alert-close{padding:0.5rem}:host([scale=m]){--calcite-alert-width:50em;--calcite-alert-spacing-token-small:0.75rem;--calcite-alert-spacing-token-large:1rem}:host([scale=m]) slot[name=title]::slotted(*),:host([scale=m]) *::slotted([slot=title]){font-size:var(--calcite-font-size-0);line-height:1.375}:host([scale=m]) slot[name=message]::slotted(*),:host([scale=m]) *::slotted([slot=message]){font-size:var(--calcite-font-size--1);line-height:1.375}:host([scale=m]) slot[name=link]::slotted(*),:host([scale=m]) *::slotted([slot=link]){font-size:var(--calcite-font-size--1);line-height:1.375}:host([scale=m]) .alert-queue-count{margin-inline:0.75rem}:host([scale=m]) .container{--calcite-alert-min-height:4.1875rem}:host([scale=l]){--calcite-alert-width:60em;--calcite-alert-spacing-token-small:1rem;--calcite-alert-spacing-token-large:1.25rem}:host([scale=l]) slot[name=title]::slotted(*),:host([scale=l]) *::slotted([slot=title]){margin-block-end:0.25rem;font-size:var(--calcite-font-size-1);line-height:1.375}:host([scale=l]) slot[name=message]::slotted(*),:host([scale=l]) *::slotted([slot=message]){font-size:var(--calcite-font-size-0);line-height:1.375}:host([scale=l]) slot[name=link]::slotted(*),:host([scale=l]) *::slotted([slot=link]){font-size:var(--calcite-font-size-0);line-height:1.375}:host([scale=l]) .alert-queue-count{margin-inline:1rem}:host([scale=l]) .container{--calcite-alert-min-height:5.625rem}:host{--calcite-alert-edge-distance:2rem;display:block}:host .container{pointer-events:none;position:fixed;z-index:500;margin-block:0px;margin-inline:auto;display:flex;align-items:center;justify-content:center;background-color:var(--calcite-ui-foreground-1);opacity:0;--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);border-radius:var(--calcite-border-radius);border-block-start:0px solid transparent;border-inline:1px solid var(--calcite-ui-border-3);border-block-end:1px solid var(--calcite-ui-border-3);min-block-size:var(--calcite-alert-min-height);inline-size:var(--calcite-alert-width);max-inline-size:calc(100% - (var(--calcite-alert-edge-distance) * 2 + 2px));max-block-size:0;transition:var(--calcite-internal-animation-timing-slow) cubic-bezier(0.215, 0.44, 0.42, 0.88), opacity var(--calcite-internal-animation-timing-slow) cubic-bezier(0.215, 0.44, 0.42, 0.88), all var(--calcite-animation-timing) ease-in-out}:host .container.bottom,:host .container.top{inset-inline-end:0;inset-inline-start:0}:host .container[class*=bottom]{transform:translate3d(0, var(--calcite-alert-edge-distance), 0);inset-block-end:var(--calcite-alert-edge-distance)}:host .container[class*=top]{transform:translate3d(0, calc(-1 * var(--calcite-alert-edge-distance)), 0);inset-block-start:var(--calcite-alert-edge-distance)}:host .container[class*=-start]{inset-inline-start:var(--calcite-alert-edge-distance);inset-inline-end:auto}:host .container[class*=-end]{inset-inline-end:var(--calcite-alert-edge-distance);inset-inline-start:auto}:host([calcite-hydrated-hidden]){visibility:hidden !important;pointer-events:none}.container{display:flex;inline-size:100%;align-items:center;justify-content:center}.alert-close{outline-color:transparent}.alert-close:focus{outline:2px solid var(--calcite-ui-brand);outline-offset:-2px}:host([open]) .container:not(.queued){max-block-size:100%;border-block-start-width:2px;opacity:1;pointer-events:initial}:host([open]) .container:not(.queued)[class*=bottom]{transform:translate3d(0, calc(-1 * var(--calcite-alert-edge-distance)), inherit)}:host([open]) .container:not(.queued)[class*=top]{transform:translate3d(0, var(--calcite-alert-edge-distance), inherit)}slot[name=title]::slotted(*),*::slotted([slot=title]){font-size:var(--calcite-font-size-0);line-height:1.375;font-weight:var(--calcite-font-weight-medium);color:var(--calcite-ui-text-1)}slot[name=message]::slotted(*),*::slotted([slot=message]){margin:0px;display:inline;font-size:var(--calcite-font-size--1);line-height:1.375;font-weight:var(--calcite-font-weight-normal);color:var(--calcite-ui-text-2);margin-inline-end:0.5rem}slot[name=link]::slotted(*),*::slotted([slot=link]){display:inline-flex;color:var(--calcite-ui-text-link)}.alert-content{transition:all var(--calcite-animation-timing) ease-in-out 0s, outline 0s, outline-offset 0s;padding-inline:var(--calcite-alert-spacing-token-large);flex:0 0 auto;overflow-wrap:break-word;background-color:var(--calcite-ui-foreground-1);flex:1 1 auto;min-inline-size:0;padding-block:var(--calcite-alert-spacing-token-small);padding-inline:0 var(--calcite-alert-spacing-token-small);border-end-start-radius:var(--calcite-border-radius);border-end-end-radius:var(--calcite-border-radius)}.alert-content:first-of-type:not(:only-child){padding-inline-start:var(--calcite-alert-spacing-token-large)}.alert-content:only-child{padding:var(--calcite-alert-spacing-token-small)}.alert-icon{transition:all var(--calcite-animation-timing) ease-in-out 0s, outline 0s, outline-offset 0s;padding-block:var(--calcite-alert-spacing-token-small);padding-inline:var(--calcite-alert-spacing-token-large);flex:0 0 auto;display:flex;align-items:center;align-self:stretch;background-color:var(--calcite-ui-foreground-1);padding-block:0px}.alert-close{transition:all var(--calcite-animation-timing) ease-in-out 0s, outline 0s, outline-offset 0s;padding-block:var(--calcite-alert-spacing-token-small);padding-inline:var(--calcite-alert-spacing-token-large);flex:0 0 auto;cursor:pointer;align-self:stretch;overflow:hidden;border-style:none;background-color:var(--calcite-ui-foreground-1);padding-block:0px;color:var(--calcite-ui-text-3);outline:2px solid transparent;outline-offset:2px;border-end-end-radius:var(--calcite-border-radius)}.alert-close:hover,.alert-close:focus{background-color:var(--calcite-ui-foreground-2);color:var(--calcite-ui-text-1)}.alert-close:open{background-color:var(--calcite-ui-foreground-3)}.alert-queue-count{visibility:hidden;display:flex;cursor:default;align-items:center;justify-content:space-around;align-self:stretch;overflow:hidden;background-color:var(--calcite-ui-foreground-1);text-align:center;font-weight:var(--calcite-font-weight-medium);color:var(--calcite-ui-text-2);opacity:0;transition:all var(--calcite-animation-timing) ease-in-out 0s, outline 0s, outline-offset 0s;border-inline:0px solid transparent;border-start-end-radius:0}.alert-queue-count.active{visibility:visible;opacity:1}:host([auto-dismiss])>.alert-queue-count{border-inline-end:0px solid transparent}.alert-dismiss-progress{position:absolute;display:block;inline-size:100%;overflow:hidden;inset-inline:0;inset-block-start:-2px;block-size:2px;border-radius:var(--calcite-border-radius) var(--calcite-border-radius) 0 0}.alert-dismiss-progress:after{position:absolute;inset-block-start:0px;display:block;block-size:2px;content:\"\";background-color:var(--calcite-alert-dismiss-progress-background);inset-inline-end:0}:host([color=blue]) .container{border-block-start-color:var(--calcite-ui-info)}:host([color=blue]) .container .alert-icon{color:var(--calcite-ui-info)}:host([color=red]) .container{border-block-start-color:var(--calcite-ui-danger)}:host([color=red]) .container .alert-icon{color:var(--calcite-ui-danger)}:host([color=yellow]) .container{border-block-start-color:var(--calcite-ui-warning)}:host([color=yellow]) .container .alert-icon{color:var(--calcite-ui-warning)}:host([color=green]) .container{border-block-start-color:var(--calcite-ui-success)}:host([color=green]) .container .alert-icon{color:var(--calcite-ui-success)}:host([auto-dismiss-duration=fast]) .alert-dismiss-progress:after{animation:dismissProgress 6000ms ease-out}:host([auto-dismiss-duration=medium]) .alert-dismiss-progress:after{animation:dismissProgress 10000ms ease-out}:host([auto-dismiss-duration=slow]) .alert-dismiss-progress:after{animation:dismissProgress 14000ms ease-out}@keyframes dismissProgress{0%{inline-size:0px;opacity:0.75}100%{inline-size:100%;opacity:1}}";
  31. const Alert = class {
  32. constructor(hostRef) {
  33. index.registerInstance(this, hostRef);
  34. this.calciteAlertBeforeClose = index.createEvent(this, "calciteAlertBeforeClose", 6);
  35. this.calciteAlertClose = index.createEvent(this, "calciteAlertClose", 6);
  36. this.calciteAlertBeforeOpen = index.createEvent(this, "calciteAlertBeforeOpen", 6);
  37. this.calciteAlertOpen = index.createEvent(this, "calciteAlertOpen", 6);
  38. this.calciteInternalAlertSync = index.createEvent(this, "calciteInternalAlertSync", 6);
  39. this.calciteInternalAlertRegister = index.createEvent(this, "calciteInternalAlertRegister", 6);
  40. //--------------------------------------------------------------------------
  41. //
  42. // Properties
  43. //
  44. //---------------------------------------------------------------------------
  45. /**
  46. * When `true`, displays and positions the component.
  47. *
  48. * @deprecated use `open` instead.
  49. */
  50. this.active = false;
  51. /** When `true`, displays and positions the component. */
  52. this.open = false;
  53. /** When `true`, the component closes automatically (recommended for passive, non-blocking alerts). */
  54. this.autoDismiss = false;
  55. /** Specifies the duration before the component automatically closes (only use with `autoDismiss`). */
  56. this.autoDismissDuration = this.autoDismiss ? "medium" : null;
  57. /** Specifies the color for the component (will apply to top border and icon). */
  58. this.color = "blue";
  59. /**
  60. * Specifies the text label for the close button.
  61. *
  62. * @default "Close"
  63. */
  64. this.intlClose = TEXT.intlClose;
  65. /** Specifies the placement of the component */
  66. this.placement = "bottom";
  67. /** Specifies the size of the component. */
  68. this.scale = "m";
  69. //--------------------------------------------------------------------------
  70. //
  71. // Private State/Props
  72. //
  73. //--------------------------------------------------------------------------
  74. this.effectiveLocale = "";
  75. /** the list of queued alerts */
  76. this.queue = [];
  77. /** the count of queued alerts */
  78. this.queueLength = 0;
  79. /** is the alert queued */
  80. this.queued = false;
  81. this.autoDismissTimeoutId = null;
  82. this.trackTimer = Date.now();
  83. this.openTransitionProp = "opacity";
  84. //--------------------------------------------------------------------------
  85. //
  86. // Private Methods
  87. //
  88. //--------------------------------------------------------------------------
  89. this.setTransitionEl = (el) => {
  90. this.transitionEl = el;
  91. openCloseComponent.connectOpenCloseComponent(this);
  92. };
  93. /** close and emit calciteInternalAlertSync event with the updated queue payload */
  94. this.closeAlert = () => {
  95. this.autoDismissTimeoutId = null;
  96. this.queued = false;
  97. this.open = false;
  98. this.queue = this.queue.filter((el) => el !== this.el);
  99. this.determineActiveAlert();
  100. this.calciteInternalAlertSync.emit({ queue: this.queue });
  101. };
  102. }
  103. activeHandler(value) {
  104. this.open = value;
  105. }
  106. openHandler(value) {
  107. if (this.open && !this.queued) {
  108. this.calciteInternalAlertRegister.emit();
  109. this.active = value;
  110. }
  111. if (!this.open) {
  112. this.queue = this.queue.filter((el) => el !== this.el);
  113. this.calciteInternalAlertSync.emit({ queue: this.queue });
  114. this.active = false;
  115. }
  116. }
  117. updateRequestedIcon() {
  118. this.requestedIcon = dom.setRequestedIcon(interfaces.StatusIcons, this.icon, this.color);
  119. }
  120. updateDuration() {
  121. if (this.autoDismiss && this.autoDismissTimeoutId) {
  122. window.clearTimeout(this.autoDismissTimeoutId);
  123. this.autoDismissTimeoutId = window.setTimeout(() => this.closeAlert(), DURATIONS[this.autoDismissDuration] - (Date.now() - this.trackTimer));
  124. }
  125. }
  126. //--------------------------------------------------------------------------
  127. //
  128. // Lifecycle
  129. //
  130. //--------------------------------------------------------------------------
  131. connectedCallback() {
  132. locale.connectLocalized(this);
  133. const open = this.open || this.active;
  134. if (open && !this.queued) {
  135. this.activeHandler(open);
  136. this.openHandler(open);
  137. this.calciteInternalAlertRegister.emit();
  138. }
  139. openCloseComponent.connectOpenCloseComponent(this);
  140. }
  141. componentWillLoad() {
  142. this.requestedIcon = dom.setRequestedIcon(interfaces.StatusIcons, this.icon, this.color);
  143. }
  144. disconnectedCallback() {
  145. window.clearTimeout(this.autoDismissTimeoutId);
  146. openCloseComponent.disconnectOpenCloseComponent(this);
  147. locale.disconnectLocalized(this);
  148. }
  149. render() {
  150. const closeButton = (index.h("button", { "aria-label": this.intlClose, class: "alert-close", onClick: this.closeAlert, ref: (el) => (this.closeButton = el), type: "button" }, index.h("calcite-icon", { icon: "x", scale: this.scale === "l" ? "m" : "s" })));
  151. locale.numberStringFormatter.numberFormatOptions = {
  152. locale: this.effectiveLocale,
  153. numberingSystem: this.numberingSystem,
  154. signDisplay: "always"
  155. };
  156. const queueNumber = this.queueLength > 2 ? this.queueLength - 1 : 1;
  157. const queueText = locale.numberStringFormatter.numberFormatter.format(queueNumber);
  158. const queueCount = (index.h("div", { class: `${this.queueLength > 1 ? "active " : ""}alert-queue-count` }, index.h("calcite-chip", { scale: this.scale, value: queueText }, queueText)));
  159. const { active, autoDismiss, label, placement, queued, requestedIcon } = this;
  160. const role = autoDismiss ? "alert" : "alertdialog";
  161. const hidden = !active;
  162. return (index.h(index.Host, { "aria-hidden": dom.toAriaBoolean(hidden), "aria-label": label, "calcite-hydrated-hidden": hidden, role: role }, index.h("div", { class: {
  163. container: true,
  164. queued,
  165. [placement]: true
  166. }, ref: this.setTransitionEl }, requestedIcon ? (index.h("div", { class: "alert-icon" }, index.h("calcite-icon", { icon: requestedIcon, scale: this.scale === "l" ? "m" : "s" }))) : null, index.h("div", { class: "alert-content" }, index.h("slot", { name: SLOTS.title }), index.h("slot", { name: SLOTS.message }), index.h("slot", { name: SLOTS.link })), queueCount, !autoDismiss ? closeButton : null, active && !queued && autoDismiss ? index.h("div", { class: "alert-dismiss-progress" }) : null)));
  167. }
  168. // when an alert is opened or closed, update queue and determine active alert
  169. alertSync(event) {
  170. if (this.queue !== event.detail.queue) {
  171. this.queue = event.detail.queue;
  172. }
  173. this.queueLength = this.queue.length;
  174. this.determineActiveAlert();
  175. event.stopPropagation();
  176. }
  177. // when an alert is first registered, trigger a queue sync
  178. alertRegister() {
  179. if (this.open && !this.queue.includes(this.el)) {
  180. this.queued = true;
  181. this.queue.push(this.el);
  182. }
  183. this.calciteInternalAlertSync.emit({ queue: this.queue });
  184. this.determineActiveAlert();
  185. }
  186. //--------------------------------------------------------------------------
  187. //
  188. // Public Methods
  189. //
  190. //--------------------------------------------------------------------------
  191. /** Sets focus on the component. */
  192. async setFocus() {
  193. const alertLinkEl = dom.getSlotted(this.el, { selector: "calcite-link" });
  194. if (!this.closeButton && !alertLinkEl) {
  195. return;
  196. }
  197. else if (alertLinkEl) {
  198. alertLinkEl.setFocus();
  199. }
  200. else if (this.closeButton) {
  201. this.closeButton.focus();
  202. }
  203. }
  204. /** determine which alert is active */
  205. determineActiveAlert() {
  206. var _a;
  207. if (((_a = this.queue) === null || _a === void 0 ? void 0 : _a[0]) === this.el) {
  208. this.openAlert();
  209. if (this.autoDismiss && !this.autoDismissTimeoutId) {
  210. this.trackTimer = Date.now();
  211. this.autoDismissTimeoutId = window.setTimeout(() => this.closeAlert(), DURATIONS[this.autoDismissDuration]);
  212. }
  213. }
  214. else {
  215. return;
  216. }
  217. }
  218. onBeforeOpen() {
  219. this.calciteAlertBeforeOpen.emit();
  220. }
  221. onOpen() {
  222. this.calciteAlertOpen.emit();
  223. }
  224. onBeforeClose() {
  225. this.calciteAlertBeforeClose.emit();
  226. }
  227. onClose() {
  228. this.calciteAlertClose.emit();
  229. }
  230. /** remove queued class after animation completes */
  231. openAlert() {
  232. window.clearTimeout(this.queueTimeout);
  233. this.queueTimeout = window.setTimeout(() => (this.queued = false), 300);
  234. }
  235. get el() { return index.getElement(this); }
  236. static get watchers() { return {
  237. "active": ["activeHandler"],
  238. "open": ["openHandler"],
  239. "icon": ["updateRequestedIcon"],
  240. "color": ["updateRequestedIcon"],
  241. "autoDismissDuration": ["updateDuration"]
  242. }; }
  243. };
  244. Alert.style = alertCss;
  245. exports.calcite_alert = Alert;