@yamada-ui/modal 0.2.7 → 0.2.9
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.
- package/dist/chunk-VHMYEQE4.mjs +777 -0
- package/dist/dialog.js +382 -238
- package/dist/dialog.mjs +1 -1
- package/dist/drawer.js +382 -238
- package/dist/drawer.mjs +1 -1
- package/dist/index.js +382 -238
- package/dist/index.mjs +1 -1
- package/dist/modal-body.js +382 -238
- package/dist/modal-body.mjs +1 -1
- package/dist/modal-close-button.js +382 -238
- package/dist/modal-close-button.mjs +1 -1
- package/dist/modal-footer.js +382 -238
- package/dist/modal-footer.mjs +1 -1
- package/dist/modal-header.js +382 -238
- package/dist/modal-header.mjs +1 -1
- package/dist/modal-overlay.js +382 -238
- package/dist/modal-overlay.mjs +1 -1
- package/dist/modal.js +382 -238
- package/dist/modal.mjs +1 -1
- package/package.json +10 -10
- package/dist/chunk-OUW3Q5QN.mjs +0 -623
|
@@ -0,0 +1,777 @@
|
|
|
1
|
+
// src/drawer.tsx
|
|
2
|
+
import {
|
|
3
|
+
forwardRef as forwardRef8,
|
|
4
|
+
useMultiComponentStyle as useMultiComponentStyle3,
|
|
5
|
+
omitThemeProps as omitThemeProps3
|
|
6
|
+
} from "@yamada-ui/core";
|
|
7
|
+
import { Slide } from "@yamada-ui/transitions";
|
|
8
|
+
import {
|
|
9
|
+
createContext as createContext3,
|
|
10
|
+
getValidChildren as getValidChildren3,
|
|
11
|
+
findChildren as findChildren3,
|
|
12
|
+
cx as cx8
|
|
13
|
+
} from "@yamada-ui/utils";
|
|
14
|
+
|
|
15
|
+
// src/modal.tsx
|
|
16
|
+
import {
|
|
17
|
+
ui as ui5,
|
|
18
|
+
forwardRef as forwardRef7,
|
|
19
|
+
omitThemeProps as omitThemeProps2,
|
|
20
|
+
useMultiComponentStyle as useMultiComponentStyle2
|
|
21
|
+
} from "@yamada-ui/core";
|
|
22
|
+
import { FocusLock } from "@yamada-ui/focus-lock";
|
|
23
|
+
import {
|
|
24
|
+
motion as motion2,
|
|
25
|
+
AnimatePresence
|
|
26
|
+
} from "@yamada-ui/motion";
|
|
27
|
+
import { Portal } from "@yamada-ui/portal";
|
|
28
|
+
import { scaleFadeProps, slideFadeProps } from "@yamada-ui/transitions";
|
|
29
|
+
import { useValue } from "@yamada-ui/use-value";
|
|
30
|
+
import {
|
|
31
|
+
cx as cx7,
|
|
32
|
+
createContext as createContext2,
|
|
33
|
+
getValidChildren as getValidChildren2,
|
|
34
|
+
findChildren as findChildren2
|
|
35
|
+
} from "@yamada-ui/utils";
|
|
36
|
+
import { cloneElement, useCallback } from "react";
|
|
37
|
+
import { RemoveScroll } from "react-remove-scroll";
|
|
38
|
+
|
|
39
|
+
// src/modal-overlay.tsx
|
|
40
|
+
import { ui, forwardRef } from "@yamada-ui/core";
|
|
41
|
+
import { motion } from "@yamada-ui/motion";
|
|
42
|
+
import { fadeProps } from "@yamada-ui/transitions";
|
|
43
|
+
import { cx, handlerAll } from "@yamada-ui/utils";
|
|
44
|
+
import { jsx } from "react/jsx-runtime";
|
|
45
|
+
var ModalOverlay = forwardRef(
|
|
46
|
+
({ className, __css, onClick, ...rest }, ref) => {
|
|
47
|
+
const {
|
|
48
|
+
styles,
|
|
49
|
+
closeOnOverlay,
|
|
50
|
+
onOverlayClick,
|
|
51
|
+
onClose,
|
|
52
|
+
animation,
|
|
53
|
+
duration
|
|
54
|
+
} = useModal();
|
|
55
|
+
const css = {
|
|
56
|
+
position: "fixed",
|
|
57
|
+
top: 0,
|
|
58
|
+
left: 0,
|
|
59
|
+
w: "100vw",
|
|
60
|
+
h: "100vh",
|
|
61
|
+
...__css ? __css : styles.overlay
|
|
62
|
+
};
|
|
63
|
+
const props = animation !== "none" ? fadeProps : {};
|
|
64
|
+
return /* @__PURE__ */ jsx(
|
|
65
|
+
ui.div,
|
|
66
|
+
{
|
|
67
|
+
as: motion.div,
|
|
68
|
+
ref,
|
|
69
|
+
className: cx("ui-modal-overlay", className),
|
|
70
|
+
custom: { duration },
|
|
71
|
+
__css: css,
|
|
72
|
+
onClick: handlerAll(onClick, onOverlayClick, (event) => {
|
|
73
|
+
event.stopPropagation();
|
|
74
|
+
if (closeOnOverlay)
|
|
75
|
+
onClose == null ? void 0 : onClose();
|
|
76
|
+
}),
|
|
77
|
+
...props,
|
|
78
|
+
...rest
|
|
79
|
+
}
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
// src/modal-close-button.tsx
|
|
85
|
+
import { CloseButton } from "@yamada-ui/close-button";
|
|
86
|
+
import { forwardRef as forwardRef2 } from "@yamada-ui/core";
|
|
87
|
+
import { cx as cx2, handlerAll as handlerAll2 } from "@yamada-ui/utils";
|
|
88
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
89
|
+
var ModalCloseButton = forwardRef2(
|
|
90
|
+
({ onClick, __css, ...rest }, ref) => {
|
|
91
|
+
const { styles, onClose } = useModal();
|
|
92
|
+
const css = {
|
|
93
|
+
position: "absolute",
|
|
94
|
+
...__css ? __css : styles.closeButton
|
|
95
|
+
};
|
|
96
|
+
return /* @__PURE__ */ jsx2(
|
|
97
|
+
CloseButton,
|
|
98
|
+
{
|
|
99
|
+
ref,
|
|
100
|
+
className: cx2("ui-modal-close-button"),
|
|
101
|
+
__css: css,
|
|
102
|
+
onClick: handlerAll2(onClick, (event) => {
|
|
103
|
+
event.stopPropagation();
|
|
104
|
+
onClose == null ? void 0 : onClose();
|
|
105
|
+
}),
|
|
106
|
+
...rest
|
|
107
|
+
}
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
// src/modal-header.tsx
|
|
113
|
+
import { ui as ui2, forwardRef as forwardRef3 } from "@yamada-ui/core";
|
|
114
|
+
import { cx as cx3 } from "@yamada-ui/utils";
|
|
115
|
+
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
116
|
+
var ModalHeader = forwardRef3(
|
|
117
|
+
({ className, __css, ...rest }, ref) => {
|
|
118
|
+
const { styles } = useModal();
|
|
119
|
+
const css = {
|
|
120
|
+
display: "flex",
|
|
121
|
+
alignItems: "center",
|
|
122
|
+
justifyContent: "flex-start",
|
|
123
|
+
...__css ? __css : styles.header
|
|
124
|
+
};
|
|
125
|
+
return /* @__PURE__ */ jsx3(
|
|
126
|
+
ui2.header,
|
|
127
|
+
{
|
|
128
|
+
ref,
|
|
129
|
+
className: cx3("ui-modal-header", className),
|
|
130
|
+
__css: css,
|
|
131
|
+
...rest
|
|
132
|
+
}
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
// src/modal-body.tsx
|
|
138
|
+
import { ui as ui3, forwardRef as forwardRef4 } from "@yamada-ui/core";
|
|
139
|
+
import { cx as cx4 } from "@yamada-ui/utils";
|
|
140
|
+
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
141
|
+
var ModalBody = forwardRef4(
|
|
142
|
+
({ className, __css, ...rest }, ref) => {
|
|
143
|
+
const { styles, scrollBehavior } = useModal();
|
|
144
|
+
const css = {
|
|
145
|
+
display: "flex",
|
|
146
|
+
flexDirection: "column",
|
|
147
|
+
alignItems: "flex-start",
|
|
148
|
+
overflow: scrollBehavior === "inside" ? "auto" : void 0,
|
|
149
|
+
...__css ? __css : styles.body
|
|
150
|
+
};
|
|
151
|
+
return /* @__PURE__ */ jsx4(
|
|
152
|
+
ui3.main,
|
|
153
|
+
{
|
|
154
|
+
ref,
|
|
155
|
+
className: cx4("ui-modal-body", className),
|
|
156
|
+
__css: css,
|
|
157
|
+
...rest
|
|
158
|
+
}
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
);
|
|
162
|
+
|
|
163
|
+
// src/modal-footer.tsx
|
|
164
|
+
import { ui as ui4, forwardRef as forwardRef5 } from "@yamada-ui/core";
|
|
165
|
+
import { cx as cx5 } from "@yamada-ui/utils";
|
|
166
|
+
import { jsx as jsx5 } from "react/jsx-runtime";
|
|
167
|
+
var ModalFooter = forwardRef5(
|
|
168
|
+
({ className, __css, ...rest }, ref) => {
|
|
169
|
+
const { styles } = useModal();
|
|
170
|
+
const css = {
|
|
171
|
+
display: "flex",
|
|
172
|
+
alignItems: "center",
|
|
173
|
+
justifyContent: "flex-end",
|
|
174
|
+
...__css ? __css : styles.footer
|
|
175
|
+
};
|
|
176
|
+
return /* @__PURE__ */ jsx5(
|
|
177
|
+
ui4.footer,
|
|
178
|
+
{
|
|
179
|
+
ref,
|
|
180
|
+
className: cx5("ui-modal-footer", className),
|
|
181
|
+
__css: css,
|
|
182
|
+
...rest
|
|
183
|
+
}
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
);
|
|
187
|
+
|
|
188
|
+
// src/dialog.tsx
|
|
189
|
+
import { Button } from "@yamada-ui/button";
|
|
190
|
+
import {
|
|
191
|
+
forwardRef as forwardRef6,
|
|
192
|
+
useMultiComponentStyle,
|
|
193
|
+
omitThemeProps
|
|
194
|
+
} from "@yamada-ui/core";
|
|
195
|
+
import {
|
|
196
|
+
createContext,
|
|
197
|
+
getValidChildren,
|
|
198
|
+
findChildren,
|
|
199
|
+
omitChildren,
|
|
200
|
+
isValidElement,
|
|
201
|
+
isEmpty,
|
|
202
|
+
cx as cx6
|
|
203
|
+
} from "@yamada-ui/utils";
|
|
204
|
+
import { Fragment, jsx as jsx6, jsxs } from "react/jsx-runtime";
|
|
205
|
+
var [DialogProvider, useDialog] = createContext({
|
|
206
|
+
name: `DialogContext`,
|
|
207
|
+
errorMessage: `useDialog returned is 'undefined'. Seems you forgot to wrap the components in "<Dialog />" `
|
|
208
|
+
});
|
|
209
|
+
var Dialog = forwardRef6(
|
|
210
|
+
({ size, ...props }, ref) => {
|
|
211
|
+
const [styles, mergedProps] = useMultiComponentStyle("Dialog", {
|
|
212
|
+
size,
|
|
213
|
+
...props
|
|
214
|
+
});
|
|
215
|
+
const {
|
|
216
|
+
className,
|
|
217
|
+
children,
|
|
218
|
+
withOverlay = true,
|
|
219
|
+
withCloseButton = true,
|
|
220
|
+
header,
|
|
221
|
+
footer,
|
|
222
|
+
cancel,
|
|
223
|
+
other,
|
|
224
|
+
success,
|
|
225
|
+
onClose,
|
|
226
|
+
onCancel,
|
|
227
|
+
onOther,
|
|
228
|
+
onSuccess,
|
|
229
|
+
...rest
|
|
230
|
+
} = omitThemeProps(mergedProps);
|
|
231
|
+
const validChildren = getValidChildren(children);
|
|
232
|
+
const [customDialogOverlay] = findChildren(validChildren, DialogOverlay);
|
|
233
|
+
const [customDialogCloseButton] = findChildren(
|
|
234
|
+
validChildren,
|
|
235
|
+
DialogCloseButton
|
|
236
|
+
);
|
|
237
|
+
const [customDialogHeader] = findChildren(validChildren, DialogHeader);
|
|
238
|
+
const [customDialogBody] = findChildren(validChildren, DialogBody);
|
|
239
|
+
const [customDialogFooter] = findChildren(validChildren, DialogFooter);
|
|
240
|
+
const cloneChildren = !isEmpty(validChildren) ? omitChildren(
|
|
241
|
+
validChildren,
|
|
242
|
+
DialogOverlay,
|
|
243
|
+
DialogCloseButton,
|
|
244
|
+
DialogHeader,
|
|
245
|
+
DialogBody,
|
|
246
|
+
DialogFooter
|
|
247
|
+
) : children;
|
|
248
|
+
const css = { ...styles.container };
|
|
249
|
+
const cancelButtonProps = isValidElement(cancel) ? { children: cancel } : cancel;
|
|
250
|
+
const otherButtonProps = isValidElement(other) ? { children: other } : other;
|
|
251
|
+
const successButtonProps = isValidElement(success) ? { children: success } : success;
|
|
252
|
+
if (cancelButtonProps && !cancelButtonProps.variant)
|
|
253
|
+
cancelButtonProps.variant = "ghost";
|
|
254
|
+
if (otherButtonProps && !otherButtonProps.colorScheme)
|
|
255
|
+
otherButtonProps.colorScheme = "secondary";
|
|
256
|
+
if (successButtonProps && !successButtonProps.colorScheme)
|
|
257
|
+
successButtonProps.colorScheme = "primary";
|
|
258
|
+
return /* @__PURE__ */ jsx6(DialogProvider, { value: styles, children: /* @__PURE__ */ jsxs(
|
|
259
|
+
Modal,
|
|
260
|
+
{
|
|
261
|
+
ref,
|
|
262
|
+
className: cx6("ui-dialog", className),
|
|
263
|
+
__css: css,
|
|
264
|
+
...{
|
|
265
|
+
size,
|
|
266
|
+
onClose,
|
|
267
|
+
withOverlay: false,
|
|
268
|
+
withCloseButton: false,
|
|
269
|
+
...rest
|
|
270
|
+
},
|
|
271
|
+
children: [
|
|
272
|
+
customDialogOverlay != null ? customDialogOverlay : withOverlay && size !== "full" ? /* @__PURE__ */ jsx6(DialogOverlay, {}) : null,
|
|
273
|
+
customDialogCloseButton != null ? customDialogCloseButton : withCloseButton && onClose ? /* @__PURE__ */ jsx6(DialogCloseButton, {}) : null,
|
|
274
|
+
customDialogHeader != null ? customDialogHeader : header ? /* @__PURE__ */ jsx6(DialogHeader, { children: header }) : null,
|
|
275
|
+
customDialogBody != null ? customDialogBody : cloneChildren ? /* @__PURE__ */ jsx6(DialogBody, { children: cloneChildren }) : null,
|
|
276
|
+
customDialogFooter != null ? customDialogFooter : footer || cancelButtonProps || otherButtonProps || successButtonProps ? /* @__PURE__ */ jsx6(DialogFooter, { children: footer != null ? footer : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
277
|
+
cancelButtonProps ? /* @__PURE__ */ jsx6(
|
|
278
|
+
Button,
|
|
279
|
+
{
|
|
280
|
+
onClick: () => onCancel == null ? void 0 : onCancel(onClose),
|
|
281
|
+
...cancelButtonProps
|
|
282
|
+
}
|
|
283
|
+
) : null,
|
|
284
|
+
otherButtonProps ? /* @__PURE__ */ jsx6(
|
|
285
|
+
Button,
|
|
286
|
+
{
|
|
287
|
+
onClick: () => onOther == null ? void 0 : onOther(onClose),
|
|
288
|
+
...otherButtonProps
|
|
289
|
+
}
|
|
290
|
+
) : null,
|
|
291
|
+
successButtonProps ? /* @__PURE__ */ jsx6(
|
|
292
|
+
Button,
|
|
293
|
+
{
|
|
294
|
+
onClick: () => onSuccess == null ? void 0 : onSuccess(onClose),
|
|
295
|
+
...successButtonProps
|
|
296
|
+
}
|
|
297
|
+
) : null
|
|
298
|
+
] }) }) : null
|
|
299
|
+
]
|
|
300
|
+
}
|
|
301
|
+
) });
|
|
302
|
+
}
|
|
303
|
+
);
|
|
304
|
+
var DialogOverlay = forwardRef6(
|
|
305
|
+
({ className, ...rest }, ref) => {
|
|
306
|
+
const styles = useDialog();
|
|
307
|
+
const css = { ...styles.overlay };
|
|
308
|
+
return /* @__PURE__ */ jsx6(
|
|
309
|
+
ModalOverlay,
|
|
310
|
+
{
|
|
311
|
+
ref,
|
|
312
|
+
className: cx6("ui-dialog-overlay", className),
|
|
313
|
+
__css: css,
|
|
314
|
+
...rest
|
|
315
|
+
}
|
|
316
|
+
);
|
|
317
|
+
}
|
|
318
|
+
);
|
|
319
|
+
var DialogCloseButton = forwardRef6(
|
|
320
|
+
({ className, ...rest }, ref) => {
|
|
321
|
+
const styles = useDialog();
|
|
322
|
+
const css = { ...styles.closeButton };
|
|
323
|
+
return /* @__PURE__ */ jsx6(
|
|
324
|
+
ModalCloseButton,
|
|
325
|
+
{
|
|
326
|
+
ref,
|
|
327
|
+
className: cx6("ui-dialog-close-button", className),
|
|
328
|
+
__css: css,
|
|
329
|
+
...rest
|
|
330
|
+
}
|
|
331
|
+
);
|
|
332
|
+
}
|
|
333
|
+
);
|
|
334
|
+
var DialogHeader = forwardRef6(
|
|
335
|
+
({ className, ...rest }, ref) => {
|
|
336
|
+
const styles = useDialog();
|
|
337
|
+
const css = { ...styles.header };
|
|
338
|
+
return /* @__PURE__ */ jsx6(
|
|
339
|
+
ModalHeader,
|
|
340
|
+
{
|
|
341
|
+
ref,
|
|
342
|
+
className: cx6("ui-dialog-header", className),
|
|
343
|
+
__css: css,
|
|
344
|
+
...rest
|
|
345
|
+
}
|
|
346
|
+
);
|
|
347
|
+
}
|
|
348
|
+
);
|
|
349
|
+
var DialogBody = forwardRef6(
|
|
350
|
+
({ className, ...rest }, ref) => {
|
|
351
|
+
const styles = useDialog();
|
|
352
|
+
const css = { ...styles.body };
|
|
353
|
+
return /* @__PURE__ */ jsx6(
|
|
354
|
+
ModalBody,
|
|
355
|
+
{
|
|
356
|
+
ref,
|
|
357
|
+
className: cx6("ui-dialog-body", className),
|
|
358
|
+
__css: css,
|
|
359
|
+
...rest
|
|
360
|
+
}
|
|
361
|
+
);
|
|
362
|
+
}
|
|
363
|
+
);
|
|
364
|
+
var DialogFooter = forwardRef6(
|
|
365
|
+
({ className, ...rest }, ref) => {
|
|
366
|
+
const styles = useDialog();
|
|
367
|
+
const css = { ...styles.footer };
|
|
368
|
+
return /* @__PURE__ */ jsx6(
|
|
369
|
+
ModalFooter,
|
|
370
|
+
{
|
|
371
|
+
ref,
|
|
372
|
+
className: cx6("ui-dialog-footer", className),
|
|
373
|
+
__css: css,
|
|
374
|
+
...rest
|
|
375
|
+
}
|
|
376
|
+
);
|
|
377
|
+
}
|
|
378
|
+
);
|
|
379
|
+
|
|
380
|
+
// src/modal.tsx
|
|
381
|
+
import { jsx as jsx7, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
382
|
+
var [ModalProvider, useModal] = createContext2({
|
|
383
|
+
name: `ModalContext`,
|
|
384
|
+
errorMessage: `useModal returned is 'undefined'. Seems you forgot to wrap the components in "<Modal />" `
|
|
385
|
+
});
|
|
386
|
+
var Modal = forwardRef7(
|
|
387
|
+
({ size, ...props }, ref) => {
|
|
388
|
+
const [styles, mergedProps] = useMultiComponentStyle2("Modal", {
|
|
389
|
+
size,
|
|
390
|
+
...props
|
|
391
|
+
});
|
|
392
|
+
const {
|
|
393
|
+
className,
|
|
394
|
+
children,
|
|
395
|
+
isOpen,
|
|
396
|
+
onClose,
|
|
397
|
+
onOverlayClick,
|
|
398
|
+
onEsc,
|
|
399
|
+
onCloseComplete,
|
|
400
|
+
placement: _placement = "center",
|
|
401
|
+
outside = "md",
|
|
402
|
+
withCloseButton = true,
|
|
403
|
+
withOverlay = true,
|
|
404
|
+
allowPinchZoom = false,
|
|
405
|
+
scrollBehavior = "inside",
|
|
406
|
+
autoFocus,
|
|
407
|
+
restoreFocus,
|
|
408
|
+
initialFocusRef,
|
|
409
|
+
finalFocusRef,
|
|
410
|
+
blockScrollOnMount = true,
|
|
411
|
+
closeOnOverlay = true,
|
|
412
|
+
closeOnEsc = true,
|
|
413
|
+
lockFocusAcrossFrames = true,
|
|
414
|
+
animation = "scale",
|
|
415
|
+
duration,
|
|
416
|
+
...rest
|
|
417
|
+
} = omitThemeProps2(mergedProps);
|
|
418
|
+
const onKeyDown = useCallback(
|
|
419
|
+
(event) => {
|
|
420
|
+
if (event.key !== "Escape")
|
|
421
|
+
return;
|
|
422
|
+
event.stopPropagation();
|
|
423
|
+
if (closeOnEsc)
|
|
424
|
+
onClose == null ? void 0 : onClose();
|
|
425
|
+
onEsc == null ? void 0 : onEsc();
|
|
426
|
+
},
|
|
427
|
+
[closeOnEsc, onClose, onEsc]
|
|
428
|
+
);
|
|
429
|
+
const validChildren = getValidChildren2(children);
|
|
430
|
+
const [customModalOverlay, ...cloneChildren] = findChildren2(
|
|
431
|
+
validChildren,
|
|
432
|
+
ModalOverlay,
|
|
433
|
+
DialogOverlay,
|
|
434
|
+
DrawerOverlay
|
|
435
|
+
);
|
|
436
|
+
let [drawerContent] = findChildren2(validChildren, DrawerContent);
|
|
437
|
+
if (drawerContent)
|
|
438
|
+
drawerContent = cloneElement(drawerContent, { onKeyDown });
|
|
439
|
+
const placement = useValue(_placement);
|
|
440
|
+
const css = {
|
|
441
|
+
position: "fixed",
|
|
442
|
+
top: 0,
|
|
443
|
+
left: 0,
|
|
444
|
+
zIndex: "beerus",
|
|
445
|
+
w: "100vw",
|
|
446
|
+
h: "100vh",
|
|
447
|
+
p: size !== "full" ? outside : void 0,
|
|
448
|
+
display: "flex",
|
|
449
|
+
justifyContent: placement.includes("right") ? "flex-start" : placement.includes("left") ? "flex-end" : "center",
|
|
450
|
+
alignItems: placement.includes("top") ? "flex-start" : placement.includes("bottom") ? "flex-end" : "center"
|
|
451
|
+
};
|
|
452
|
+
return /* @__PURE__ */ jsx7(
|
|
453
|
+
ModalProvider,
|
|
454
|
+
{
|
|
455
|
+
value: {
|
|
456
|
+
isOpen,
|
|
457
|
+
onClose,
|
|
458
|
+
onOverlayClick,
|
|
459
|
+
withCloseButton,
|
|
460
|
+
scrollBehavior,
|
|
461
|
+
closeOnOverlay,
|
|
462
|
+
animation,
|
|
463
|
+
duration,
|
|
464
|
+
styles
|
|
465
|
+
},
|
|
466
|
+
children: /* @__PURE__ */ jsx7(AnimatePresence, { onExitComplete: onCloseComplete, children: isOpen ? /* @__PURE__ */ jsx7(Portal, { children: /* @__PURE__ */ jsx7(
|
|
467
|
+
FocusLock,
|
|
468
|
+
{
|
|
469
|
+
autoFocus,
|
|
470
|
+
initialFocusRef,
|
|
471
|
+
finalFocusRef,
|
|
472
|
+
restoreFocus,
|
|
473
|
+
lockFocusAcrossFrames,
|
|
474
|
+
children: /* @__PURE__ */ jsx7(
|
|
475
|
+
RemoveScroll,
|
|
476
|
+
{
|
|
477
|
+
allowPinchZoom,
|
|
478
|
+
enabled: blockScrollOnMount,
|
|
479
|
+
forwardProps: true,
|
|
480
|
+
children: /* @__PURE__ */ jsxs2(ui5.div, { __css: css, children: [
|
|
481
|
+
customModalOverlay != null ? customModalOverlay : withOverlay && size !== "full" ? /* @__PURE__ */ jsx7(ModalOverlay, {}) : null,
|
|
482
|
+
drawerContent != null ? drawerContent : /* @__PURE__ */ jsx7(
|
|
483
|
+
ModalContent,
|
|
484
|
+
{
|
|
485
|
+
ref,
|
|
486
|
+
className,
|
|
487
|
+
onKeyDown,
|
|
488
|
+
...rest,
|
|
489
|
+
children: cloneChildren
|
|
490
|
+
}
|
|
491
|
+
)
|
|
492
|
+
] })
|
|
493
|
+
}
|
|
494
|
+
)
|
|
495
|
+
}
|
|
496
|
+
) }) : null })
|
|
497
|
+
}
|
|
498
|
+
);
|
|
499
|
+
}
|
|
500
|
+
);
|
|
501
|
+
var getModalContentProps = (animation = "scale", duration) => {
|
|
502
|
+
switch (animation) {
|
|
503
|
+
case "scale":
|
|
504
|
+
return {
|
|
505
|
+
...scaleFadeProps,
|
|
506
|
+
custom: { scale: 0.95, reverse: true, duration }
|
|
507
|
+
};
|
|
508
|
+
case "top":
|
|
509
|
+
return {
|
|
510
|
+
...slideFadeProps,
|
|
511
|
+
custom: { offsetY: -16, reverse: true, duration }
|
|
512
|
+
};
|
|
513
|
+
case "right":
|
|
514
|
+
return {
|
|
515
|
+
...slideFadeProps,
|
|
516
|
+
custom: { offsetX: 16, reverse: true, duration }
|
|
517
|
+
};
|
|
518
|
+
case "left":
|
|
519
|
+
return {
|
|
520
|
+
...slideFadeProps,
|
|
521
|
+
custom: { offsetX: -16, reverse: true, duration }
|
|
522
|
+
};
|
|
523
|
+
case "bottom":
|
|
524
|
+
return {
|
|
525
|
+
...slideFadeProps,
|
|
526
|
+
custom: { offsetY: 16, reverse: true, duration }
|
|
527
|
+
};
|
|
528
|
+
}
|
|
529
|
+
};
|
|
530
|
+
var ModalContent = forwardRef7(
|
|
531
|
+
({ className, children, __css, ...rest }, ref) => {
|
|
532
|
+
const {
|
|
533
|
+
styles,
|
|
534
|
+
scrollBehavior,
|
|
535
|
+
withCloseButton,
|
|
536
|
+
onClose,
|
|
537
|
+
animation,
|
|
538
|
+
duration
|
|
539
|
+
} = useModal();
|
|
540
|
+
const validChildren = getValidChildren2(children);
|
|
541
|
+
const [customModalCloseButton, ...cloneChildren] = findChildren2(
|
|
542
|
+
validChildren,
|
|
543
|
+
ModalCloseButton,
|
|
544
|
+
DialogCloseButton
|
|
545
|
+
);
|
|
546
|
+
const props = animation !== "none" ? getModalContentProps(animation, duration) : {};
|
|
547
|
+
const css = {
|
|
548
|
+
position: "relative",
|
|
549
|
+
maxH: "100%",
|
|
550
|
+
display: "flex",
|
|
551
|
+
flexDirection: "column",
|
|
552
|
+
overflow: scrollBehavior === "inside" ? "hidden" : "auto",
|
|
553
|
+
outline: 0,
|
|
554
|
+
...__css ? __css : styles.container
|
|
555
|
+
};
|
|
556
|
+
return /* @__PURE__ */ jsxs2(
|
|
557
|
+
ui5.section,
|
|
558
|
+
{
|
|
559
|
+
as: motion2.section,
|
|
560
|
+
ref,
|
|
561
|
+
className: cx7("ui-modal", className),
|
|
562
|
+
tabIndex: -1,
|
|
563
|
+
__css: css,
|
|
564
|
+
...props,
|
|
565
|
+
...rest,
|
|
566
|
+
children: [
|
|
567
|
+
customModalCloseButton != null ? customModalCloseButton : withCloseButton && onClose ? /* @__PURE__ */ jsx7(ModalCloseButton, {}) : null,
|
|
568
|
+
cloneChildren
|
|
569
|
+
]
|
|
570
|
+
}
|
|
571
|
+
);
|
|
572
|
+
}
|
|
573
|
+
);
|
|
574
|
+
|
|
575
|
+
// src/drawer.tsx
|
|
576
|
+
import { jsx as jsx8, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
577
|
+
var [DrawerProvider, useDrawer] = createContext3({
|
|
578
|
+
name: `DrawerContext`,
|
|
579
|
+
errorMessage: `useDrawer returned is 'undefined'. Seems you forgot to wrap the components in "<Drawer />" `
|
|
580
|
+
});
|
|
581
|
+
var Drawer = forwardRef8(
|
|
582
|
+
({ size, ...props }, ref) => {
|
|
583
|
+
const [styles, mergedProps] = useMultiComponentStyle3("Drawer", {
|
|
584
|
+
size,
|
|
585
|
+
...props
|
|
586
|
+
});
|
|
587
|
+
const {
|
|
588
|
+
children,
|
|
589
|
+
isOpen,
|
|
590
|
+
placement = "right",
|
|
591
|
+
onClose,
|
|
592
|
+
onOverlayClick,
|
|
593
|
+
onEsc,
|
|
594
|
+
onCloseComplete,
|
|
595
|
+
withCloseButton = true,
|
|
596
|
+
withOverlay = true,
|
|
597
|
+
allowPinchZoom,
|
|
598
|
+
autoFocus,
|
|
599
|
+
restoreFocus,
|
|
600
|
+
initialFocusRef,
|
|
601
|
+
finalFocusRef,
|
|
602
|
+
blockScrollOnMount,
|
|
603
|
+
closeOnOverlay,
|
|
604
|
+
closeOnEsc,
|
|
605
|
+
lockFocusAcrossFrames,
|
|
606
|
+
duration = { enter: 0.4, exit: 0.3 },
|
|
607
|
+
...rest
|
|
608
|
+
} = omitThemeProps3(mergedProps);
|
|
609
|
+
const validChildren = getValidChildren3(children);
|
|
610
|
+
const [customDrawerOverlay, ...cloneChildren] = findChildren3(
|
|
611
|
+
validChildren,
|
|
612
|
+
DrawerOverlay
|
|
613
|
+
);
|
|
614
|
+
return /* @__PURE__ */ jsx8(DrawerProvider, { value: styles, children: /* @__PURE__ */ jsxs3(
|
|
615
|
+
Modal,
|
|
616
|
+
{
|
|
617
|
+
ref,
|
|
618
|
+
...{
|
|
619
|
+
isOpen,
|
|
620
|
+
onClose,
|
|
621
|
+
onOverlayClick,
|
|
622
|
+
onEsc,
|
|
623
|
+
onCloseComplete,
|
|
624
|
+
withCloseButton: false,
|
|
625
|
+
withOverlay: false,
|
|
626
|
+
allowPinchZoom,
|
|
627
|
+
autoFocus,
|
|
628
|
+
restoreFocus,
|
|
629
|
+
initialFocusRef,
|
|
630
|
+
finalFocusRef,
|
|
631
|
+
blockScrollOnMount,
|
|
632
|
+
closeOnOverlay,
|
|
633
|
+
closeOnEsc,
|
|
634
|
+
lockFocusAcrossFrames,
|
|
635
|
+
duration
|
|
636
|
+
},
|
|
637
|
+
children: [
|
|
638
|
+
customDrawerOverlay != null ? customDrawerOverlay : withOverlay ? /* @__PURE__ */ jsx8(DrawerOverlay, {}) : null,
|
|
639
|
+
/* @__PURE__ */ jsx8(DrawerContent, { ...{ placement, withCloseButton, ...rest }, children: cloneChildren })
|
|
640
|
+
]
|
|
641
|
+
}
|
|
642
|
+
) });
|
|
643
|
+
}
|
|
644
|
+
);
|
|
645
|
+
var DrawerContent = forwardRef8(
|
|
646
|
+
({ className, children, placement, withCloseButton, ...rest }, ref) => {
|
|
647
|
+
const { isOpen, onClose, duration } = useModal();
|
|
648
|
+
const styles = useDrawer();
|
|
649
|
+
const validChildren = getValidChildren3(children);
|
|
650
|
+
const [customDrawerCloseButton, ...cloneChildren] = findChildren3(
|
|
651
|
+
validChildren,
|
|
652
|
+
DrawerCloseButton
|
|
653
|
+
);
|
|
654
|
+
const css = {
|
|
655
|
+
display: "flex",
|
|
656
|
+
flexDirection: "column",
|
|
657
|
+
width: "100%",
|
|
658
|
+
outline: 0,
|
|
659
|
+
...styles.container
|
|
660
|
+
};
|
|
661
|
+
return /* @__PURE__ */ jsxs3(
|
|
662
|
+
Slide,
|
|
663
|
+
{
|
|
664
|
+
ref,
|
|
665
|
+
className: cx8("ui-drawer", className),
|
|
666
|
+
tabIndex: -1,
|
|
667
|
+
isOpen,
|
|
668
|
+
placement,
|
|
669
|
+
duration,
|
|
670
|
+
__css: css,
|
|
671
|
+
...rest,
|
|
672
|
+
children: [
|
|
673
|
+
customDrawerCloseButton != null ? customDrawerCloseButton : withCloseButton && onClose ? /* @__PURE__ */ jsx8(DrawerCloseButton, {}) : null,
|
|
674
|
+
cloneChildren
|
|
675
|
+
]
|
|
676
|
+
}
|
|
677
|
+
);
|
|
678
|
+
}
|
|
679
|
+
);
|
|
680
|
+
var DrawerOverlay = forwardRef8(
|
|
681
|
+
({ className, ...rest }, ref) => {
|
|
682
|
+
const styles = useDrawer();
|
|
683
|
+
const css = { ...styles.overlay };
|
|
684
|
+
return /* @__PURE__ */ jsx8(
|
|
685
|
+
ModalOverlay,
|
|
686
|
+
{
|
|
687
|
+
ref,
|
|
688
|
+
className: cx8("ui-drawer-overlay", className),
|
|
689
|
+
__css: css,
|
|
690
|
+
...rest
|
|
691
|
+
}
|
|
692
|
+
);
|
|
693
|
+
}
|
|
694
|
+
);
|
|
695
|
+
var DrawerCloseButton = forwardRef8(
|
|
696
|
+
({ className, ...rest }, ref) => {
|
|
697
|
+
const styles = useDrawer();
|
|
698
|
+
const css = { ...styles.closeButton };
|
|
699
|
+
return /* @__PURE__ */ jsx8(
|
|
700
|
+
ModalCloseButton,
|
|
701
|
+
{
|
|
702
|
+
ref,
|
|
703
|
+
className: cx8("ui-drawer-close-button", className),
|
|
704
|
+
__css: css,
|
|
705
|
+
...rest
|
|
706
|
+
}
|
|
707
|
+
);
|
|
708
|
+
}
|
|
709
|
+
);
|
|
710
|
+
var DrawerHeader = forwardRef8(
|
|
711
|
+
({ className, ...rest }, ref) => {
|
|
712
|
+
const styles = useDrawer();
|
|
713
|
+
const css = { ...styles.header };
|
|
714
|
+
return /* @__PURE__ */ jsx8(
|
|
715
|
+
ModalHeader,
|
|
716
|
+
{
|
|
717
|
+
ref,
|
|
718
|
+
className: cx8("ui-drawer-header", className),
|
|
719
|
+
__css: css,
|
|
720
|
+
...rest
|
|
721
|
+
}
|
|
722
|
+
);
|
|
723
|
+
}
|
|
724
|
+
);
|
|
725
|
+
var DrawerBody = forwardRef8(
|
|
726
|
+
({ className, ...rest }, ref) => {
|
|
727
|
+
const styles = useDrawer();
|
|
728
|
+
const css = { ...styles.body };
|
|
729
|
+
return /* @__PURE__ */ jsx8(
|
|
730
|
+
ModalBody,
|
|
731
|
+
{
|
|
732
|
+
ref,
|
|
733
|
+
className: cx8("ui-drawer-body", className),
|
|
734
|
+
__css: css,
|
|
735
|
+
...rest
|
|
736
|
+
}
|
|
737
|
+
);
|
|
738
|
+
}
|
|
739
|
+
);
|
|
740
|
+
var DrawerFooter = forwardRef8(
|
|
741
|
+
({ className, ...rest }, ref) => {
|
|
742
|
+
const styles = useDrawer();
|
|
743
|
+
const css = { ...styles.footer };
|
|
744
|
+
return /* @__PURE__ */ jsx8(
|
|
745
|
+
ModalFooter,
|
|
746
|
+
{
|
|
747
|
+
ref,
|
|
748
|
+
className: cx8("ui-drawer-footer", className),
|
|
749
|
+
__css: css,
|
|
750
|
+
...rest
|
|
751
|
+
}
|
|
752
|
+
);
|
|
753
|
+
}
|
|
754
|
+
);
|
|
755
|
+
|
|
756
|
+
export {
|
|
757
|
+
Drawer,
|
|
758
|
+
DrawerContent,
|
|
759
|
+
DrawerOverlay,
|
|
760
|
+
DrawerCloseButton,
|
|
761
|
+
DrawerHeader,
|
|
762
|
+
DrawerBody,
|
|
763
|
+
DrawerFooter,
|
|
764
|
+
useModal,
|
|
765
|
+
Modal,
|
|
766
|
+
ModalOverlay,
|
|
767
|
+
ModalCloseButton,
|
|
768
|
+
ModalHeader,
|
|
769
|
+
ModalBody,
|
|
770
|
+
ModalFooter,
|
|
771
|
+
Dialog,
|
|
772
|
+
DialogOverlay,
|
|
773
|
+
DialogCloseButton,
|
|
774
|
+
DialogHeader,
|
|
775
|
+
DialogBody,
|
|
776
|
+
DialogFooter
|
|
777
|
+
};
|