@yamada-ui/modal 1.2.0 → 1.2.1-dev-20240409072750

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,942 @@
1
+ "use client"
2
+
3
+ // src/drawer.tsx
4
+ import {
5
+ ui as ui6,
6
+ forwardRef as forwardRef8,
7
+ useMultiComponentStyle as useMultiComponentStyle3,
8
+ omitThemeProps as omitThemeProps3
9
+ } from "@yamada-ui/core";
10
+ import { Slide } from "@yamada-ui/transitions";
11
+ import { useValue as useValue2 } from "@yamada-ui/use-value";
12
+ import {
13
+ createContext as createContext3,
14
+ getValidChildren as getValidChildren3,
15
+ findChildren as findChildren3,
16
+ cx as cx8,
17
+ omitObject,
18
+ isArray
19
+ } from "@yamada-ui/utils";
20
+ import { useCallback as useCallback2, useMemo } from "react";
21
+
22
+ // src/modal.tsx
23
+ import {
24
+ ui as ui5,
25
+ forwardRef as forwardRef7,
26
+ omitThemeProps as omitThemeProps2,
27
+ useMultiComponentStyle as useMultiComponentStyle2
28
+ } from "@yamada-ui/core";
29
+ import { FocusLock } from "@yamada-ui/focus-lock";
30
+ import { AnimatePresence, Motion } from "@yamada-ui/motion";
31
+ import { Portal } from "@yamada-ui/portal";
32
+ import { scaleFadeProps, slideFadeProps } from "@yamada-ui/transitions";
33
+ import { useValue } from "@yamada-ui/use-value";
34
+ import {
35
+ cx as cx7,
36
+ createContext as createContext2,
37
+ getValidChildren as getValidChildren2,
38
+ findChildren as findChildren2
39
+ } from "@yamada-ui/utils";
40
+ import { cloneElement, useCallback } from "react";
41
+ import { RemoveScroll } from "react-remove-scroll";
42
+
43
+ // src/modal-overlay.tsx
44
+ import { ui, forwardRef } from "@yamada-ui/core";
45
+ import { motion } from "@yamada-ui/motion";
46
+ import { fadeProps } from "@yamada-ui/transitions";
47
+ import { cx, handlerAll } from "@yamada-ui/utils";
48
+ import { jsx } from "react/jsx-runtime";
49
+ var ModalOverlay = forwardRef(
50
+ ({ className, __css, onClick, ...rest }, ref) => {
51
+ const {
52
+ styles,
53
+ closeOnOverlay,
54
+ onOverlayClick,
55
+ onClose,
56
+ animation,
57
+ duration
58
+ } = useModal();
59
+ const css = {
60
+ position: "fixed",
61
+ top: 0,
62
+ left: 0,
63
+ w: "100vw",
64
+ h: "100vh",
65
+ ...__css ? __css : styles.overlay
66
+ };
67
+ const props = animation !== "none" ? fadeProps : {};
68
+ return /* @__PURE__ */ jsx(
69
+ ui.div,
70
+ {
71
+ as: motion.div,
72
+ ref,
73
+ className: cx("ui-modal__overlay", className),
74
+ custom: { duration },
75
+ __css: css,
76
+ onClick: handlerAll(onClick, onOverlayClick, (ev) => {
77
+ ev.stopPropagation();
78
+ if (closeOnOverlay)
79
+ onClose == null ? void 0 : onClose();
80
+ }),
81
+ ...props,
82
+ ...rest
83
+ }
84
+ );
85
+ }
86
+ );
87
+
88
+ // src/modal-close-button.tsx
89
+ import { CloseButton } from "@yamada-ui/close-button";
90
+ import { forwardRef as forwardRef2 } from "@yamada-ui/core";
91
+ import { cx as cx2, handlerAll as handlerAll2 } from "@yamada-ui/utils";
92
+ import { jsx as jsx2 } from "react/jsx-runtime";
93
+ var ModalCloseButton = forwardRef2(
94
+ ({ onClick, __css, ...rest }, ref) => {
95
+ const { styles, onClose } = useModal();
96
+ const css = {
97
+ position: "absolute",
98
+ ...__css ? __css : styles.closeButton
99
+ };
100
+ return /* @__PURE__ */ jsx2(
101
+ CloseButton,
102
+ {
103
+ ref,
104
+ className: cx2("ui-modal__close-button"),
105
+ __css: css,
106
+ onClick: handlerAll2(onClick, (ev) => {
107
+ ev.stopPropagation();
108
+ onClose == null ? void 0 : onClose();
109
+ }),
110
+ ...rest
111
+ }
112
+ );
113
+ }
114
+ );
115
+
116
+ // src/modal-header.tsx
117
+ import { ui as ui2, forwardRef as forwardRef3 } from "@yamada-ui/core";
118
+ import { cx as cx3 } from "@yamada-ui/utils";
119
+ import { jsx as jsx3 } from "react/jsx-runtime";
120
+ var ModalHeader = forwardRef3(
121
+ ({ className, __css, ...rest }, ref) => {
122
+ const { styles } = useModal();
123
+ const css = {
124
+ display: "flex",
125
+ alignItems: "center",
126
+ justifyContent: "flex-start",
127
+ ...__css ? __css : styles.header
128
+ };
129
+ return /* @__PURE__ */ jsx3(
130
+ ui2.header,
131
+ {
132
+ ref,
133
+ className: cx3("ui-modal__header", className),
134
+ __css: css,
135
+ ...rest
136
+ }
137
+ );
138
+ }
139
+ );
140
+
141
+ // src/modal-body.tsx
142
+ import { ui as ui3, forwardRef as forwardRef4 } from "@yamada-ui/core";
143
+ import { cx as cx4 } from "@yamada-ui/utils";
144
+ import { jsx as jsx4 } from "react/jsx-runtime";
145
+ var ModalBody = forwardRef4(
146
+ ({ className, __css, ...rest }, ref) => {
147
+ const { styles, scrollBehavior } = useModal();
148
+ const css = {
149
+ display: "flex",
150
+ flexDirection: "column",
151
+ alignItems: "flex-start",
152
+ overflow: scrollBehavior === "inside" ? "auto" : void 0,
153
+ ...__css ? __css : styles.body
154
+ };
155
+ return /* @__PURE__ */ jsx4(
156
+ ui3.main,
157
+ {
158
+ ref,
159
+ className: cx4("ui-modal__body", className),
160
+ __css: css,
161
+ ...rest
162
+ }
163
+ );
164
+ }
165
+ );
166
+
167
+ // src/modal-footer.tsx
168
+ import { ui as ui4, forwardRef as forwardRef5 } from "@yamada-ui/core";
169
+ import { cx as cx5 } from "@yamada-ui/utils";
170
+ import { jsx as jsx5 } from "react/jsx-runtime";
171
+ var ModalFooter = forwardRef5(
172
+ ({ className, __css, ...rest }, ref) => {
173
+ const { styles } = useModal();
174
+ const css = {
175
+ display: "flex",
176
+ alignItems: "center",
177
+ justifyContent: "flex-end",
178
+ ...__css ? __css : styles.footer
179
+ };
180
+ return /* @__PURE__ */ jsx5(
181
+ ui4.footer,
182
+ {
183
+ ref,
184
+ className: cx5("ui-modal__footer", className),
185
+ __css: css,
186
+ ...rest
187
+ }
188
+ );
189
+ }
190
+ );
191
+
192
+ // src/dialog.tsx
193
+ import { Button } from "@yamada-ui/button";
194
+ import {
195
+ forwardRef as forwardRef6,
196
+ useMultiComponentStyle,
197
+ omitThemeProps
198
+ } from "@yamada-ui/core";
199
+ import {
200
+ createContext,
201
+ getValidChildren,
202
+ findChildren,
203
+ omitChildren,
204
+ isValidElement,
205
+ isEmpty,
206
+ cx as cx6
207
+ } from "@yamada-ui/utils";
208
+ import { Fragment, jsx as jsx6, jsxs } from "react/jsx-runtime";
209
+ var [DialogProvider, useDialog] = createContext({
210
+ name: `DialogContext`,
211
+ errorMessage: `useDialog returned is 'undefined'. Seems you forgot to wrap the components in "<Dialog />" `
212
+ });
213
+ var Dialog = forwardRef6(
214
+ ({ size, ...props }, ref) => {
215
+ const [styles, mergedProps] = useMultiComponentStyle("Dialog", {
216
+ size,
217
+ ...props
218
+ });
219
+ const {
220
+ className,
221
+ children,
222
+ withOverlay = true,
223
+ withCloseButton = true,
224
+ header,
225
+ footer,
226
+ cancel,
227
+ other,
228
+ success,
229
+ onClose,
230
+ onCancel,
231
+ onOther,
232
+ onSuccess,
233
+ ...rest
234
+ } = omitThemeProps(mergedProps);
235
+ const validChildren = getValidChildren(children);
236
+ const [customDialogOverlay] = findChildren(validChildren, DialogOverlay);
237
+ const [customDialogCloseButton] = findChildren(
238
+ validChildren,
239
+ DialogCloseButton
240
+ );
241
+ const [customDialogHeader] = findChildren(validChildren, DialogHeader);
242
+ const [customDialogBody] = findChildren(validChildren, DialogBody);
243
+ const [customDialogFooter] = findChildren(validChildren, DialogFooter);
244
+ const cloneChildren = !isEmpty(validChildren) ? omitChildren(
245
+ validChildren,
246
+ DialogOverlay,
247
+ DialogCloseButton,
248
+ DialogHeader,
249
+ DialogBody,
250
+ DialogFooter
251
+ ) : children;
252
+ const css = { ...styles.container };
253
+ const cancelButtonProps = isValidElement(cancel) ? { children: cancel } : cancel;
254
+ const otherButtonProps = isValidElement(other) ? { children: other } : other;
255
+ const successButtonProps = isValidElement(success) ? { children: success } : success;
256
+ if (cancelButtonProps && !cancelButtonProps.variant)
257
+ cancelButtonProps.variant = "ghost";
258
+ if (otherButtonProps && !otherButtonProps.colorScheme)
259
+ otherButtonProps.colorScheme = "secondary";
260
+ if (successButtonProps && !successButtonProps.colorScheme)
261
+ successButtonProps.colorScheme = "primary";
262
+ return /* @__PURE__ */ jsx6(DialogProvider, { value: styles, children: /* @__PURE__ */ jsxs(
263
+ Modal,
264
+ {
265
+ ref,
266
+ className: cx6("ui-dialog", className),
267
+ __css: css,
268
+ ...{
269
+ size,
270
+ onClose,
271
+ withOverlay: false,
272
+ withCloseButton: false,
273
+ ...rest
274
+ },
275
+ children: [
276
+ customDialogOverlay != null ? customDialogOverlay : withOverlay && size !== "full" ? /* @__PURE__ */ jsx6(DialogOverlay, {}) : null,
277
+ customDialogCloseButton != null ? customDialogCloseButton : withCloseButton && onClose ? /* @__PURE__ */ jsx6(DialogCloseButton, {}) : null,
278
+ customDialogHeader != null ? customDialogHeader : header ? /* @__PURE__ */ jsx6(DialogHeader, { children: header }) : null,
279
+ customDialogBody != null ? customDialogBody : cloneChildren ? /* @__PURE__ */ jsx6(DialogBody, { children: cloneChildren }) : null,
280
+ customDialogFooter != null ? customDialogFooter : footer || cancelButtonProps || otherButtonProps || successButtonProps ? /* @__PURE__ */ jsx6(DialogFooter, { children: footer != null ? footer : /* @__PURE__ */ jsxs(Fragment, { children: [
281
+ cancelButtonProps ? /* @__PURE__ */ jsx6(
282
+ Button,
283
+ {
284
+ onClick: () => onCancel == null ? void 0 : onCancel(onClose),
285
+ ...cancelButtonProps
286
+ }
287
+ ) : null,
288
+ otherButtonProps ? /* @__PURE__ */ jsx6(
289
+ Button,
290
+ {
291
+ onClick: () => onOther == null ? void 0 : onOther(onClose),
292
+ ...otherButtonProps
293
+ }
294
+ ) : null,
295
+ successButtonProps ? /* @__PURE__ */ jsx6(
296
+ Button,
297
+ {
298
+ onClick: () => onSuccess == null ? void 0 : onSuccess(onClose),
299
+ ...successButtonProps
300
+ }
301
+ ) : null
302
+ ] }) }) : null
303
+ ]
304
+ }
305
+ ) });
306
+ }
307
+ );
308
+ var DialogOverlay = forwardRef6(
309
+ ({ className, ...rest }, ref) => {
310
+ const styles = useDialog();
311
+ const css = { ...styles.overlay };
312
+ return /* @__PURE__ */ jsx6(
313
+ ModalOverlay,
314
+ {
315
+ ref,
316
+ className: cx6("ui-dialog__overlay", className),
317
+ __css: css,
318
+ ...rest
319
+ }
320
+ );
321
+ }
322
+ );
323
+ var DialogCloseButton = forwardRef6(
324
+ ({ className, ...rest }, ref) => {
325
+ const styles = useDialog();
326
+ const css = { ...styles.closeButton };
327
+ return /* @__PURE__ */ jsx6(
328
+ ModalCloseButton,
329
+ {
330
+ ref,
331
+ className: cx6("ui-dialog__close-button", className),
332
+ __css: css,
333
+ ...rest
334
+ }
335
+ );
336
+ }
337
+ );
338
+ var DialogHeader = forwardRef6(
339
+ ({ className, ...rest }, ref) => {
340
+ const styles = useDialog();
341
+ const css = { ...styles.header };
342
+ return /* @__PURE__ */ jsx6(
343
+ ModalHeader,
344
+ {
345
+ ref,
346
+ className: cx6("ui-dialog__header", className),
347
+ __css: css,
348
+ ...rest
349
+ }
350
+ );
351
+ }
352
+ );
353
+ var DialogBody = forwardRef6(
354
+ ({ className, ...rest }, ref) => {
355
+ const styles = useDialog();
356
+ const css = { ...styles.body };
357
+ return /* @__PURE__ */ jsx6(
358
+ ModalBody,
359
+ {
360
+ ref,
361
+ className: cx6("ui-dialog__body", className),
362
+ __css: css,
363
+ ...rest
364
+ }
365
+ );
366
+ }
367
+ );
368
+ var DialogFooter = forwardRef6(
369
+ ({ className, ...rest }, ref) => {
370
+ const styles = useDialog();
371
+ const css = { ...styles.footer };
372
+ return /* @__PURE__ */ jsx6(
373
+ ModalFooter,
374
+ {
375
+ ref,
376
+ className: cx6("ui-dialog__footer", className),
377
+ __css: css,
378
+ ...rest
379
+ }
380
+ );
381
+ }
382
+ );
383
+
384
+ // src/modal.tsx
385
+ import { jsx as jsx7, jsxs as jsxs2 } from "react/jsx-runtime";
386
+ var [ModalProvider, useModal] = createContext2({
387
+ name: `ModalContext`,
388
+ errorMessage: `useModal returned is 'undefined'. Seems you forgot to wrap the components in "<Modal />" `
389
+ });
390
+ var Modal = forwardRef7(
391
+ ({ size, ...props }, ref) => {
392
+ const [styles, mergedProps] = useMultiComponentStyle2("Modal", {
393
+ size,
394
+ ...props
395
+ });
396
+ const {
397
+ className,
398
+ children,
399
+ isOpen,
400
+ onClose,
401
+ onOverlayClick,
402
+ onEsc,
403
+ onCloseComplete,
404
+ placement: _placement = "center",
405
+ outside = "fallback(4, 1rem)",
406
+ withCloseButton = true,
407
+ withOverlay = true,
408
+ allowPinchZoom = false,
409
+ scrollBehavior = "inside",
410
+ autoFocus,
411
+ restoreFocus,
412
+ initialFocusRef,
413
+ finalFocusRef,
414
+ blockScrollOnMount = true,
415
+ closeOnOverlay = true,
416
+ closeOnEsc = true,
417
+ lockFocusAcrossFrames = true,
418
+ animation = "scale",
419
+ duration,
420
+ portalProps,
421
+ ...rest
422
+ } = omitThemeProps2(mergedProps);
423
+ const onKeyDown = useCallback(
424
+ (ev) => {
425
+ if (ev.key !== "Escape")
426
+ return;
427
+ ev.stopPropagation();
428
+ if (closeOnEsc)
429
+ onClose == null ? void 0 : onClose();
430
+ onEsc == null ? void 0 : onEsc();
431
+ },
432
+ [closeOnEsc, onClose, onEsc]
433
+ );
434
+ const validChildren = getValidChildren2(children);
435
+ const [customModalOverlay, ...cloneChildren] = findChildren2(
436
+ validChildren,
437
+ ModalOverlay,
438
+ DialogOverlay,
439
+ DrawerOverlay
440
+ );
441
+ let [drawerContent] = findChildren2(validChildren, DrawerContent);
442
+ if (drawerContent)
443
+ drawerContent = cloneElement(drawerContent, { onKeyDown });
444
+ const placement = useValue(_placement);
445
+ const css = {
446
+ position: "fixed",
447
+ top: 0,
448
+ left: 0,
449
+ zIndex: "fallback(jeice, 110)",
450
+ w: "100vw",
451
+ h: "100dvh",
452
+ p: size !== "full" ? outside : void 0,
453
+ display: "flex",
454
+ justifyContent: placement.includes("left") ? "flex-start" : placement.includes("right") ? "flex-end" : "center",
455
+ alignItems: placement.includes("top") ? "flex-start" : placement.includes("bottom") ? "flex-end" : "center"
456
+ };
457
+ return /* @__PURE__ */ jsx7(
458
+ ModalProvider,
459
+ {
460
+ value: {
461
+ isOpen,
462
+ onClose,
463
+ onOverlayClick,
464
+ withCloseButton,
465
+ scrollBehavior,
466
+ closeOnOverlay,
467
+ animation,
468
+ duration,
469
+ styles
470
+ },
471
+ children: /* @__PURE__ */ jsx7(AnimatePresence, { onExitComplete: onCloseComplete, children: isOpen ? /* @__PURE__ */ jsx7(Portal, { ...portalProps, children: /* @__PURE__ */ jsx7(
472
+ FocusLock,
473
+ {
474
+ autoFocus,
475
+ initialFocusRef,
476
+ finalFocusRef,
477
+ restoreFocus,
478
+ lockFocusAcrossFrames,
479
+ children: /* @__PURE__ */ jsx7(
480
+ RemoveScroll,
481
+ {
482
+ allowPinchZoom,
483
+ enabled: blockScrollOnMount,
484
+ forwardProps: true,
485
+ children: /* @__PURE__ */ jsxs2(ui5.div, { __css: css, children: [
486
+ customModalOverlay != null ? customModalOverlay : withOverlay && size !== "full" ? /* @__PURE__ */ jsx7(ModalOverlay, {}) : null,
487
+ drawerContent != null ? drawerContent : /* @__PURE__ */ jsx7(
488
+ ModalContent,
489
+ {
490
+ ref,
491
+ className,
492
+ onKeyDown,
493
+ ...rest,
494
+ children: cloneChildren
495
+ }
496
+ )
497
+ ] })
498
+ }
499
+ )
500
+ }
501
+ ) }) : null })
502
+ }
503
+ );
504
+ }
505
+ );
506
+ var getModalContentProps = (animation = "scale", duration) => {
507
+ switch (animation) {
508
+ case "scale":
509
+ return {
510
+ ...scaleFadeProps,
511
+ custom: { scale: 0.95, reverse: true, duration }
512
+ };
513
+ case "top":
514
+ return {
515
+ ...slideFadeProps,
516
+ custom: { offsetY: -16, reverse: true, duration }
517
+ };
518
+ case "right":
519
+ return {
520
+ ...slideFadeProps,
521
+ custom: { offsetX: 16, reverse: true, duration }
522
+ };
523
+ case "left":
524
+ return {
525
+ ...slideFadeProps,
526
+ custom: { offsetX: -16, reverse: true, duration }
527
+ };
528
+ case "bottom":
529
+ return {
530
+ ...slideFadeProps,
531
+ custom: { offsetY: 16, reverse: true, duration }
532
+ };
533
+ }
534
+ };
535
+ var ModalContent = forwardRef7(
536
+ ({ className, children, __css, ...rest }, ref) => {
537
+ const {
538
+ styles,
539
+ scrollBehavior,
540
+ withCloseButton,
541
+ onClose,
542
+ animation,
543
+ duration
544
+ } = useModal();
545
+ const validChildren = getValidChildren2(children);
546
+ const [customModalCloseButton, ...cloneChildren] = findChildren2(
547
+ validChildren,
548
+ ModalCloseButton,
549
+ DialogCloseButton
550
+ );
551
+ const props = animation !== "none" ? getModalContentProps(animation, duration) : {};
552
+ const css = {
553
+ position: "relative",
554
+ maxH: "100%",
555
+ display: "flex",
556
+ flexDirection: "column",
557
+ overflow: scrollBehavior === "inside" ? "hidden" : "auto",
558
+ outline: 0,
559
+ ...__css ? __css : styles.container
560
+ };
561
+ return /* @__PURE__ */ jsxs2(
562
+ Motion,
563
+ {
564
+ as: "section",
565
+ ref,
566
+ className: cx7("ui-modal", className),
567
+ tabIndex: -1,
568
+ __css: css,
569
+ ...props,
570
+ ...rest,
571
+ children: [
572
+ customModalCloseButton != null ? customModalCloseButton : withCloseButton && onClose ? /* @__PURE__ */ jsx7(ModalCloseButton, {}) : null,
573
+ cloneChildren
574
+ ]
575
+ }
576
+ );
577
+ }
578
+ );
579
+
580
+ // src/drawer.tsx
581
+ import { jsx as jsx8, jsxs as jsxs3 } from "react/jsx-runtime";
582
+ var [DrawerProvider, useDrawer] = createContext3({
583
+ name: `DrawerContext`,
584
+ errorMessage: `useDrawer returned is 'undefined'. Seems you forgot to wrap the components in "<Drawer />" `
585
+ });
586
+ var Drawer = forwardRef8(
587
+ ({ size, placement = "right", closeOnDrag = false, ...props }, ref) => {
588
+ const [styles, mergedProps] = useMultiComponentStyle3("Drawer", {
589
+ size,
590
+ placement,
591
+ closeOnDrag,
592
+ ...props
593
+ });
594
+ const {
595
+ children,
596
+ isOpen,
597
+ onClose,
598
+ onOverlayClick,
599
+ onEsc,
600
+ onCloseComplete,
601
+ withCloseButton = !closeOnDrag,
602
+ withOverlay = true,
603
+ withDragBar = true,
604
+ allowPinchZoom,
605
+ autoFocus,
606
+ restoreFocus,
607
+ initialFocusRef,
608
+ finalFocusRef,
609
+ blockScrollOnMount,
610
+ closeOnOverlay,
611
+ closeOnEsc,
612
+ lockFocusAcrossFrames,
613
+ duration = { enter: 0.4, exit: 0.3 },
614
+ dragConstraints = 0,
615
+ dragElastic = 0.1,
616
+ dragOffset = 80,
617
+ dragVelocity = 100,
618
+ blankForDragProps,
619
+ portalProps,
620
+ ...rest
621
+ } = omitThemeProps3(mergedProps);
622
+ const validChildren = getValidChildren3(children);
623
+ const [customDrawerOverlay, ...cloneChildren] = findChildren3(
624
+ validChildren,
625
+ DrawerOverlay
626
+ );
627
+ return /* @__PURE__ */ jsx8(DrawerProvider, { value: styles, children: /* @__PURE__ */ jsxs3(
628
+ Modal,
629
+ {
630
+ ref,
631
+ ...{
632
+ isOpen,
633
+ onClose,
634
+ onOverlayClick,
635
+ onEsc,
636
+ onCloseComplete,
637
+ withCloseButton: false,
638
+ withOverlay: false,
639
+ allowPinchZoom,
640
+ autoFocus,
641
+ restoreFocus,
642
+ initialFocusRef,
643
+ finalFocusRef,
644
+ blockScrollOnMount,
645
+ closeOnOverlay,
646
+ closeOnEsc,
647
+ lockFocusAcrossFrames,
648
+ duration,
649
+ portalProps
650
+ },
651
+ children: [
652
+ customDrawerOverlay != null ? customDrawerOverlay : withOverlay ? /* @__PURE__ */ jsx8(DrawerOverlay, {}) : null,
653
+ /* @__PURE__ */ jsx8(
654
+ DrawerContent,
655
+ {
656
+ ...{
657
+ dragConstraints,
658
+ dragElastic,
659
+ dragOffset,
660
+ dragVelocity,
661
+ withCloseButton,
662
+ withDragBar,
663
+ blankForDragProps,
664
+ ...omitObject(rest, ["isFullHeight"]),
665
+ placement,
666
+ closeOnDrag
667
+ },
668
+ children: cloneChildren
669
+ }
670
+ )
671
+ ]
672
+ }
673
+ ) });
674
+ }
675
+ );
676
+ var DrawerContent = forwardRef8(
677
+ ({
678
+ className,
679
+ children,
680
+ placement: _placement,
681
+ withCloseButton,
682
+ withDragBar,
683
+ closeOnDrag,
684
+ dragConstraints,
685
+ dragElastic,
686
+ dragOffset,
687
+ dragVelocity,
688
+ blankForDragProps,
689
+ ...rest
690
+ }, ref) => {
691
+ const { isOpen, onClose, duration } = useModal();
692
+ const styles = useDrawer();
693
+ const placement = useValue2(_placement);
694
+ const validChildren = getValidChildren3(children);
695
+ const [customDrawerCloseButton, ...cloneChildren] = findChildren3(
696
+ validChildren,
697
+ DrawerCloseButton
698
+ );
699
+ const blankForDragBg = useMemo(() => {
700
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
701
+ const propBg = (_c = (_b = (_a = rest.backgroundColor) != null ? _a : rest.bgColor) != null ? _b : rest.background) != null ? _c : rest.bg;
702
+ const styleBg = (_j = (_h = (_f = (_d = styles.container) == null ? void 0 : _d.backgroundColor) != null ? _f : (_e = styles.container) == null ? void 0 : _e.bgColor) != null ? _h : (_g = styles.container) == null ? void 0 : _g.background) != null ? _j : (_i = styles.container) == null ? void 0 : _i.bg;
703
+ const computedBg = propBg != null ? propBg : styleBg;
704
+ return isArray(computedBg) ? computedBg : [computedBg];
705
+ }, [rest, styles]);
706
+ const blankForDrag = useMemo(() => {
707
+ let position = {};
708
+ switch (placement) {
709
+ case "top":
710
+ position = { top: "calc(-100dvh + 1px)", left: 0, right: 0 };
711
+ break;
712
+ case "bottom":
713
+ position = { bottom: "calc(-100dvh + 1px)", left: 0, right: 0 };
714
+ break;
715
+ case "left":
716
+ position = { left: "calc(-100% + 1px)", top: 0, bottom: 0 };
717
+ break;
718
+ case "right":
719
+ position = { right: "calc(-100% + 1px)", top: 0, bottom: 0 };
720
+ break;
721
+ }
722
+ const [lightBg, darkBg] = blankForDragBg;
723
+ return {
724
+ _after: {
725
+ content: '""',
726
+ display: "block",
727
+ w: "100%",
728
+ h: "100dvh",
729
+ bg: lightBg,
730
+ position: "absolute",
731
+ ...position,
732
+ ...blankForDragProps
733
+ },
734
+ _dark: {
735
+ _after: {
736
+ bg: darkBg
737
+ }
738
+ }
739
+ };
740
+ }, [placement, blankForDragBg, blankForDragProps]);
741
+ const css = useMemo(
742
+ () => ({
743
+ display: "flex",
744
+ flexDirection: placement === "top" || placement === "bottom" ? "column" : "row",
745
+ outline: 0,
746
+ ...closeOnDrag ? blankForDrag : {},
747
+ ...styles.container
748
+ }),
749
+ [blankForDrag, closeOnDrag, placement, styles]
750
+ );
751
+ const getDragDirectionRestriction = useCallback2(
752
+ (value) => {
753
+ switch (placement) {
754
+ case "top":
755
+ return { bottom: value };
756
+ case "bottom":
757
+ return { top: value };
758
+ case "left":
759
+ return { right: value };
760
+ case "right":
761
+ return { left: value };
762
+ }
763
+ },
764
+ [placement]
765
+ );
766
+ const getDragDirection = useCallback2(() => {
767
+ switch (placement) {
768
+ case "top":
769
+ case "bottom":
770
+ return "y";
771
+ case "left":
772
+ case "right":
773
+ return "x";
774
+ }
775
+ }, [placement]);
776
+ const isCloseByDragInfo = useCallback2(
777
+ (info) => {
778
+ switch (placement) {
779
+ case "top":
780
+ return info.velocity.y <= dragVelocity * -1 || info.offset.y <= dragOffset * -1;
781
+ case "bottom":
782
+ return info.velocity.y >= dragVelocity || info.offset.y >= dragOffset;
783
+ case "left":
784
+ return info.velocity.x <= dragVelocity * -1 || info.offset.x <= dragOffset * -1;
785
+ case "right":
786
+ return info.velocity.x >= dragVelocity || info.offset.x >= dragOffset;
787
+ }
788
+ },
789
+ [placement, dragVelocity, dragOffset]
790
+ );
791
+ return /* @__PURE__ */ jsxs3(
792
+ Slide,
793
+ {
794
+ ref,
795
+ className: cx8("ui-drawer", className),
796
+ isOpen,
797
+ placement,
798
+ duration,
799
+ drag: closeOnDrag ? getDragDirection() : false,
800
+ dragConstraints: getDragDirectionRestriction(dragConstraints),
801
+ dragElastic: getDragDirectionRestriction(dragElastic),
802
+ dragSnapToOrigin: true,
803
+ dragMomentum: false,
804
+ onDragEnd: (_, info) => {
805
+ if (isCloseByDragInfo(info))
806
+ onClose == null ? void 0 : onClose();
807
+ },
808
+ tabIndex: -1,
809
+ __css: css,
810
+ ...rest,
811
+ children: [
812
+ customDrawerCloseButton != null ? customDrawerCloseButton : withCloseButton && onClose ? /* @__PURE__ */ jsx8(DrawerCloseButton, {}) : null,
813
+ withDragBar && closeOnDrag && (placement === "bottom" || placement === "right") ? /* @__PURE__ */ jsx8(DrawerDragBar, {}) : null,
814
+ /* @__PURE__ */ jsx8(
815
+ ui6.div,
816
+ {
817
+ className: "ui-drawer__inner",
818
+ __css: { display: "flex", flexDirection: "column", ...styles.inner },
819
+ children: cloneChildren
820
+ }
821
+ ),
822
+ withDragBar && closeOnDrag && (placement === "top" || placement === "left") ? /* @__PURE__ */ jsx8(DrawerDragBar, {}) : null
823
+ ]
824
+ }
825
+ );
826
+ }
827
+ );
828
+ var DrawerOverlay = forwardRef8(
829
+ ({ className, ...rest }, ref) => {
830
+ const styles = useDrawer();
831
+ const css = { ...styles.overlay };
832
+ return /* @__PURE__ */ jsx8(
833
+ ModalOverlay,
834
+ {
835
+ ref,
836
+ className: cx8("ui-drawer__overlay", className),
837
+ __css: css,
838
+ ...rest
839
+ }
840
+ );
841
+ }
842
+ );
843
+ var DrawerDragBar = ({
844
+ className,
845
+ ...rest
846
+ }) => {
847
+ const styles = useDrawer();
848
+ const css = { ...styles.dragBar };
849
+ return /* @__PURE__ */ jsx8(
850
+ ui6.div,
851
+ {
852
+ className: cx8("ui-drawer__drag-bar", className),
853
+ __css: css,
854
+ ...rest
855
+ }
856
+ );
857
+ };
858
+ var DrawerCloseButton = forwardRef8(
859
+ ({ className, ...rest }, ref) => {
860
+ const styles = useDrawer();
861
+ const css = { ...styles.closeButton };
862
+ return /* @__PURE__ */ jsx8(
863
+ ModalCloseButton,
864
+ {
865
+ ref,
866
+ className: cx8("ui-drawer__close-button", className),
867
+ __css: css,
868
+ ...rest
869
+ }
870
+ );
871
+ }
872
+ );
873
+ var DrawerHeader = forwardRef8(
874
+ ({ className, ...rest }, ref) => {
875
+ const styles = useDrawer();
876
+ const css = { ...styles.header };
877
+ return /* @__PURE__ */ jsx8(
878
+ ModalHeader,
879
+ {
880
+ ref,
881
+ className: cx8("ui-drawer__header", className),
882
+ __css: css,
883
+ ...rest
884
+ }
885
+ );
886
+ }
887
+ );
888
+ var DrawerBody = forwardRef8(
889
+ ({ className, ...rest }, ref) => {
890
+ const styles = useDrawer();
891
+ const css = { ...styles.body };
892
+ return /* @__PURE__ */ jsx8(
893
+ ModalBody,
894
+ {
895
+ ref,
896
+ className: cx8("ui-drawer__body", className),
897
+ __css: css,
898
+ ...rest
899
+ }
900
+ );
901
+ }
902
+ );
903
+ var DrawerFooter = forwardRef8(
904
+ ({ className, ...rest }, ref) => {
905
+ const styles = useDrawer();
906
+ const css = { ...styles.footer };
907
+ return /* @__PURE__ */ jsx8(
908
+ ModalFooter,
909
+ {
910
+ ref,
911
+ className: cx8("ui-drawer__footer", className),
912
+ __css: css,
913
+ ...rest
914
+ }
915
+ );
916
+ }
917
+ );
918
+
919
+ export {
920
+ Drawer,
921
+ DrawerContent,
922
+ DrawerOverlay,
923
+ DrawerDragBar,
924
+ DrawerCloseButton,
925
+ DrawerHeader,
926
+ DrawerBody,
927
+ DrawerFooter,
928
+ useModal,
929
+ Modal,
930
+ ModalOverlay,
931
+ ModalCloseButton,
932
+ ModalHeader,
933
+ ModalBody,
934
+ ModalFooter,
935
+ Dialog,
936
+ DialogOverlay,
937
+ DialogCloseButton,
938
+ DialogHeader,
939
+ DialogBody,
940
+ DialogFooter
941
+ };
942
+ //# sourceMappingURL=chunk-74PDTFI6.mjs.map