chunk.MAVOU5NE.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. import {
  2. animateTo,
  3. stopAnimations,
  4. waitForEvent
  5. } from "./chunk.CTCDC263.js";
  6. import {
  7. getAnimation,
  8. setDefaultAnimation
  9. } from "./chunk.NC36RJW4.js";
  10. import {
  11. event,
  12. watch
  13. } from "./chunk.XX234VRK.js";
  14. import {
  15. e as e2
  16. } from "./chunk.YXKHB4AC.js";
  17. import {
  18. T,
  19. e,
  20. h,
  21. n,
  22. o,
  23. r
  24. } from "./chunk.5PIDMFOE.js";
  25. import {
  26. __decorateClass
  27. } from "./chunk.IHGPZX35.js";
  28. // _uyihdawu1:/Users/claviska/Projects/shoelace/src/components/alert/alert.scss
  29. var alert_default = ":host {\n position: relative;\n box-sizing: border-box;\n}\n:host *, :host *:before, :host *:after {\n box-sizing: inherit;\n}\n\n[hidden] {\n display: none !important;\n}\n\n:host {\n display: contents;\n margin: 0;\n}\n\n.alert {\n position: relative;\n display: flex;\n align-items: stretch;\n background-color: var(--sl-color-white);\n border: solid 1px var(--sl-color-gray-200);\n border-top-width: 3px;\n border-radius: var(--sl-border-radius-medium);\n box-shadow: var(--box-shadow);\n font-family: var(--sl-font-sans);\n font-size: var(--sl-font-size-small);\n font-weight: var(--sl-font-weight-normal);\n line-height: 1.6;\n color: var(--sl-color-gray-700);\n margin: inherit;\n}\n\n.alert__icon {\n flex: 0 0 auto;\n display: flex;\n align-items: center;\n font-size: var(--sl-font-size-large);\n}\n.alert__icon ::slotted(*) {\n margin-left: var(--sl-spacing-large);\n}\n\n.alert--primary {\n border-top-color: var(--sl-color-primary-500);\n}\n.alert--primary .alert__icon {\n color: var(--sl-color-primary-500);\n}\n\n.alert--success {\n border-top-color: var(--sl-color-success-500);\n}\n.alert--success .alert__icon {\n color: var(--sl-color-success-500);\n}\n\n.alert--info {\n border-top-color: var(--sl-color-info-500);\n}\n.alert--info .alert__icon {\n color: var(--sl-color-info-500);\n}\n\n.alert--warning {\n border-top-color: var(--sl-color-warning-500);\n}\n.alert--warning .alert__icon {\n color: var(--sl-color-warning-500);\n}\n\n.alert--danger {\n border-top-color: var(--sl-color-danger-500);\n}\n.alert--danger .alert__icon {\n color: var(--sl-color-danger-500);\n}\n\n.alert__message {\n flex: 1 1 auto;\n padding: var(--sl-spacing-large);\n overflow: hidden;\n}\n\n.alert__close {\n flex: 0 0 auto;\n display: flex;\n align-items: center;\n font-size: var(--sl-font-size-large);\n padding-right: var(--sl-spacing-medium);\n}";
  30. // src/components/alert/alert.ts
  31. var toastStack = Object.assign(document.createElement("div"), { className: "sl-toast-stack" });
  32. var SlAlert = class extends h {
  33. constructor() {
  34. super(...arguments);
  35. this.hasInitialized = false;
  36. this.open = false;
  37. this.closable = false;
  38. this.type = "primary";
  39. this.duration = Infinity;
  40. }
  41. firstUpdated() {
  42. this.base.hidden = !this.open;
  43. this.updateComplete.then(() => this.hasInitialized = true);
  44. }
  45. async show() {
  46. if (this.open) {
  47. return;
  48. }
  49. this.open = true;
  50. return waitForEvent(this, "sl-after-show");
  51. }
  52. async hide() {
  53. if (!this.open) {
  54. return;
  55. }
  56. this.open = false;
  57. return waitForEvent(this, "sl-after-hide");
  58. }
  59. async toast() {
  60. return new Promise((resolve) => {
  61. if (!toastStack.parentElement) {
  62. document.body.append(toastStack);
  63. }
  64. toastStack.appendChild(this);
  65. requestAnimationFrame(() => {
  66. this.clientWidth;
  67. this.show();
  68. });
  69. this.addEventListener("sl-after-hide", () => {
  70. toastStack.removeChild(this);
  71. resolve();
  72. if (!toastStack.querySelector("sl-alert")) {
  73. toastStack.remove();
  74. }
  75. }, { once: true });
  76. });
  77. }
  78. restartAutoHide() {
  79. clearTimeout(this.autoHideTimeout);
  80. if (this.open && this.duration < Infinity) {
  81. this.autoHideTimeout = setTimeout(() => this.hide(), this.duration);
  82. }
  83. }
  84. handleCloseClick() {
  85. this.hide();
  86. }
  87. handleMouseMove() {
  88. this.restartAutoHide();
  89. }
  90. async handleOpenChange() {
  91. if (!this.hasInitialized) {
  92. return;
  93. }
  94. if (this.open) {
  95. this.slShow.emit();
  96. if (this.duration < Infinity) {
  97. this.restartAutoHide();
  98. }
  99. await stopAnimations(this.base);
  100. this.base.hidden = false;
  101. const { keyframes, options } = getAnimation(this, "alert.show");
  102. await animateTo(this.base, keyframes, options);
  103. this.slAfterShow.emit();
  104. } else {
  105. this.slHide.emit();
  106. clearTimeout(this.autoHideTimeout);
  107. await stopAnimations(this.base);
  108. const { keyframes, options } = getAnimation(this, "alert.hide");
  109. await animateTo(this.base, keyframes, options);
  110. this.base.hidden = true;
  111. this.slAfterHide.emit();
  112. }
  113. }
  114. handleDurationChange() {
  115. this.restartAutoHide();
  116. }
  117. render() {
  118. return T`
  119. <div
  120. part="base"
  121. class=${e2({
  122. alert: true,
  123. "alert--open": this.open,
  124. "alert--closable": this.closable,
  125. "alert--primary": this.type === "primary",
  126. "alert--success": this.type === "success",
  127. "alert--info": this.type === "info",
  128. "alert--warning": this.type === "warning",
  129. "alert--danger": this.type === "danger"
  130. })}
  131. role="alert"
  132. aria-live="assertive"
  133. aria-atomic="true"
  134. aria-hidden=${this.open ? "false" : "true"}
  135. @mousemove=${this.handleMouseMove.bind(this)}
  136. >
  137. <span part="icon" class="alert__icon">
  138. <slot name="icon"></slot>
  139. </span>
  140. <span part="message" class="alert__message">
  141. <slot></slot>
  142. </span>
  143. ${this.closable ? T`
  144. <span class="alert__close">
  145. <sl-icon-button
  146. exportparts="base:close-button"
  147. name="x"
  148. library="system"
  149. @click=${this.handleCloseClick.bind(this)}
  150. ></sl-icon-button>
  151. </span>
  152. ` : ""}
  153. </div>
  154. `;
  155. }
  156. };
  157. SlAlert.styles = r(alert_default);
  158. __decorateClass([
  159. o('[part="base"]')
  160. ], SlAlert.prototype, "base", 2);
  161. __decorateClass([
  162. e({ type: Boolean, reflect: true })
  163. ], SlAlert.prototype, "open", 2);
  164. __decorateClass([
  165. e({ type: Boolean, reflect: true })
  166. ], SlAlert.prototype, "closable", 2);
  167. __decorateClass([
  168. e({ reflect: true })
  169. ], SlAlert.prototype, "type", 2);
  170. __decorateClass([
  171. e({ type: Number })
  172. ], SlAlert.prototype, "duration", 2);
  173. __decorateClass([
  174. event("sl-show")
  175. ], SlAlert.prototype, "slShow", 2);
  176. __decorateClass([
  177. event("sl-after-show")
  178. ], SlAlert.prototype, "slAfterShow", 2);
  179. __decorateClass([
  180. event("sl-hide")
  181. ], SlAlert.prototype, "slHide", 2);
  182. __decorateClass([
  183. event("sl-after-hide")
  184. ], SlAlert.prototype, "slAfterHide", 2);
  185. __decorateClass([
  186. watch("open")
  187. ], SlAlert.prototype, "handleOpenChange", 1);
  188. __decorateClass([
  189. watch("duration")
  190. ], SlAlert.prototype, "handleDurationChange", 1);
  191. SlAlert = __decorateClass([
  192. n("sl-alert")
  193. ], SlAlert);
  194. var alert_default2 = SlAlert;
  195. setDefaultAnimation("alert.show", {
  196. keyframes: [
  197. { opacity: 0, transform: "scale(0.8)" },
  198. { opacity: 1, transform: "scale(1)" }
  199. ],
  200. options: { duration: 250, easing: "ease" }
  201. });
  202. setDefaultAnimation("alert.hide", {
  203. keyframes: [
  204. { opacity: 1, transform: "scale(1)" },
  205. { opacity: 0, transform: "scale(0.8)" }
  206. ],
  207. options: { duration: 250, easing: "ease" }
  208. });
  209. export {
  210. alert_default2 as alert_default
  211. };