chunk.JMRYI5SC.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  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. // src/internal/string.ts
  44. function uppercaseFirstLetter(string) {
  45. return string.charAt(0).toUpperCase() + string.slice(1);
  46. }
  47. // _uyihdawu1:/Users/claviska/Projects/shoelace/src/components/drawer/drawer.scss
  48. var drawer_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 --size: 25rem;\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.drawer {\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n pointer-events: none;\n overflow: hidden;\n}\n\n.drawer--contained {\n position: absolute;\n z-index: initial;\n}\n\n.drawer--fixed {\n position: fixed;\n z-index: var(--sl-z-index-drawer);\n}\n\n.drawer__panel {\n position: absolute;\n display: flex;\n flex-direction: column;\n z-index: 2;\n max-width: 100%;\n max-height: 100%;\n background-color: var(--sl-panel-background-color);\n box-shadow: var(--sl-shadow-x-large);\n transition: var(--sl-transition-medium) transform;\n overflow: auto;\n pointer-events: all;\n}\n.drawer__panel:focus {\n outline: none;\n}\n\n.drawer--top .drawer__panel {\n top: 0;\n right: auto;\n bottom: auto;\n left: 0;\n width: 100%;\n height: var(--size);\n}\n\n.drawer--end .drawer__panel {\n top: 0;\n right: 0;\n bottom: auto;\n left: auto;\n width: var(--size);\n height: 100%;\n}\n\n.drawer--bottom .drawer__panel {\n top: auto;\n right: auto;\n bottom: 0;\n left: 0;\n width: 100%;\n height: var(--size);\n}\n\n.drawer--start .drawer__panel {\n top: 0;\n right: auto;\n bottom: auto;\n left: 0;\n width: var(--size);\n height: 100%;\n}\n\n.drawer__header {\n display: flex;\n}\n\n.drawer__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.drawer__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.drawer__body {\n flex: 1 1 auto;\n padding: var(--body-spacing);\n overflow: auto;\n -webkit-overflow-scrolling: touch;\n}\n\n.drawer__footer {\n text-align: right;\n padding: var(--footer-spacing);\n}\n.drawer__footer ::slotted(sl-button:not(:last-of-type)) {\n margin-right: var(--sl-spacing-x-small);\n}\n\n.drawer:not(.drawer--has-footer) .drawer__footer {\n display: none;\n}\n\n.drawer__overlay {\n display: block;\n position: fixed;\n top: 0;\n right: 0;\n bottom: 0;\n left: 0;\n background-color: var(--sl-overlay-background-color);\n pointer-events: all;\n}\n\n.drawer--contained .drawer__overlay {\n position: absolute;\n}";
  49. // src/components/drawer/drawer.ts
  50. var hasPreventScroll = isPreventScrollSupported();
  51. var id = 0;
  52. var SlDrawer = class extends h {
  53. constructor() {
  54. super(...arguments);
  55. this.componentId = `drawer-${++id}`;
  56. this.hasInitialized = false;
  57. this.hasFooter = false;
  58. this.open = false;
  59. this.label = "";
  60. this.placement = "end";
  61. this.contained = false;
  62. this.noHeader = false;
  63. }
  64. connectedCallback() {
  65. super.connectedCallback();
  66. this.modal = new modal_default(this);
  67. this.handleSlotChange();
  68. }
  69. firstUpdated() {
  70. this.drawer.hidden = !this.open;
  71. this.updateComplete.then(() => this.hasInitialized = true);
  72. }
  73. disconnectedCallback() {
  74. super.disconnectedCallback();
  75. unlockBodyScrolling(this);
  76. }
  77. async show() {
  78. if (this.open) {
  79. return;
  80. }
  81. this.open = true;
  82. return waitForEvent(this, "sl-after-show");
  83. }
  84. async hide() {
  85. if (!this.open) {
  86. return;
  87. }
  88. this.open = false;
  89. return waitForEvent(this, "sl-after-hide");
  90. }
  91. handleCloseClick() {
  92. this.hide();
  93. }
  94. handleKeyDown(event2) {
  95. if (event2.key === "Escape") {
  96. event2.stopPropagation();
  97. this.hide();
  98. }
  99. }
  100. async handleOpenChange() {
  101. if (!this.hasInitialized) {
  102. return;
  103. }
  104. if (this.open) {
  105. this.slShow.emit();
  106. this.originalTrigger = document.activeElement;
  107. if (!this.contained) {
  108. this.modal.activate();
  109. lockBodyScrolling(this);
  110. }
  111. await Promise.all([stopAnimations(this.drawer), stopAnimations(this.overlay)]);
  112. this.drawer.hidden = false;
  113. if (hasPreventScroll) {
  114. const slInitialFocus = this.slInitialFocus.emit({ cancelable: true });
  115. if (!slInitialFocus.defaultPrevented) {
  116. this.panel.focus({ preventScroll: true });
  117. }
  118. }
  119. const panelAnimation = getAnimation(this, `drawer.show${uppercaseFirstLetter(this.placement)}`);
  120. const overlayAnimation = getAnimation(this, "drawer.overlay.show");
  121. await Promise.all([
  122. animateTo(this.panel, panelAnimation.keyframes, panelAnimation.options),
  123. animateTo(this.overlay, overlayAnimation.keyframes, overlayAnimation.options)
  124. ]);
  125. if (!hasPreventScroll) {
  126. const slInitialFocus = this.slInitialFocus.emit({ cancelable: true });
  127. if (!slInitialFocus.defaultPrevented) {
  128. this.panel.focus({ preventScroll: true });
  129. }
  130. }
  131. this.slAfterShow.emit();
  132. } else {
  133. this.slHide.emit();
  134. this.modal.deactivate();
  135. unlockBodyScrolling(this);
  136. await Promise.all([stopAnimations(this.drawer), stopAnimations(this.overlay)]);
  137. const panelAnimation = getAnimation(this, `drawer.hide${uppercaseFirstLetter(this.placement)}`);
  138. const overlayAnimation = getAnimation(this, "drawer.overlay.hide");
  139. await Promise.all([
  140. animateTo(this.panel, panelAnimation.keyframes, panelAnimation.options),
  141. animateTo(this.overlay, overlayAnimation.keyframes, overlayAnimation.options)
  142. ]);
  143. this.drawer.hidden = true;
  144. const trigger = this.originalTrigger;
  145. if (trigger && typeof trigger.focus === "function") {
  146. setTimeout(() => trigger.focus());
  147. }
  148. this.slAfterHide.emit();
  149. }
  150. }
  151. handleOverlayClick() {
  152. const slOverlayDismiss = this.slOverlayDismiss.emit({ cancelable: true });
  153. if (!slOverlayDismiss.defaultPrevented) {
  154. this.hide();
  155. }
  156. }
  157. handleSlotChange() {
  158. this.hasFooter = hasSlot(this, "footer");
  159. }
  160. render() {
  161. return T`
  162. <div
  163. part="base"
  164. class=${e2({
  165. drawer: true,
  166. "drawer--open": this.open,
  167. "drawer--top": this.placement === "top",
  168. "drawer--end": this.placement === "end",
  169. "drawer--bottom": this.placement === "bottom",
  170. "drawer--start": this.placement === "start",
  171. "drawer--contained": this.contained,
  172. "drawer--fixed": !this.contained,
  173. "drawer--has-footer": this.hasFooter
  174. })}
  175. @keydown=${this.handleKeyDown}
  176. >
  177. <div part="overlay" class="drawer__overlay" @click=${this.handleOverlayClick} tabindex="-1"></div>
  178. <div
  179. part="panel"
  180. class="drawer__panel"
  181. role="dialog"
  182. aria-modal="true"
  183. aria-hidden=${this.open ? "false" : "true"}
  184. aria-label=${l(this.noHeader ? this.label : void 0)}
  185. aria-labelledby=${l(!this.noHeader ? `${this.componentId}-title` : void 0)}
  186. tabindex="0"
  187. >
  188. ${!this.noHeader ? T`
  189. <header part="header" class="drawer__header">
  190. <span part="title" class="drawer__title" id=${`${this.componentId}-title`}>
  191. <!-- If there's no label, use an invisible character to prevent the heading from collapsing -->
  192. <slot name="label"> ${this.label || String.fromCharCode(65279)} </slot>
  193. </span>
  194. <sl-icon-button
  195. exportparts="base:close-button"
  196. class="drawer__close"
  197. name="x"
  198. library="system"
  199. @click=${this.handleCloseClick}
  200. ></sl-icon-button>
  201. </header>
  202. ` : ""}
  203. <div part="body" class="drawer__body">
  204. <slot></slot>
  205. </div>
  206. <footer part="footer" class="drawer__footer">
  207. <slot name="footer" @slotchange=${this.handleSlotChange}></slot>
  208. </footer>
  209. </div>
  210. </div>
  211. `;
  212. }
  213. };
  214. SlDrawer.styles = r(drawer_default);
  215. __decorateClass([
  216. o(".drawer")
  217. ], SlDrawer.prototype, "drawer", 2);
  218. __decorateClass([
  219. o(".drawer__panel")
  220. ], SlDrawer.prototype, "panel", 2);
  221. __decorateClass([
  222. o(".drawer__overlay")
  223. ], SlDrawer.prototype, "overlay", 2);
  224. __decorateClass([
  225. r2()
  226. ], SlDrawer.prototype, "hasFooter", 2);
  227. __decorateClass([
  228. e({ type: Boolean, reflect: true })
  229. ], SlDrawer.prototype, "open", 2);
  230. __decorateClass([
  231. e({ reflect: true })
  232. ], SlDrawer.prototype, "label", 2);
  233. __decorateClass([
  234. e({ reflect: true })
  235. ], SlDrawer.prototype, "placement", 2);
  236. __decorateClass([
  237. e({ type: Boolean, reflect: true })
  238. ], SlDrawer.prototype, "contained", 2);
  239. __decorateClass([
  240. e({ attribute: "no-header", type: Boolean, reflect: true })
  241. ], SlDrawer.prototype, "noHeader", 2);
  242. __decorateClass([
  243. event("sl-show")
  244. ], SlDrawer.prototype, "slShow", 2);
  245. __decorateClass([
  246. event("sl-after-show")
  247. ], SlDrawer.prototype, "slAfterShow", 2);
  248. __decorateClass([
  249. event("sl-hide")
  250. ], SlDrawer.prototype, "slHide", 2);
  251. __decorateClass([
  252. event("sl-after-hide")
  253. ], SlDrawer.prototype, "slAfterHide", 2);
  254. __decorateClass([
  255. event("sl-initial-focus")
  256. ], SlDrawer.prototype, "slInitialFocus", 2);
  257. __decorateClass([
  258. event("sl-overlay-dismiss")
  259. ], SlDrawer.prototype, "slOverlayDismiss", 2);
  260. __decorateClass([
  261. watch("open")
  262. ], SlDrawer.prototype, "handleOpenChange", 1);
  263. SlDrawer = __decorateClass([
  264. n("sl-drawer")
  265. ], SlDrawer);
  266. var drawer_default2 = SlDrawer;
  267. setDefaultAnimation("drawer.showTop", {
  268. keyframes: [
  269. { opacity: 0, transform: "translateY(-100%)" },
  270. { opacity: 1, transform: "translateY(0)" }
  271. ],
  272. options: { duration: 250, easing: "ease" }
  273. });
  274. setDefaultAnimation("drawer.hideTop", {
  275. keyframes: [
  276. { opacity: 1, transform: "translateY(0)" },
  277. { opacity: 0, transform: "translateY(-100%)" }
  278. ],
  279. options: { duration: 250, easing: "ease" }
  280. });
  281. setDefaultAnimation("drawer.showEnd", {
  282. keyframes: [
  283. { opacity: 0, transform: "translateX(100%)" },
  284. { opacity: 1, transform: "translateX(0)" }
  285. ],
  286. options: { duration: 250, easing: "ease" }
  287. });
  288. setDefaultAnimation("drawer.hideEnd", {
  289. keyframes: [
  290. { opacity: 1, transform: "translateX(0)" },
  291. { opacity: 0, transform: "translateX(100%)" }
  292. ],
  293. options: { duration: 250, easing: "ease" }
  294. });
  295. setDefaultAnimation("drawer.showBottom", {
  296. keyframes: [
  297. { opacity: 0, transform: "translateY(100%)" },
  298. { opacity: 1, transform: "translateY(0)" }
  299. ],
  300. options: { duration: 250, easing: "ease" }
  301. });
  302. setDefaultAnimation("drawer.hideBottom", {
  303. keyframes: [
  304. { opacity: 1, transform: "translateY(0)" },
  305. { opacity: 0, transform: "translateY(100%)" }
  306. ],
  307. options: { duration: 250, easing: "ease" }
  308. });
  309. setDefaultAnimation("drawer.showStart", {
  310. keyframes: [
  311. { opacity: 0, transform: "translateX(-100%)" },
  312. { opacity: 1, transform: "translateX(0)" }
  313. ],
  314. options: { duration: 250, easing: "ease" }
  315. });
  316. setDefaultAnimation("drawer.hideStart", {
  317. keyframes: [
  318. { opacity: 1, transform: "translateX(0)" },
  319. { opacity: 0, transform: "translateX(-100%)" }
  320. ],
  321. options: { duration: 250, easing: "ease" }
  322. });
  323. setDefaultAnimation("drawer.overlay.show", {
  324. keyframes: [{ opacity: 0 }, { opacity: 1 }],
  325. options: { duration: 250 }
  326. });
  327. setDefaultAnimation("drawer.overlay.hide", {
  328. keyframes: [{ opacity: 1 }, { opacity: 0 }],
  329. options: { duration: 250 }
  330. });
  331. export {
  332. drawer_default2 as drawer_default
  333. };