chunk.AYYU5VR7.js 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. import {
  2. isPreventScrollSupported,
  3. modal_default
  4. } from "./chunk.EAHZ6VJU.js";
  5. import {
  6. lockBodyScrolling,
  7. unlockBodyScrolling
  8. } from "./chunk.XAZN5AQ5.js";
  9. import {
  10. animateTo,
  11. stopAnimations,
  12. waitForEvent
  13. } from "./chunk.CTCDC263.js";
  14. import {
  15. getAnimation,
  16. setDefaultAnimation
  17. } from "./chunk.NC36RJW4.js";
  18. import {
  19. hasSlot
  20. } from "./chunk.FMCX45AD.js";
  21. import {
  22. l
  23. } from "./chunk.5MED2A3H.js";
  24. import {
  25. event,
  26. watch
  27. } from "./chunk.XX234VRK.js";
  28. import {
  29. e as e2
  30. } from "./chunk.YXKHB4AC.js";
  31. import {
  32. T,
  33. e,
  34. h,
  35. n,
  36. o,
  37. r,
  38. r2
  39. } from "./chunk.5PIDMFOE.js";
  40. import {
  41. __decorateClass
  42. } from "./chunk.IHGPZX35.js";
  43. // _uyihdawu1:/Users/claviska/Projects/shoelace/src/components/dialog/dialog.scss
  44. var dialog_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 --width: 31rem;\n --header-spacing: var(--sl-spacing-large);\n --body-spacing: var(--sl-spacing-large);\n --footer-spacing: var(--sl-spacing-large);\n display: contents;\n}\n\n.dialog {\n display: flex;\n align-items: center;\n justify-content: center;\n position: fixed;\n top: 0;\n right: 0;\n bottom: 0;\n left: 0;\n z-index: var(--sl-z-index-dialog);\n}\n\n.dialog__panel {\n display: flex;\n flex-direction: column;\n z-index: 2;\n width: var(--width);\n max-width: calc(100% - var(--sl-spacing-xx-large));\n max-height: calc(100% - var(--sl-spacing-xx-large));\n background-color: var(--sl-panel-background-color);\n border-radius: var(--sl-border-radius-medium);\n box-shadow: var(--sl-shadow-x-large);\n}\n.dialog__panel:focus {\n outline: none;\n}\n\n@media screen and (max-width: 420px) {\n .dialog__panel {\n max-height: 80vh;\n }\n}\n.dialog--open .dialog__panel {\n display: flex;\n opacity: 1;\n transform: none;\n}\n\n.dialog__header {\n flex: 0 0 auto;\n display: flex;\n}\n\n.dialog__title {\n flex: 1 1 auto;\n font-size: var(--sl-font-size-large);\n line-height: var(--sl-line-height-dense);\n padding: var(--header-spacing);\n}\n\n.dialog__close {\n flex: 0 0 auto;\n display: flex;\n align-items: center;\n font-size: var(--sl-font-size-x-large);\n padding: 0 var(--header-spacing);\n}\n\n.dialog__body {\n flex: 1 1 auto;\n padding: var(--body-spacing);\n overflow: auto;\n -webkit-overflow-scrolling: touch;\n}\n\n.dialog__footer {\n flex: 0 0 auto;\n text-align: right;\n padding: var(--footer-spacing);\n}\n.dialog__footer ::slotted(sl-button:not(:first-of-type)) {\n margin-left: var(--sl-spacing-x-small);\n}\n\n.dialog:not(.dialog--has-footer) .dialog__footer {\n display: none;\n}\n\n.dialog__overlay {\n position: fixed;\n top: 0;\n right: 0;\n bottom: 0;\n left: 0;\n background-color: var(--sl-overlay-background-color);\n}";
  45. // src/components/dialog/dialog.ts
  46. var hasPreventScroll = isPreventScrollSupported();
  47. var id = 0;
  48. var SlDialog = class extends h {
  49. constructor() {
  50. super(...arguments);
  51. this.componentId = `dialog-${++id}`;
  52. this.hasInitialized = false;
  53. this.hasFooter = false;
  54. this.open = false;
  55. this.label = "";
  56. this.noHeader = false;
  57. }
  58. connectedCallback() {
  59. super.connectedCallback();
  60. this.modal = new modal_default(this);
  61. this.handleSlotChange();
  62. }
  63. firstUpdated() {
  64. this.dialog.hidden = !this.open;
  65. this.updateComplete.then(() => this.hasInitialized = true);
  66. }
  67. disconnectedCallback() {
  68. super.disconnectedCallback();
  69. unlockBodyScrolling(this);
  70. }
  71. async show() {
  72. if (this.open) {
  73. return;
  74. }
  75. this.open = true;
  76. return waitForEvent(this, "sl-after-show");
  77. }
  78. async hide() {
  79. if (!this.open) {
  80. return;
  81. }
  82. this.open = false;
  83. return waitForEvent(this, "sl-after-hide");
  84. }
  85. handleCloseClick() {
  86. this.hide();
  87. }
  88. handleKeyDown(event2) {
  89. if (event2.key === "Escape") {
  90. event2.stopPropagation();
  91. this.hide();
  92. }
  93. }
  94. async handleOpenChange() {
  95. if (!this.hasInitialized) {
  96. return;
  97. }
  98. if (this.open) {
  99. this.slShow.emit();
  100. this.originalTrigger = document.activeElement;
  101. this.modal.activate();
  102. lockBodyScrolling(this);
  103. await Promise.all([stopAnimations(this.dialog), stopAnimations(this.overlay)]);
  104. this.dialog.hidden = false;
  105. if (hasPreventScroll) {
  106. const slInitialFocus = this.slInitialFocus.emit({ cancelable: true });
  107. if (!slInitialFocus.defaultPrevented) {
  108. this.panel.focus({ preventScroll: true });
  109. }
  110. }
  111. const panelAnimation = getAnimation(this, "dialog.show");
  112. const overlayAnimation = getAnimation(this, "dialog.overlay.show");
  113. await Promise.all([
  114. animateTo(this.panel, panelAnimation.keyframes, panelAnimation.options),
  115. animateTo(this.overlay, overlayAnimation.keyframes, overlayAnimation.options)
  116. ]);
  117. if (!hasPreventScroll) {
  118. const slInitialFocus = this.slInitialFocus.emit({ cancelable: true });
  119. if (!slInitialFocus.defaultPrevented) {
  120. this.panel.focus({ preventScroll: true });
  121. }
  122. }
  123. this.slAfterShow.emit();
  124. } else {
  125. this.slHide.emit();
  126. this.modal.deactivate();
  127. await Promise.all([stopAnimations(this.dialog), stopAnimations(this.overlay)]);
  128. const panelAnimation = getAnimation(this, "dialog.hide");
  129. const overlayAnimation = getAnimation(this, "dialog.overlay.hide");
  130. await Promise.all([
  131. animateTo(this.panel, panelAnimation.keyframes, panelAnimation.options),
  132. animateTo(this.overlay, overlayAnimation.keyframes, overlayAnimation.options)
  133. ]);
  134. this.dialog.hidden = true;
  135. unlockBodyScrolling(this);
  136. const trigger = this.originalTrigger;
  137. if (trigger && typeof trigger.focus === "function") {
  138. setTimeout(() => trigger.focus());
  139. }
  140. this.slAfterHide.emit();
  141. }
  142. }
  143. handleOverlayClick() {
  144. const slOverlayDismiss = this.slOverlayDismiss.emit({ cancelable: true });
  145. if (!slOverlayDismiss.defaultPrevented) {
  146. this.hide();
  147. }
  148. }
  149. handleSlotChange() {
  150. this.hasFooter = hasSlot(this, "footer");
  151. }
  152. render() {
  153. return T`
  154. <div
  155. part="base"
  156. class=${e2({
  157. dialog: true,
  158. "dialog--open": this.open,
  159. "dialog--has-footer": this.hasFooter
  160. })}
  161. @keydown=${this.handleKeyDown}
  162. >
  163. <div part="overlay" class="dialog__overlay" @click=${this.handleOverlayClick} tabindex="-1"></div>
  164. <div
  165. part="panel"
  166. class="dialog__panel"
  167. role="dialog"
  168. aria-modal="true"
  169. aria-hidden=${this.open ? "false" : "true"}
  170. aria-label=${l(this.noHeader ? this.label : void 0)}
  171. aria-labelledby=${l(!this.noHeader ? `${this.componentId}-title` : void 0)}
  172. tabindex="0"
  173. >
  174. ${!this.noHeader ? T`
  175. <header part="header" class="dialog__header">
  176. <span part="title" class="dialog__title" id=${`${this.componentId}-title`}>
  177. <slot name="label"> ${this.label || String.fromCharCode(65279)} </slot>
  178. </span>
  179. <sl-icon-button
  180. exportparts="base:close-button"
  181. class="dialog__close"
  182. name="x"
  183. library="system"
  184. @click="${this.handleCloseClick}"
  185. ></sl-icon-button>
  186. </header>
  187. ` : ""}
  188. <div part="body" class="dialog__body">
  189. <slot></slot>
  190. </div>
  191. <footer part="footer" class="dialog__footer">
  192. <slot name="footer" @slotchange=${this.handleSlotChange}></slot>
  193. </footer>
  194. </div>
  195. </div>
  196. `;
  197. }
  198. };
  199. SlDialog.styles = r(dialog_default);
  200. __decorateClass([
  201. o(".dialog")
  202. ], SlDialog.prototype, "dialog", 2);
  203. __decorateClass([
  204. o(".dialog__panel")
  205. ], SlDialog.prototype, "panel", 2);
  206. __decorateClass([
  207. o(".dialog__overlay")
  208. ], SlDialog.prototype, "overlay", 2);
  209. __decorateClass([
  210. r2()
  211. ], SlDialog.prototype, "hasFooter", 2);
  212. __decorateClass([
  213. e({ type: Boolean, reflect: true })
  214. ], SlDialog.prototype, "open", 2);
  215. __decorateClass([
  216. e({ reflect: true })
  217. ], SlDialog.prototype, "label", 2);
  218. __decorateClass([
  219. e({ attribute: "no-header", type: Boolean, reflect: true })
  220. ], SlDialog.prototype, "noHeader", 2);
  221. __decorateClass([
  222. event("sl-show")
  223. ], SlDialog.prototype, "slShow", 2);
  224. __decorateClass([
  225. event("sl-after-show")
  226. ], SlDialog.prototype, "slAfterShow", 2);
  227. __decorateClass([
  228. event("sl-hide")
  229. ], SlDialog.prototype, "slHide", 2);
  230. __decorateClass([
  231. event("sl-after-hide")
  232. ], SlDialog.prototype, "slAfterHide", 2);
  233. __decorateClass([
  234. event("sl-initial-focus")
  235. ], SlDialog.prototype, "slInitialFocus", 2);
  236. __decorateClass([
  237. event("sl-overlay-dismiss")
  238. ], SlDialog.prototype, "slOverlayDismiss", 2);
  239. __decorateClass([
  240. watch("open")
  241. ], SlDialog.prototype, "handleOpenChange", 1);
  242. SlDialog = __decorateClass([
  243. n("sl-dialog")
  244. ], SlDialog);
  245. var dialog_default2 = SlDialog;
  246. setDefaultAnimation("dialog.show", {
  247. keyframes: [
  248. { opacity: 0, transform: "scale(0.8)" },
  249. { opacity: 1, transform: "scale(1)" }
  250. ],
  251. options: { duration: 250, easing: "ease" }
  252. });
  253. setDefaultAnimation("dialog.hide", {
  254. keyframes: [
  255. { opacity: 1, transform: "scale(1)" },
  256. { opacity: 0, transform: "scale(0.8)" }
  257. ],
  258. options: { duration: 250, easing: "ease" }
  259. });
  260. setDefaultAnimation("dialog.overlay.show", {
  261. keyframes: [{ opacity: 0 }, { opacity: 1 }],
  262. options: { duration: 250 }
  263. });
  264. setDefaultAnimation("dialog.overlay.hide", {
  265. keyframes: [{ opacity: 1 }, { opacity: 0 }],
  266. options: { duration: 250 }
  267. });
  268. export {
  269. dialog_default2 as dialog_default
  270. };