@saas-ui/modals 1.5.5 → 2.0.0-next.1
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/CHANGELOG.md +23 -3
- package/dist/index.d.ts +218 -7
- package/dist/index.js +433 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +401 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +13 -11
- package/src/dialog.tsx +3 -6
- package/src/form.tsx +24 -14
- package/src/menu.tsx +1 -3
- package/dist/dialog.d.ts +0 -54
- package/dist/dialog.d.ts.map +0 -1
- package/dist/drawer.d.ts +0 -26
- package/dist/drawer.d.ts.map +0 -1
- package/dist/form.d.ts +0 -32
- package/dist/form.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.modern.mjs +0 -2
- package/dist/index.modern.mjs.map +0 -1
- package/dist/menu.d.ts +0 -14
- package/dist/menu.d.ts.map +0 -1
- package/dist/modal.d.ts +0 -23
- package/dist/modal.d.ts.map +0 -1
- package/dist/provider.d.ts +0 -83
- package/dist/provider.d.ts.map +0 -1
package/dist/index.js
CHANGED
@@ -1,2 +1,433 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
var React = require('react');
|
4
|
+
var react = require('@chakra-ui/react');
|
5
|
+
var reactUtils = require('@saas-ui/react-utils');
|
6
|
+
var forms = require('@saas-ui/forms');
|
7
|
+
|
8
|
+
function _interopNamespaceDefault(e) {
|
9
|
+
var n = Object.create(null);
|
10
|
+
if (e) {
|
11
|
+
Object.keys(e).forEach(function (k) {
|
12
|
+
if (k !== 'default') {
|
13
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
14
|
+
Object.defineProperty(n, k, d.get ? d : {
|
15
|
+
enumerable: true,
|
16
|
+
get: function () { return e[k]; }
|
17
|
+
});
|
18
|
+
}
|
19
|
+
});
|
20
|
+
}
|
21
|
+
n.default = e;
|
22
|
+
return Object.freeze(n);
|
23
|
+
}
|
24
|
+
|
25
|
+
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
26
|
+
|
27
|
+
// src/dialog.tsx
|
28
|
+
var ConfirmDialog = (props) => {
|
29
|
+
const {
|
30
|
+
title,
|
31
|
+
cancelLabel = "Cancel",
|
32
|
+
confirmLabel = "Confirm",
|
33
|
+
cancelProps,
|
34
|
+
confirmProps,
|
35
|
+
buttonGroupProps,
|
36
|
+
isOpen,
|
37
|
+
closeOnCancel = true,
|
38
|
+
closeOnConfirm = true,
|
39
|
+
leastDestructiveFocus = "cancel",
|
40
|
+
onClose,
|
41
|
+
onCancel,
|
42
|
+
onConfirm,
|
43
|
+
children,
|
44
|
+
...rest
|
45
|
+
} = props;
|
46
|
+
const cancelRef = React__namespace.useRef(null);
|
47
|
+
const confirmRef = React__namespace.useRef(null);
|
48
|
+
return /* @__PURE__ */ React__namespace.createElement(react.AlertDialog, {
|
49
|
+
isOpen,
|
50
|
+
onClose,
|
51
|
+
...rest,
|
52
|
+
leastDestructiveRef: leastDestructiveFocus === "cancel" ? cancelRef : confirmRef
|
53
|
+
}, /* @__PURE__ */ React__namespace.createElement(react.AlertDialogOverlay, null, /* @__PURE__ */ React__namespace.createElement(react.AlertDialogContent, null, /* @__PURE__ */ React__namespace.createElement(react.AlertDialogHeader, null, title), /* @__PURE__ */ React__namespace.createElement(react.AlertDialogBody, null, children), /* @__PURE__ */ React__namespace.createElement(react.AlertDialogFooter, null, /* @__PURE__ */ React__namespace.createElement(react.ButtonGroup, {
|
54
|
+
...buttonGroupProps
|
55
|
+
}, /* @__PURE__ */ React__namespace.createElement(react.Button, {
|
56
|
+
ref: cancelRef,
|
57
|
+
...cancelProps,
|
58
|
+
onClick: () => {
|
59
|
+
onCancel == null ? void 0 : onCancel();
|
60
|
+
closeOnCancel && onClose();
|
61
|
+
}
|
62
|
+
}, (cancelProps == null ? void 0 : cancelProps.children) || cancelLabel), /* @__PURE__ */ React__namespace.createElement(react.Button, {
|
63
|
+
ref: confirmRef,
|
64
|
+
...confirmProps,
|
65
|
+
onClick: () => {
|
66
|
+
onConfirm == null ? void 0 : onConfirm();
|
67
|
+
closeOnConfirm && onClose();
|
68
|
+
}
|
69
|
+
}, (confirmProps == null ? void 0 : confirmProps.children) || confirmLabel))))));
|
70
|
+
};
|
71
|
+
var BaseDrawer = (props) => {
|
72
|
+
const {
|
73
|
+
title,
|
74
|
+
children,
|
75
|
+
isOpen,
|
76
|
+
onClose,
|
77
|
+
hideCloseButton,
|
78
|
+
hideOverlay,
|
79
|
+
...rest
|
80
|
+
} = props;
|
81
|
+
return /* @__PURE__ */ React__namespace.createElement(react.Drawer, {
|
82
|
+
isOpen,
|
83
|
+
onClose,
|
84
|
+
...rest
|
85
|
+
}, !hideOverlay && /* @__PURE__ */ React__namespace.createElement(react.DrawerOverlay, null), /* @__PURE__ */ React__namespace.createElement(react.DrawerContent, null, /* @__PURE__ */ React__namespace.createElement(react.DrawerHeader, null, title), !hideCloseButton && /* @__PURE__ */ React__namespace.createElement(react.DrawerCloseButton, null), children));
|
86
|
+
};
|
87
|
+
var Drawer = (props) => {
|
88
|
+
const { footer, children, ...rest } = props;
|
89
|
+
return /* @__PURE__ */ React__namespace.createElement(BaseDrawer, {
|
90
|
+
...rest
|
91
|
+
}, /* @__PURE__ */ React__namespace.createElement(react.DrawerBody, null, children), footer && /* @__PURE__ */ React__namespace.createElement(react.DrawerFooter, null, footer));
|
92
|
+
};
|
93
|
+
var BaseModal = (props) => {
|
94
|
+
const {
|
95
|
+
title,
|
96
|
+
footer,
|
97
|
+
children,
|
98
|
+
isOpen,
|
99
|
+
onClose,
|
100
|
+
hideCloseButton,
|
101
|
+
hideOverlay,
|
102
|
+
...rest
|
103
|
+
} = props;
|
104
|
+
return /* @__PURE__ */ React__namespace.createElement(react.Modal, {
|
105
|
+
isOpen,
|
106
|
+
onClose,
|
107
|
+
...rest
|
108
|
+
}, !hideOverlay && /* @__PURE__ */ React__namespace.createElement(react.ModalOverlay, null), /* @__PURE__ */ React__namespace.createElement(react.ModalContent, null, title && /* @__PURE__ */ React__namespace.createElement(react.ModalHeader, null, title), !hideCloseButton && /* @__PURE__ */ React__namespace.createElement(react.ModalCloseButton, null), children, footer && /* @__PURE__ */ React__namespace.createElement(react.ModalFooter, null, footer)));
|
109
|
+
};
|
110
|
+
var Modal = (props) => {
|
111
|
+
const { children, ...rest } = props;
|
112
|
+
return /* @__PURE__ */ React__namespace.createElement(BaseModal, {
|
113
|
+
...rest
|
114
|
+
}, /* @__PURE__ */ React__namespace.createElement(react.ModalBody, null, children));
|
115
|
+
};
|
116
|
+
var [StylesProvider] = react.createStylesContext("SuiMenuDialog");
|
117
|
+
var MenuDialog = (props) => {
|
118
|
+
const { onClose, onCloseComplete, ...rest } = props;
|
119
|
+
return /* @__PURE__ */ React__namespace.createElement(react.Menu, {
|
120
|
+
variant: "dialog",
|
121
|
+
onClose: () => {
|
122
|
+
onClose == null ? void 0 : onClose();
|
123
|
+
onCloseComplete == null ? void 0 : onCloseComplete();
|
124
|
+
},
|
125
|
+
...rest
|
126
|
+
});
|
127
|
+
};
|
128
|
+
var MenuDialogList = react.forwardRef(
|
129
|
+
(props, forwardedRef) => {
|
130
|
+
const {
|
131
|
+
rootProps,
|
132
|
+
title,
|
133
|
+
footer,
|
134
|
+
initialFocusRef,
|
135
|
+
hideCloseButton,
|
136
|
+
motionPreset,
|
137
|
+
...rest
|
138
|
+
} = props;
|
139
|
+
const { isOpen, onClose, menuRef } = react.useMenuContext();
|
140
|
+
const { ref, ...ownProps } = react.useMenuList(rest, forwardedRef);
|
141
|
+
const styles = react.useMultiStyleConfig("Menu", props);
|
142
|
+
return /* @__PURE__ */ React__namespace.createElement(BaseModal, {
|
143
|
+
isOpen,
|
144
|
+
onClose,
|
145
|
+
initialFocusRef: initialFocusRef || menuRef,
|
146
|
+
title,
|
147
|
+
hideCloseButton,
|
148
|
+
motionPreset
|
149
|
+
}, /* @__PURE__ */ React__namespace.createElement(StylesProvider, {
|
150
|
+
value: styles
|
151
|
+
}, /* @__PURE__ */ React__namespace.createElement(react.chakra.div, {
|
152
|
+
...ownProps,
|
153
|
+
ref,
|
154
|
+
__css: {
|
155
|
+
outline: 0,
|
156
|
+
maxHeight: "80vh",
|
157
|
+
overflowY: "auto",
|
158
|
+
...styles.list,
|
159
|
+
boxShadow: "none",
|
160
|
+
border: 0
|
161
|
+
}
|
162
|
+
})), footer && /* @__PURE__ */ React__namespace.createElement(react.ModalFooter, null, footer));
|
163
|
+
}
|
164
|
+
);
|
165
|
+
var FormDialog = react.forwardRef(
|
166
|
+
(props, ref) => {
|
167
|
+
const {
|
168
|
+
children,
|
169
|
+
schema,
|
170
|
+
resolver,
|
171
|
+
fieldResolver,
|
172
|
+
defaultValues,
|
173
|
+
values,
|
174
|
+
context,
|
175
|
+
onChange,
|
176
|
+
onSubmit,
|
177
|
+
onError,
|
178
|
+
mode,
|
179
|
+
reValidateMode,
|
180
|
+
shouldFocusError = true,
|
181
|
+
shouldUnregister,
|
182
|
+
shouldUseNativeValidation,
|
183
|
+
criteriaMode,
|
184
|
+
delayError = 100,
|
185
|
+
cancelLabel = "Cancel",
|
186
|
+
submitLabel = "Submit",
|
187
|
+
footer,
|
188
|
+
isOpen,
|
189
|
+
onClose,
|
190
|
+
...rest
|
191
|
+
} = props;
|
192
|
+
const formProps = {
|
193
|
+
ref,
|
194
|
+
schema,
|
195
|
+
resolver,
|
196
|
+
defaultValues,
|
197
|
+
values,
|
198
|
+
context,
|
199
|
+
onChange,
|
200
|
+
onSubmit,
|
201
|
+
onError,
|
202
|
+
mode,
|
203
|
+
reValidateMode,
|
204
|
+
shouldFocusError,
|
205
|
+
shouldUnregister,
|
206
|
+
shouldUseNativeValidation,
|
207
|
+
criteriaMode,
|
208
|
+
delayError
|
209
|
+
};
|
210
|
+
return /* @__PURE__ */ React__namespace.createElement(BaseModal, {
|
211
|
+
isOpen,
|
212
|
+
onClose,
|
213
|
+
...rest
|
214
|
+
}, /* @__PURE__ */ React__namespace.createElement(forms.Form, {
|
215
|
+
...formProps,
|
216
|
+
ref
|
217
|
+
}, (form) => /* @__PURE__ */ React__namespace.createElement(React__namespace.Fragment, null, /* @__PURE__ */ React__namespace.createElement(react.ModalBody, null, reactUtils.runIfFn(children, form) || /* @__PURE__ */ React__namespace.createElement(forms.Fields, {
|
218
|
+
schema,
|
219
|
+
fieldResolver,
|
220
|
+
focusFirstField: true
|
221
|
+
})), footer || /* @__PURE__ */ React__namespace.createElement(react.ModalFooter, null, /* @__PURE__ */ React__namespace.createElement(react.Button, {
|
222
|
+
variant: "ghost",
|
223
|
+
mr: 3,
|
224
|
+
onClick: onClose
|
225
|
+
}, cancelLabel), /* @__PURE__ */ React__namespace.createElement(forms.SubmitButton, null, submitLabel)))));
|
226
|
+
}
|
227
|
+
);
|
228
|
+
var ModalsContext = React__namespace.createContext(
|
229
|
+
null
|
230
|
+
);
|
231
|
+
var initialModalState = {
|
232
|
+
id: null,
|
233
|
+
props: null,
|
234
|
+
type: "modal"
|
235
|
+
};
|
236
|
+
var defaultModals = {
|
237
|
+
alert: ConfirmDialog,
|
238
|
+
confirm: ConfirmDialog,
|
239
|
+
drawer: Drawer,
|
240
|
+
modal: Modal,
|
241
|
+
menu: MenuDialog,
|
242
|
+
form: FormDialog
|
243
|
+
};
|
244
|
+
function ModalsProvider({ children, modals }) {
|
245
|
+
const _instances = React__namespace.useMemo(() => /* @__PURE__ */ new Set(), []);
|
246
|
+
const [activeModals, setActiveModals] = React__namespace.useState({
|
247
|
+
modal: initialModalState
|
248
|
+
});
|
249
|
+
const getModalComponent = React__namespace.useMemo(() => {
|
250
|
+
const _modals = {
|
251
|
+
...defaultModals,
|
252
|
+
...modals
|
253
|
+
};
|
254
|
+
return (type = "modal") => {
|
255
|
+
const component = _modals[type] || _modals.modal;
|
256
|
+
return component;
|
257
|
+
};
|
258
|
+
}, [modals]);
|
259
|
+
const setActiveModal = (modal, scope) => {
|
260
|
+
if (!scope) {
|
261
|
+
return setActiveModals({
|
262
|
+
modal
|
263
|
+
});
|
264
|
+
}
|
265
|
+
setActiveModals((prevState) => ({
|
266
|
+
...prevState,
|
267
|
+
[scope]: modal
|
268
|
+
}));
|
269
|
+
};
|
270
|
+
const open = (options) => {
|
271
|
+
if (typeof options === "function") {
|
272
|
+
const component2 = options;
|
273
|
+
options = {
|
274
|
+
component: component2
|
275
|
+
};
|
276
|
+
}
|
277
|
+
const {
|
278
|
+
id = _instances.size + 1,
|
279
|
+
type = "modal",
|
280
|
+
scope = "modal",
|
281
|
+
component,
|
282
|
+
...props
|
283
|
+
} = options;
|
284
|
+
const modal = {
|
285
|
+
id,
|
286
|
+
props,
|
287
|
+
type,
|
288
|
+
scope,
|
289
|
+
component,
|
290
|
+
isOpen: true
|
291
|
+
};
|
292
|
+
_instances.add(modal);
|
293
|
+
setActiveModal(modal, scope);
|
294
|
+
return id;
|
295
|
+
};
|
296
|
+
const drawer = (options) => {
|
297
|
+
return open({
|
298
|
+
...options,
|
299
|
+
type: "drawer"
|
300
|
+
});
|
301
|
+
};
|
302
|
+
const alert = (options) => {
|
303
|
+
return open({
|
304
|
+
...options,
|
305
|
+
scope: "alert",
|
306
|
+
type: "alert",
|
307
|
+
cancelProps: {
|
308
|
+
display: "none"
|
309
|
+
},
|
310
|
+
confirmProps: {
|
311
|
+
label: "OK"
|
312
|
+
},
|
313
|
+
leastDestructiveFocus: "confirm"
|
314
|
+
});
|
315
|
+
};
|
316
|
+
const confirm = (options) => {
|
317
|
+
return open({
|
318
|
+
...options,
|
319
|
+
scope: "alert",
|
320
|
+
type: "confirm"
|
321
|
+
});
|
322
|
+
};
|
323
|
+
const menu = (options) => {
|
324
|
+
return open({
|
325
|
+
...options,
|
326
|
+
type: "menu"
|
327
|
+
});
|
328
|
+
};
|
329
|
+
const form = (options) => {
|
330
|
+
return open({
|
331
|
+
...options,
|
332
|
+
type: "form"
|
333
|
+
});
|
334
|
+
};
|
335
|
+
const close = async (id, force) => {
|
336
|
+
var _a, _b;
|
337
|
+
const modals2 = [...Array.from(_instances)];
|
338
|
+
const modal = modals2.filter((modal2) => modal2.id === id)[0];
|
339
|
+
if (!modal) {
|
340
|
+
return;
|
341
|
+
}
|
342
|
+
const shouldClose = await ((_b = (_a = modal.props) == null ? void 0 : _a.onClose) == null ? void 0 : _b.call(_a, { force }));
|
343
|
+
if (shouldClose === false) {
|
344
|
+
return;
|
345
|
+
}
|
346
|
+
const scoped = modals2.filter(({ scope }) => scope === modal.scope);
|
347
|
+
if (scoped.length === 1) {
|
348
|
+
setActiveModal(
|
349
|
+
{
|
350
|
+
...modal,
|
351
|
+
isOpen: false
|
352
|
+
},
|
353
|
+
modal.scope
|
354
|
+
);
|
355
|
+
} else if (scoped.length > 1) {
|
356
|
+
setActiveModal(scoped[scoped.length - 2], modal.scope);
|
357
|
+
} else {
|
358
|
+
setActiveModal(
|
359
|
+
{
|
360
|
+
id: null,
|
361
|
+
props: null,
|
362
|
+
type: modal.type
|
363
|
+
},
|
364
|
+
modal.scope
|
365
|
+
);
|
366
|
+
}
|
367
|
+
};
|
368
|
+
const closeComplete = (id) => {
|
369
|
+
const modals2 = [...Array.from(_instances)];
|
370
|
+
const modal = modals2.filter((modal2) => modal2.id === id)[0];
|
371
|
+
_instances.delete(modal);
|
372
|
+
const scoped = modals2.filter(({ scope }) => scope === modal.scope);
|
373
|
+
if (scoped.length === 1) {
|
374
|
+
setActiveModal(initialModalState, modal.scope);
|
375
|
+
}
|
376
|
+
};
|
377
|
+
const closeAll = () => {
|
378
|
+
_instances.forEach((modal) => {
|
379
|
+
var _a, _b;
|
380
|
+
return (_b = (_a = modal.props) == null ? void 0 : _a.onClose) == null ? void 0 : _b.call(_a, { force: true });
|
381
|
+
});
|
382
|
+
_instances.clear();
|
383
|
+
setActiveModal(initialModalState);
|
384
|
+
};
|
385
|
+
const context = {
|
386
|
+
open,
|
387
|
+
drawer,
|
388
|
+
alert,
|
389
|
+
confirm,
|
390
|
+
menu,
|
391
|
+
form,
|
392
|
+
close,
|
393
|
+
closeAll
|
394
|
+
};
|
395
|
+
const content = React__namespace.useMemo(
|
396
|
+
() => Object.entries(activeModals).map(([scope, config]) => {
|
397
|
+
const Component = config.component || getModalComponent(config.type);
|
398
|
+
const { title, body, children: children2, ...props } = config.props || {};
|
399
|
+
return /* @__PURE__ */ React__namespace.createElement(Component, {
|
400
|
+
key: scope,
|
401
|
+
title,
|
402
|
+
children: body || children2,
|
403
|
+
...props,
|
404
|
+
isOpen: !!config.isOpen,
|
405
|
+
onClose: () => close(config.id),
|
406
|
+
onCloseComplete: () => closeComplete(config.id)
|
407
|
+
});
|
408
|
+
}),
|
409
|
+
[activeModals]
|
410
|
+
);
|
411
|
+
return /* @__PURE__ */ React__namespace.createElement(ModalsContext.Provider, {
|
412
|
+
value: context
|
413
|
+
}, content, children);
|
414
|
+
}
|
415
|
+
var useModalsContext = () => React__namespace.useContext(ModalsContext);
|
416
|
+
var useModals = () => {
|
417
|
+
return useModalsContext();
|
418
|
+
};
|
419
|
+
|
420
|
+
exports.BaseDrawer = BaseDrawer;
|
421
|
+
exports.BaseModal = BaseModal;
|
422
|
+
exports.ConfirmDialog = ConfirmDialog;
|
423
|
+
exports.Drawer = Drawer;
|
424
|
+
exports.FormDialog = FormDialog;
|
425
|
+
exports.MenuDialog = MenuDialog;
|
426
|
+
exports.MenuDialogList = MenuDialogList;
|
427
|
+
exports.Modal = Modal;
|
428
|
+
exports.ModalsContext = ModalsContext;
|
429
|
+
exports.ModalsProvider = ModalsProvider;
|
430
|
+
exports.useModals = useModals;
|
431
|
+
exports.useModalsContext = useModalsContext;
|
432
|
+
//# sourceMappingURL=out.js.map
|
433
|
+
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/dialog.tsx","../src/drawer.tsx","../src/modal.tsx","../src/menu.tsx","../src/form.tsx","../src/provider.tsx"],"sourcesContent":["import * as React from 'react'\n\nimport {\n AlertDialog,\n AlertDialogBody,\n AlertDialogFooter,\n AlertDialogHeader,\n AlertDialogContent,\n AlertDialogOverlay,\n AlertDialogProps,\n} from '@chakra-ui/react'\n\nimport {\n ButtonGroup,\n ButtonGroupProps,\n Button,\n ButtonProps,\n} from '@saas-ui/button'\n\nexport interface ConfirmDialogProps\n extends Omit<AlertDialogProps, 'leastDestructiveRef'> {\n /**\n * The dialog title\n */\n title?: React.ReactNode\n /**\n * The cancel button label\n */\n cancelLabel?: React.ReactNode\n /**\n * The confirm button label\n */\n confirmLabel?: React.ReactNode\n /**\n * The cancel button props\n */\n cancelProps?: ButtonProps\n /**\n * The confirm button props\n */\n confirmProps?: ButtonProps\n /**\n * The button group props\n */\n buttonGroupProps?: ButtonGroupProps\n /**\n * Close the dialog on cancel\n * @default true\n */\n closeOnCancel?: boolean\n /**\n * Close the dialog on confirm\n * @default true\n */\n closeOnConfirm?: boolean\n /**\n * Defines which button gets initial focus\n * https://www.w3.org/TR/wai-aria-practices/#alertdialog\n */\n leastDestructiveFocus?: 'cancel' | 'confirm'\n /**\n * Function that's called when cancel is clicked\n */\n onCancel?: () => void\n /**\n * Function that's called when confirm is clicked\n */\n onConfirm?: () => void\n}\n\nexport const ConfirmDialog: React.FC<ConfirmDialogProps> = (props) => {\n const {\n title,\n cancelLabel = 'Cancel',\n confirmLabel = 'Confirm',\n cancelProps,\n confirmProps,\n buttonGroupProps,\n isOpen,\n closeOnCancel = true,\n closeOnConfirm = true,\n leastDestructiveFocus = 'cancel',\n onClose,\n onCancel,\n onConfirm,\n children,\n ...rest\n } = props\n\n const cancelRef = React.useRef(null)\n const confirmRef = React.useRef(null)\n\n return (\n <AlertDialog\n isOpen={isOpen}\n onClose={onClose}\n {...rest}\n leastDestructiveRef={\n leastDestructiveFocus === 'cancel' ? cancelRef : confirmRef\n }\n >\n <AlertDialogOverlay>\n <AlertDialogContent>\n <AlertDialogHeader>{title}</AlertDialogHeader>\n\n <AlertDialogBody>{children}</AlertDialogBody>\n\n <AlertDialogFooter>\n <ButtonGroup {...buttonGroupProps}>\n <Button\n ref={cancelRef}\n {...cancelProps}\n onClick={() => {\n onCancel?.()\n\n closeOnCancel && onClose()\n }}\n >\n {cancelProps?.children || cancelProps?.label || cancelLabel}\n </Button>\n <Button\n ref={confirmRef}\n {...confirmProps}\n onClick={() => {\n onConfirm?.()\n\n closeOnConfirm && onClose()\n }}\n >\n {confirmProps?.children || confirmProps?.label || confirmLabel}\n </Button>\n </ButtonGroup>\n </AlertDialogFooter>\n </AlertDialogContent>\n </AlertDialogOverlay>\n </AlertDialog>\n )\n}\n","import * as React from 'react'\n\nimport {\n Drawer as ChakraDrawer,\n DrawerOverlay,\n DrawerContent,\n DrawerHeader,\n DrawerFooter,\n DrawerBody,\n DrawerCloseButton,\n DrawerProps as ChakraDrawerProps,\n} from '@chakra-ui/react'\n\nexport interface BaseDrawerProps extends Omit<ChakraDrawerProps, 'children'> {\n /**\n * The drawer title\n */\n title: React.ReactNode\n /**\n * Hide the close button\n */\n hideCloseButton?: boolean\n /**\n * Hide the overflow\n */\n hideOverlay?: boolean\n children?: React.ReactNode\n}\n\nexport const BaseDrawer: React.FC<BaseDrawerProps> = (props) => {\n const {\n title,\n children,\n isOpen,\n onClose,\n hideCloseButton,\n hideOverlay,\n ...rest\n } = props\n return (\n <ChakraDrawer isOpen={isOpen} onClose={onClose} {...rest}>\n {!hideOverlay && <DrawerOverlay />}\n <DrawerContent>\n <DrawerHeader>{title}</DrawerHeader>\n {!hideCloseButton && <DrawerCloseButton />}\n {children}\n </DrawerContent>\n </ChakraDrawer>\n )\n}\n\nexport interface DrawerProps extends BaseDrawerProps {\n /**\n * Drawer footer content, wrapped with `DrawerFooter`\n */\n footer?: React.ReactNode\n}\n\nexport const Drawer: React.FC<DrawerProps> = (props) => {\n const { footer, children, ...rest } = props\n return (\n <BaseDrawer {...rest}>\n <DrawerBody>{children}</DrawerBody>\n\n {footer && <DrawerFooter>{footer}</DrawerFooter>}\n </BaseDrawer>\n )\n}\n","import * as React from 'react'\n\nimport {\n Modal as ChakraModal,\n ModalOverlay,\n ModalContent,\n ModalHeader,\n ModalFooter,\n ModalBody,\n ModalCloseButton,\n ModalProps as ChakraModalProps,\n} from '@chakra-ui/react'\n\nexport interface BaseModalProps extends ChakraModalProps {\n /**\n * The modal title\n */\n title?: React.ReactNode\n /**\n * The modal footer\n */\n footer?: React.ReactNode\n /**\n * Hide the close button\n */\n hideCloseButton?: boolean\n /**\n * Hide the overlay\n */\n hideOverlay?: boolean\n}\n\nexport const BaseModal: React.FC<BaseModalProps> = (props) => {\n const {\n title,\n footer,\n children,\n isOpen,\n onClose,\n hideCloseButton,\n hideOverlay,\n ...rest\n } = props\n return (\n <ChakraModal isOpen={isOpen} onClose={onClose} {...rest}>\n {!hideOverlay && <ModalOverlay />}\n <ModalContent>\n {title && <ModalHeader>{title}</ModalHeader>}\n {!hideCloseButton && <ModalCloseButton />}\n {children}\n {footer && <ModalFooter>{footer}</ModalFooter>}\n </ModalContent>\n </ChakraModal>\n )\n}\n\nexport const Modal: React.FC<BaseModalProps> = (props) => {\n const { children, ...rest } = props\n return (\n <BaseModal {...rest}>\n <ModalBody>{children}</ModalBody>\n </BaseModal>\n )\n}\n","import * as React from 'react'\n\nimport {\n ModalFooter,\n chakra,\n forwardRef,\n useMenuContext,\n useMenuList,\n createStylesContext,\n useMultiStyleConfig,\n Menu,\n MenuListProps,\n} from '@chakra-ui/react'\n\nimport {} from '@chakra-ui/system'\n\nimport { BaseModal, BaseModalProps } from './modal'\n\nconst [StylesProvider] = createStylesContext('MenuDialog')\n\nexport interface MenuDialogProps extends BaseModalProps {\n /**\n * The modal footer, wrapped with `ModalFooter`\n */\n footer?: React.ReactNode\n}\n\nexport const MenuDialog: React.FC<MenuDialogProps> = (props) => {\n const { onClose, onCloseComplete, ...rest } = props\n\n return (\n <Menu\n variant=\"dialog\"\n onClose={() => {\n onClose?.()\n // Not supported in Menu, so we call it here instead\n // @todo Refactor this in v2?\n onCloseComplete?.()\n }}\n {...rest}\n />\n )\n}\n\nexport interface MenuDialogListProps\n extends Omit<\n BaseModalProps,\n 'isOpen' | 'onClose' | 'children' | 'scrollBehavior'\n >,\n Omit<MenuListProps, 'title'> {}\n\nexport const MenuDialogList = forwardRef<MenuDialogListProps, 'div'>(\n (props, forwardedRef) => {\n const {\n rootProps,\n title,\n footer,\n initialFocusRef,\n hideCloseButton,\n motionPreset,\n ...rest\n } = props\n\n const { isOpen, onClose, menuRef } = useMenuContext()\n\n const { ref, ...ownProps } = useMenuList(rest, forwardedRef)\n\n const styles = useMultiStyleConfig('Menu', props)\n\n return (\n <BaseModal\n isOpen={isOpen}\n onClose={onClose}\n initialFocusRef={initialFocusRef || menuRef}\n title={title}\n hideCloseButton={hideCloseButton}\n motionPreset={motionPreset}\n >\n {/* We forward the styles again, otherwise the modal styles will be picked up */}\n <StylesProvider value={styles}>\n <chakra.div\n {...ownProps}\n ref={ref as React.Ref<HTMLDivElement>}\n __css={{\n outline: 0,\n maxHeight: '80vh', // can override this in theme\n overflowY: 'auto', // can override this in theme\n ...styles.list,\n boxShadow: 'none',\n border: 0,\n }}\n />\n </StylesProvider>\n {footer && <ModalFooter>{footer}</ModalFooter>}\n </BaseModal>\n )\n }\n)\n","import * as React from 'react'\n\nimport { ModalBody, ModalFooter, Button, forwardRef } from '@chakra-ui/react'\nimport { runIfFn } from '@chakra-ui/utils'\n\nimport {\n Form,\n Fields,\n SubmitButton,\n FormProps,\n FieldValues,\n FieldResolver,\n UseFormReturn,\n} from '@saas-ui/forms'\n\nimport { BaseModal, BaseModalProps } from './modal'\n\nexport interface FormDialogProps<TFieldValues extends FieldValues = FieldValues>\n extends Omit<BaseModalProps, 'children'>,\n Pick<\n FormProps<TFieldValues>,\n | 'schema'\n | 'defaultValues'\n | 'onChange'\n | 'onSubmit'\n | 'onError'\n | 'resolver'\n | 'mode'\n | 'reValidateMode'\n | 'shouldFocusError'\n | 'shouldUnregister'\n | 'shouldUseNativeValidation'\n | 'criteriaMode'\n | 'delayError'\n > {\n /**\n * The modal footer, will be wrapped with `ModalFooter`.\n * Defaults to a cancel and submit button.\n */\n footer?: React.ReactNode\n /**\n * The cancel button label\n * @default \"Cancel\"\n */\n cancelLabel?: React.ReactNode\n /**\n * The submit button label\n * @default \"Submit\"\n */\n submitLabel?: React.ReactNode\n /**\n * If no children are passed, this will auto render fields based on the supplied schema.\n */\n children?: React.ReactNode\n /**\n * A schema field resolver used to auto generate form fields.\n */\n fieldResolver?: FieldResolver\n}\n\nexport const FormDialog = forwardRef(\n <TFieldValues extends FieldValues = FieldValues>(\n props: FormDialogProps<TFieldValues>,\n ref: React.ForwardedRef<UseFormReturn<TFieldValues>>\n ) => {\n const {\n children,\n schema,\n resolver,\n fieldResolver,\n defaultValues,\n onChange,\n onSubmit,\n onError,\n mode,\n reValidateMode,\n shouldFocusError = true,\n shouldUnregister,\n shouldUseNativeValidation,\n criteriaMode,\n delayError = 100,\n cancelLabel,\n submitLabel,\n footer,\n isOpen,\n onClose,\n ...rest\n } = props\n\n const formProps = {\n ref,\n schema,\n resolver,\n defaultValues,\n onChange,\n onSubmit,\n onError,\n mode,\n reValidateMode,\n shouldFocusError,\n shouldUnregister,\n shouldUseNativeValidation,\n criteriaMode,\n delayError,\n }\n\n return (\n <BaseModal isOpen={isOpen} onClose={onClose} {...rest}>\n <Form {...formProps}>\n {(form) => (\n <>\n <ModalBody>\n {runIfFn(children, form) || (\n <Fields\n schema={schema}\n fieldResolver={fieldResolver}\n focusFirstField\n />\n )}\n </ModalBody>\n\n {footer || (\n <ModalFooter>\n <Button variant=\"ghost\" mr={3} onClick={onClose}>\n {cancelLabel || 'Cancel'}\n </Button>\n <SubmitButton>{submitLabel || 'Submit'}</SubmitButton>\n </ModalFooter>\n )}\n </>\n )}\n </Form>\n </BaseModal>\n )\n }\n) as <TFieldValues extends FieldValues>(\n props: FormDialogProps<TFieldValues> & {\n ref?: React.ForwardedRef<UseFormReturn<TFieldValues>>\n }\n) => React.ReactElement\n","import * as React from 'react'\n\nimport { Modal, BaseModalProps } from './modal'\nimport { Drawer, DrawerProps } from './drawer'\nimport { ConfirmDialog, ConfirmDialogProps } from './dialog'\nimport { MenuDialog, MenuDialogProps } from './menu'\nimport { FormDialog, FormDialogProps } from './form'\n\nexport interface ModalsContextValue {\n open: (options: OpenOptions) => ModalId\n drawer: (options: DrawerOptions) => ModalId\n alert: (options: ConfirmDialogOptions) => ModalId\n confirm: (options: ConfirmDialogOptions) => ModalId\n menu: (options: MenuDialogOptions) => ModalId\n form: (options: FormDialogOptions) => ModalId\n close: (id: ModalId) => void\n closeAll: () => void\n}\n\nexport const ModalsContext = React.createContext<ModalsContextValue | null>(\n null\n)\n\ninterface ModalsProviderProps {\n children: React.ReactNode\n modals?: Record<string, React.FC<any>>\n}\n\nexport type ModalId = string | number\n\ninterface ModalOptions\n extends Omit<BaseModalProps, 'onClose' | 'isOpen' | 'children'> {\n onClose?: (args: { force?: boolean }) => Promise<boolean | undefined> | void\n body?: React.ReactNode\n children?: React.ReactNode\n [key: string]: any\n}\n\nexport interface DrawerOptions\n extends ModalOptions,\n Omit<DrawerProps, 'onClose' | 'isOpen' | 'children' | 'title' | 'size'> {}\n\nexport interface ConfirmDialogOptions\n extends ModalOptions,\n Omit<ConfirmDialogProps, 'onClose' | 'isOpen' | 'children'> {}\n\nexport interface MenuDialogOptions\n extends ModalOptions,\n Omit<MenuDialogProps, 'onClose' | 'isOpen' | 'children'> {}\n\nexport interface FormDialogOptions\n extends ModalOptions,\n Omit<FormDialogProps, 'onClose' | 'isOpen' | 'children'> {}\n\nexport interface OpenOptions extends ModalOptions {\n type?: ModalTypes\n scope?: ModalScopes\n}\n\nexport type ModalScopes = 'modal' | 'alert'\n\nexport type ModalTypes =\n | 'modal'\n | 'drawer'\n | 'alert'\n | 'confirm'\n | 'menu'\n | string\n\nexport interface ModalConfig<\n TModalOptions extends ModalOptions = ModalOptions\n> {\n /**\n * The modal id, autogenerated when not set.\n * Can be used to close modals.\n */\n id?: ModalId | null\n /**\n * The modal props\n */\n props?: TModalOptions | null\n /**\n * The modal scope\n * Modals can only have one level per scope.\n * The default scopes are 'modal' and 'alert', alerts can be openend above modals.\n */\n scope?: ModalScopes | string\n /**\n * The modal type to open.\n * Build in types are 'modal', 'drawer', 'alert', 'confirm'\n *\n * Custom types can be configured using the `modals` prop of `ModalProvider`\n */\n type?: ModalTypes\n /**\n * Render a custom modal component.\n * This will ignore the `type` param.\n */\n component?: React.FC<BaseModalProps>\n /**\n * Whether the modal is open or not.\n * This is used internally to keep track of the modal state.\n */\n isOpen?: boolean\n}\n\nconst initialModalState: ModalConfig = {\n id: null,\n props: null,\n type: 'modal',\n}\n\nconst defaultModals = {\n alert: ConfirmDialog,\n confirm: ConfirmDialog,\n drawer: Drawer,\n modal: Modal,\n menu: MenuDialog,\n form: FormDialog,\n}\n\nexport function ModalsProvider({ children, modals }: ModalsProviderProps) {\n // Note that updating the Set doesn't trigger a re-render,\n // use in conjuction with setActiveModals\n const _instances = React.useMemo(() => new Set<ModalConfig>(), [])\n\n const [activeModals, setActiveModals] = React.useState<\n Record<string, ModalConfig>\n >({\n modal: initialModalState,\n })\n\n const getModalComponent = React.useMemo(() => {\n const _modals: Record<string, React.FC<any>> = {\n ...defaultModals,\n ...modals,\n }\n\n return (type: ModalTypes = 'modal') => {\n const component = _modals[type] || _modals.modal\n\n return component\n }\n }, [modals])\n\n const setActiveModal = (modal: ModalConfig, scope?: string) => {\n if (!scope) {\n return setActiveModals({\n modal,\n })\n }\n setActiveModals((prevState) => ({\n ...prevState,\n [scope]: modal,\n }))\n }\n\n const open = <T extends ModalOptions>(\n options: T | React.FC<BaseModalProps>\n ): ModalId => {\n if (typeof options === 'function') {\n const component: React.FC<BaseModalProps> = options\n options = {\n component,\n } as unknown as T\n }\n\n const {\n id = _instances.size + 1,\n type = 'modal',\n scope = 'modal',\n component,\n ...props\n } = options\n\n const modal: ModalConfig<T> = {\n id,\n props: props as T,\n type,\n scope,\n component,\n isOpen: true,\n }\n\n _instances.add(modal)\n setActiveModal(modal, scope)\n\n return id\n }\n\n const drawer = (options: DrawerOptions): ModalId => {\n return open<DrawerOptions>({\n ...options,\n type: 'drawer',\n })\n }\n\n const alert = (options: ConfirmDialogOptions): ModalId => {\n return open({\n ...options,\n scope: 'alert',\n type: 'alert',\n cancelProps: {\n display: 'none',\n },\n confirmProps: {\n label: 'OK',\n },\n leastDestructiveFocus: 'confirm',\n })\n }\n\n const confirm = (options: ConfirmDialogOptions): ModalId => {\n return open<ConfirmDialogOptions>({\n ...options,\n scope: 'alert',\n type: 'confirm',\n })\n }\n\n const menu = (options: MenuDialogOptions): ModalId => {\n return open<MenuDialogOptions>({\n ...options,\n type: 'menu',\n })\n }\n\n const form = (options: FormDialogOptions): ModalId => {\n return open<FormDialogOptions>({\n ...options,\n type: 'form',\n })\n }\n\n const close = async (id?: ModalId | null, force?: boolean) => {\n const modals = [...Array.from(_instances)]\n const modal = modals.filter((modal) => modal.id === id)[0]\n\n if (!modal) {\n return\n }\n\n const shouldClose = await modal.props?.onClose?.({ force })\n if (shouldClose === false) {\n return\n }\n\n const scoped = modals.filter(({ scope }) => scope === modal.scope)\n\n if (scoped.length === 1) {\n setActiveModal(\n {\n ...modal,\n isOpen: false,\n },\n modal.scope\n )\n } else if (scoped.length > 1) {\n setActiveModal(scoped[scoped.length - 2], modal.scope)\n } else {\n setActiveModal(\n {\n id: null,\n props: null,\n type: modal.type, // Keep type same as last modal type to make sure the animation isn't interrupted\n },\n modal.scope\n )\n }\n }\n\n const closeComplete = (id?: ModalId | null) => {\n const modals = [...Array.from(_instances)]\n const modal = modals.filter((modal) => modal.id === id)[0]\n\n _instances.delete(modal)\n\n const scoped = modals.filter(({ scope }) => scope === modal.scope)\n\n if (scoped.length === 1) {\n setActiveModal(initialModalState, modal.scope)\n }\n }\n\n const closeAll = () => {\n _instances.forEach((modal) => modal.props?.onClose?.({ force: true }))\n _instances.clear()\n\n setActiveModal(initialModalState)\n }\n\n const context = {\n open,\n drawer,\n alert,\n confirm,\n menu,\n form,\n close,\n closeAll,\n }\n\n const content = React.useMemo(\n () =>\n Object.entries(activeModals).map(([scope, config]) => {\n const Component = config.component || getModalComponent(config.type)\n\n const { title, body, children, ...props } = config.props || {}\n\n return (\n <Component\n key={scope}\n title={title}\n children={body || children}\n {...props}\n isOpen={!!config.isOpen}\n onClose={() => close(config.id)}\n onCloseComplete={() => closeComplete(config.id)}\n />\n )\n }),\n [activeModals]\n )\n\n return (\n <ModalsContext.Provider value={context}>\n {content}\n {children}\n </ModalsContext.Provider>\n )\n}\n\nexport const useModalsContext = () =>\n React.useContext(ModalsContext) as ModalsContextValue\n\nexport const useModals = () => {\n return useModalsContext()\n}\n"],"names":["_excluded","ConfirmDialog","props","title","cancelLabel","_props$cancelLabel","_props$confirmLabel","confirmLabel","cancelProps","confirmProps","buttonGroupProps","isOpen","_props$closeOnCancel","closeOnCancel","closeOnConfirm","_props$closeOnConfirm","_props$leastDestructi","leastDestructiveFocus","onClose","onCancel","onConfirm","children","rest","React","useRef","confirmRef","createElement","AlertDialog","_extends","leastDestructiveRef","cancelRef","AlertDialogOverlay","AlertDialogContent","AlertDialogHeader","AlertDialogBody","AlertDialogFooter","ButtonGroup","Button","ref","onClick","label","_excluded2","hideCloseButton","hideOverlay","_objectWithoutPropertiesLoose","ChakraDrawer","DrawerOverlay","DrawerContent","DrawerHeader","DrawerCloseButton","Drawer","footer","BaseDrawer","DrawerBody","DrawerFooter","ChakraModal","Modal","ModalOverlay","ModalContent","ModalHeader","ModalCloseButton","ModalFooter","BaseModal","ModalBody","_excluded3","StylesProvider","createStylesContext","MenuDialog","onCloseComplete","Menu","variant","MenuDialogList","forwardRef","forwardedRef","rootProps","initialFocusRef","motionPreset","_useMenuContext","useMenuContext","menuRef","useMenuList","ownProps","_useMenuList","styles","useMultiStyleConfig","value","chakra","div","__css","outline","maxHeight","overflowY","list","boxShadow","border","FormDialog","schema","resolver","fieldResolver","defaultValues","onChange","onSubmit","onError","mode","reValidateMode","shouldFocusError","_props$shouldFocusErr","shouldUnregister","shouldUseNativeValidation","criteriaMode","delayError","_props$delayError","submitLabel","formProps","Form","form","Fragment","runIfFn","Fields","focusFirstField","mr","SubmitButton","ModalsContext","createContext","id","type","defaultModals","alert","confirm","drawer","modal","menu","useModalsContext","useContext","_ref","modals","useMemo","Set","useState","initialModalState","activeModals","_React$useState","setActiveModals","getModalComponent","_modals","setActiveModal","scope","prevState","_extends2","open","options","component","_instances","size","_options$type","_options$scope","add","close","force","_modal$props","Array","from","filter","shouldClose","scoped","length","Promise","resolve","e","reject","context","display","closeAll","forEach","_modal$props2","clear","content","Object","entries","map","_ref4","config","Component","_ref5","body","key","closeComplete","_ref3","Provider"],"mappings":"0xBAAA,IAAAA,EAAA,CAAA,QAAA,cAAA,eAAA,cAAA,eAAA,mBAAA,SAAA,gBAAA,iBAAA,wBAAA,UAAA,WAAA,YAAA,YAsE0BC,EAAiC,SAACC,GAC1D,IACOC,EAeHD,EAfFC,MAeED,EAAAA,EAdFE,YAAAA,aAAc,SAAQC,EAAAC,EAcpBJ,EAbFK,aAAAA,OAAY,IAAAD,EAAG,UACfE,EAAAA,EAYEN,EAZFM,YACAC,EAWEP,EAXFO,aACAC,EAUER,EAVFQ,iBACAC,EASET,EATFS,OAAMC,EASJV,EARFW,cAAAA,OAAgB,IAAAD,GAQdV,EAAAA,EAAAA,EAPFY,eAAAA,OAAc,IAAAC,GAAOA,EAAAC,EAOnBd,EANFe,sBAAAA,aAAwB,SAAQD,EAChCE,EAKEhB,EALFgB,QACAC,EAIEjB,EAJFiB,SACAC,EAGElB,EAHFkB,UACAC,EAEEnB,EAFFmB,SACGC,EACDpB,EAAAA,EAEJF,KAAkBuB,EAAMC,OAAO,MACfC,EAAGF,EAAMC,OAAO,mBAEhC,OACED,EAAAG,cAACC,EAAAA,YAAWC,EAAA,CACVjB,OAAQA,EACRO,QAASA,GACLI,GACJO,oBAC4B,WAA1BZ,EAAqCa,EAAYL,iBAGnDF,EAAAG,cAACK,EAAkBA,mBAAA,kBACjBR,EAAC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K,OAALA,EAAK5C,EAAMhI,QAAc,MAApB4K,EAAa5J,aAAb,EAAA4J,EAAa5J,QAAU,CAAE4I,OAAO,GAAO,GACrEN,EAAWuB,QAEX9B,EAAeN,EACjB,GAaMqC,EAAUzJ,EAAMiH,QACpB,WAAA,OACQyC,OAACC,QAAQtC,GAAcuC,IAAI,SAAoBC,GAAA,IAAblC,EAAAkC,EAAA,GAAEC,EAAMD,EAAA,GACxCE,EAAYD,EAAO9B,WAAaR,EAAkBsC,EAAOxD,MAE/D0D,EAA4CF,EAAOnL,OAAS,CAAE,EAAtDC,EAAKoL,EAALpL,MAAOqL,EAAAA,EAAAA,KAAMnK,IAAAA,SAAanB,EAAK0C,EAAA2I,EAAA9I,gBAEvC,OACElB,EAAAG,cAAC4J,EAAS1J,EAAA,CACR6J,IAAKvC,EACL/I,MAAOA,EACPkB,SAAUmK,GAAQnK,GACdnB,EACJ,CAAAS,SAAU0K,EAAO1K,OACjBO,QAAS,WAAM2I,OAAAA,EAAMwB,EAAOzD,GAAG,EAC/BxD,gBAAiB,WAAMsH,OA9CX,SAAC9D,GACrB,IAAMW,YAAayB,MAAMC,KAAKT,IACxBtB,EAAQK,EAAO2B,OAAO,SAAChC,GAAUA,OAAAA,EAAMN,KAAOA,CAAE,GAAE,GAExD4B,SAAkBtB,GAII,IAFPK,EAAO2B,OAAO,SAAAyB,GAAezC,OAAPyC,EAALzC,QAAsBhB,EAAMgB,KAAK,GAEtDmB,QACTpB,EAAeN,EAAmBT,EAAMgB,MAE5C,CAmCiCwC,CAAcL,EAAOzD,GAAG,IAGrD,EAAE,EACJ,CAACgB,iBAGH,OACErH,EAAAG,cAACgG,EAAckE,SAAQ,CAACvG,MAAOqF,GAC5BM,EACA3J,EAGP,oBAKyB,WACvB,OAAuB+G,GACzB"}
|
1
|
+
{"version":3,"sources":["../src/dialog.tsx","../src/drawer.tsx","../src/modal.tsx","../src/menu.tsx","../src/form.tsx","../src/provider.tsx"],"names":["React","ModalFooter","ModalBody","Button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KAC5B,SACA,QACH;AAEJ;AAEO,IAAM,mBAAmB,MACxB,kBAAW,aAAa;AAEzB,IAAM,YAAY,MAAM;AAC7B,SAAO,iBAAiB;AAC1B","sourcesContent":["import * as React from 'react'\n\nimport {\n AlertDialog,\n AlertDialogBody,\n AlertDialogFooter,\n AlertDialogHeader,\n AlertDialogContent,\n AlertDialogOverlay,\n AlertDialogProps,\n ButtonGroup,\n ButtonGroupProps,\n Button,\n ButtonProps,\n} from '@chakra-ui/react'\n\nexport interface ConfirmDialogProps\n extends Omit<AlertDialogProps, 'leastDestructiveRef'> {\n /**\n * The dialog title\n */\n title?: React.ReactNode\n /**\n * The cancel button label\n */\n cancelLabel?: React.ReactNode\n /**\n * The confirm button label\n */\n confirmLabel?: React.ReactNode\n /**\n * The cancel button props\n */\n cancelProps?: ButtonProps\n /**\n * The confirm button props\n */\n confirmProps?: ButtonProps\n /**\n * The button group props\n */\n buttonGroupProps?: ButtonGroupProps\n /**\n * Close the dialog on cancel\n * @default true\n */\n closeOnCancel?: boolean\n /**\n * Close the dialog on confirm\n * @default true\n */\n closeOnConfirm?: boolean\n /**\n * Defines which button gets initial focus\n * https://www.w3.org/TR/wai-aria-practices/#alertdialog\n */\n leastDestructiveFocus?: 'cancel' | 'confirm'\n /**\n * Function that's called when cancel is clicked\n */\n onCancel?: () => void\n /**\n * Function that's called when confirm is clicked\n */\n onConfirm?: () => void\n}\n\nexport const ConfirmDialog: React.FC<ConfirmDialogProps> = (props) => {\n const {\n title,\n cancelLabel = 'Cancel',\n confirmLabel = 'Confirm',\n cancelProps,\n confirmProps,\n buttonGroupProps,\n isOpen,\n closeOnCancel = true,\n closeOnConfirm = true,\n leastDestructiveFocus = 'cancel',\n onClose,\n onCancel,\n onConfirm,\n children,\n ...rest\n } = props\n\n const cancelRef = React.useRef(null)\n const confirmRef = React.useRef(null)\n\n return (\n <AlertDialog\n isOpen={isOpen}\n onClose={onClose}\n {...rest}\n leastDestructiveRef={\n leastDestructiveFocus === 'cancel' ? cancelRef : confirmRef\n }\n >\n <AlertDialogOverlay>\n <AlertDialogContent>\n <AlertDialogHeader>{title}</AlertDialogHeader>\n\n <AlertDialogBody>{children}</AlertDialogBody>\n\n <AlertDialogFooter>\n <ButtonGroup {...buttonGroupProps}>\n <Button\n ref={cancelRef}\n {...cancelProps}\n onClick={() => {\n onCancel?.()\n\n closeOnCancel && onClose()\n }}\n >\n {cancelProps?.children || cancelLabel}\n </Button>\n <Button\n ref={confirmRef}\n {...confirmProps}\n onClick={() => {\n onConfirm?.()\n\n closeOnConfirm && onClose()\n }}\n >\n {confirmProps?.children || confirmLabel}\n </Button>\n </ButtonGroup>\n </AlertDialogFooter>\n </AlertDialogContent>\n </AlertDialogOverlay>\n </AlertDialog>\n )\n}\n","import * as React from 'react'\n\nimport {\n Drawer as ChakraDrawer,\n DrawerOverlay,\n DrawerContent,\n DrawerHeader,\n DrawerFooter,\n DrawerBody,\n DrawerCloseButton,\n DrawerProps as ChakraDrawerProps,\n} from '@chakra-ui/react'\n\nexport interface BaseDrawerProps extends Omit<ChakraDrawerProps, 'children'> {\n /**\n * The drawer title\n */\n title: React.ReactNode\n /**\n * Hide the close button\n */\n hideCloseButton?: boolean\n /**\n * Hide the overflow\n */\n hideOverlay?: boolean\n children?: React.ReactNode\n}\n\nexport const BaseDrawer: React.FC<BaseDrawerProps> = (props) => {\n const {\n title,\n children,\n isOpen,\n onClose,\n hideCloseButton,\n hideOverlay,\n ...rest\n } = props\n return (\n <ChakraDrawer isOpen={isOpen} onClose={onClose} {...rest}>\n {!hideOverlay && <DrawerOverlay />}\n <DrawerContent>\n <DrawerHeader>{title}</DrawerHeader>\n {!hideCloseButton && <DrawerCloseButton />}\n {children}\n </DrawerContent>\n </ChakraDrawer>\n )\n}\n\nexport interface DrawerProps extends BaseDrawerProps {\n /**\n * Drawer footer content, wrapped with `DrawerFooter`\n */\n footer?: React.ReactNode\n}\n\nexport const Drawer: React.FC<DrawerProps> = (props) => {\n const { footer, children, ...rest } = props\n return (\n <BaseDrawer {...rest}>\n <DrawerBody>{children}</DrawerBody>\n\n {footer && <DrawerFooter>{footer}</DrawerFooter>}\n </BaseDrawer>\n )\n}\n","import * as React from 'react'\n\nimport {\n Modal as ChakraModal,\n ModalOverlay,\n ModalContent,\n ModalHeader,\n ModalFooter,\n ModalBody,\n ModalCloseButton,\n ModalProps as ChakraModalProps,\n} from '@chakra-ui/react'\n\nexport interface BaseModalProps extends ChakraModalProps {\n /**\n * The modal title\n */\n title?: React.ReactNode\n /**\n * The modal footer\n */\n footer?: React.ReactNode\n /**\n * Hide the close button\n */\n hideCloseButton?: boolean\n /**\n * Hide the overlay\n */\n hideOverlay?: boolean\n}\n\nexport const BaseModal: React.FC<BaseModalProps> = (props) => {\n const {\n title,\n footer,\n children,\n isOpen,\n onClose,\n hideCloseButton,\n hideOverlay,\n ...rest\n } = props\n return (\n <ChakraModal isOpen={isOpen} onClose={onClose} {...rest}>\n {!hideOverlay && <ModalOverlay />}\n <ModalContent>\n {title && <ModalHeader>{title}</ModalHeader>}\n {!hideCloseButton && <ModalCloseButton />}\n {children}\n {footer && <ModalFooter>{footer}</ModalFooter>}\n </ModalContent>\n </ChakraModal>\n )\n}\n\nexport const Modal: React.FC<BaseModalProps> = (props) => {\n const { children, ...rest } = props\n return (\n <BaseModal {...rest}>\n <ModalBody>{children}</ModalBody>\n </BaseModal>\n )\n}\n","import * as React from 'react'\n\nimport {\n ModalFooter,\n chakra,\n forwardRef,\n useMenuContext,\n useMenuList,\n createStylesContext,\n useMultiStyleConfig,\n Menu,\n MenuListProps,\n} from '@chakra-ui/react'\n\nimport { BaseModal, BaseModalProps } from './modal'\n\nconst [StylesProvider] = createStylesContext('SuiMenuDialog')\n\nexport interface MenuDialogProps extends BaseModalProps {\n /**\n * The modal footer, wrapped with `ModalFooter`\n */\n footer?: React.ReactNode\n}\n\nexport const MenuDialog: React.FC<MenuDialogProps> = (props) => {\n const { onClose, onCloseComplete, ...rest } = props\n\n return (\n <Menu\n variant=\"dialog\"\n onClose={() => {\n onClose?.()\n // Not supported in Menu, so we call it here instead\n // @todo Refactor this in v2?\n onCloseComplete?.()\n }}\n {...rest}\n />\n )\n}\n\nexport interface MenuDialogListProps\n extends Omit<\n BaseModalProps,\n 'isOpen' | 'onClose' | 'children' | 'scrollBehavior'\n >,\n Omit<MenuListProps, 'title'> {}\n\nexport const MenuDialogList = forwardRef<MenuDialogListProps, 'div'>(\n (props, forwardedRef) => {\n const {\n rootProps,\n title,\n footer,\n initialFocusRef,\n hideCloseButton,\n motionPreset,\n ...rest\n } = props\n\n const { isOpen, onClose, menuRef } = useMenuContext()\n\n const { ref, ...ownProps } = useMenuList(rest, forwardedRef)\n\n const styles = useMultiStyleConfig('Menu', props)\n\n return (\n <BaseModal\n isOpen={isOpen}\n onClose={onClose}\n initialFocusRef={initialFocusRef || menuRef}\n title={title}\n hideCloseButton={hideCloseButton}\n motionPreset={motionPreset}\n >\n {/* We forward the styles again, otherwise the modal styles will be picked up */}\n <StylesProvider value={styles}>\n <chakra.div\n {...ownProps}\n ref={ref as React.Ref<HTMLDivElement>}\n __css={{\n outline: 0,\n maxHeight: '80vh', // can override this in theme\n overflowY: 'auto', // can override this in theme\n ...styles.list,\n boxShadow: 'none',\n border: 0,\n }}\n />\n </StylesProvider>\n {footer && <ModalFooter>{footer}</ModalFooter>}\n </BaseModal>\n )\n }\n)\n","import * as React from 'react'\n\nimport { ModalBody, ModalFooter, Button, forwardRef } from '@chakra-ui/react'\nimport { runIfFn } from '@saas-ui/react-utils'\n\nimport {\n Form,\n Fields,\n SubmitButton,\n FormProps,\n FieldValues,\n FieldResolver,\n} from '@saas-ui/forms'\n\nimport { BaseModal, BaseModalProps } from './modal'\n\nexport interface FormDialogProps<\n TFieldValues extends FieldValues = FieldValues,\n TContext extends object = object\n> extends Omit<BaseModalProps, 'children'>,\n Pick<\n FormProps<TFieldValues, TContext>,\n | 'schema'\n | 'defaultValues'\n | 'values'\n | 'context'\n | 'onChange'\n | 'onSubmit'\n | 'onError'\n | 'resolver'\n | 'mode'\n | 'reValidateMode'\n | 'shouldFocusError'\n | 'shouldUnregister'\n | 'shouldUseNativeValidation'\n | 'criteriaMode'\n | 'delayError'\n > {\n /**\n * The modal footer, will be wrapped with `ModalFooter`.\n * Defaults to a cancel and submit button.\n */\n footer?: React.ReactNode\n /**\n * The cancel button label\n * @default \"Cancel\"\n */\n cancelLabel?: React.ReactNode\n /**\n * The submit button label\n * @default \"Submit\"\n */\n submitLabel?: React.ReactNode\n /**\n * If no children are passed, this will auto render fields based on the supplied schema.\n */\n children?: React.ReactNode\n /**\n * A schema field resolver used to auto generate form fields.\n */\n fieldResolver?: FieldResolver\n}\n\nexport const FormDialog = forwardRef(\n <\n TFieldValues extends FieldValues = FieldValues,\n TContext extends object = object\n >(\n props: FormDialogProps<TFieldValues, TContext>,\n ref: React.ForwardedRef<HTMLFormElement>\n ) => {\n const {\n children,\n schema,\n resolver,\n fieldResolver,\n defaultValues,\n values,\n context,\n onChange,\n onSubmit,\n onError,\n mode,\n reValidateMode,\n shouldFocusError = true,\n shouldUnregister,\n shouldUseNativeValidation,\n criteriaMode,\n delayError = 100,\n cancelLabel = 'Cancel',\n submitLabel = 'Submit',\n footer,\n isOpen,\n onClose,\n ...rest\n } = props\n\n const formProps = {\n ref,\n schema,\n resolver,\n defaultValues,\n values,\n context,\n onChange,\n onSubmit,\n onError,\n mode,\n reValidateMode,\n shouldFocusError,\n shouldUnregister,\n shouldUseNativeValidation,\n criteriaMode,\n delayError,\n }\n\n return (\n <BaseModal isOpen={isOpen} onClose={onClose} {...rest}>\n <Form {...formProps} ref={ref}>\n {(form) => (\n <>\n <ModalBody>\n {runIfFn(children, form) || (\n <Fields\n schema={schema}\n fieldResolver={fieldResolver}\n focusFirstField\n />\n )}\n </ModalBody>\n\n {footer || (\n <ModalFooter>\n <Button variant=\"ghost\" mr={3} onClick={onClose}>\n {cancelLabel}\n </Button>\n <SubmitButton>{submitLabel}</SubmitButton>\n </ModalFooter>\n )}\n </>\n )}\n </Form>\n </BaseModal>\n )\n }\n) as <TFieldValues extends FieldValues>(\n props: FormDialogProps<TFieldValues> & {\n ref?: React.ForwardedRef<HTMLFormElement>\n }\n) => React.ReactElement\n","import * as React from 'react'\n\nimport { Modal, BaseModalProps } from './modal'\nimport { Drawer, DrawerProps } from './drawer'\nimport { ConfirmDialog, ConfirmDialogProps } from './dialog'\nimport { MenuDialog, MenuDialogProps } from './menu'\nimport { FormDialog, FormDialogProps } from './form'\n\nexport interface ModalsContextValue {\n open: (options: OpenOptions) => ModalId\n drawer: (options: DrawerOptions) => ModalId\n alert: (options: ConfirmDialogOptions) => ModalId\n confirm: (options: ConfirmDialogOptions) => ModalId\n menu: (options: MenuDialogOptions) => ModalId\n form: (options: FormDialogOptions) => ModalId\n close: (id: ModalId) => void\n closeAll: () => void\n}\n\nexport const ModalsContext = React.createContext<ModalsContextValue | null>(\n null\n)\n\ninterface ModalsProviderProps {\n children: React.ReactNode\n modals?: Record<string, React.FC<any>>\n}\n\nexport type ModalId = string | number\n\ninterface ModalOptions\n extends Omit<BaseModalProps, 'onClose' | 'isOpen' | 'children'> {\n onClose?: (args: { force?: boolean }) => Promise<boolean | undefined> | void\n body?: React.ReactNode\n children?: React.ReactNode\n [key: string]: any\n}\n\nexport interface DrawerOptions\n extends ModalOptions,\n Omit<DrawerProps, 'onClose' | 'isOpen' | 'children' | 'title' | 'size'> {}\n\nexport interface ConfirmDialogOptions\n extends ModalOptions,\n Omit<ConfirmDialogProps, 'onClose' | 'isOpen' | 'children'> {}\n\nexport interface MenuDialogOptions\n extends ModalOptions,\n Omit<MenuDialogProps, 'onClose' | 'isOpen' | 'children'> {}\n\nexport interface FormDialogOptions\n extends ModalOptions,\n Omit<FormDialogProps, 'onClose' | 'isOpen' | 'children'> {}\n\nexport interface OpenOptions extends ModalOptions {\n type?: ModalTypes\n scope?: ModalScopes\n}\n\nexport type ModalScopes = 'modal' | 'alert'\n\nexport type ModalTypes =\n | 'modal'\n | 'drawer'\n | 'alert'\n | 'confirm'\n | 'menu'\n | string\n\nexport interface ModalConfig<\n TModalOptions extends ModalOptions = ModalOptions\n> {\n /**\n * The modal id, autogenerated when not set.\n * Can be used to close modals.\n */\n id?: ModalId | null\n /**\n * The modal props\n */\n props?: TModalOptions | null\n /**\n * The modal scope\n * Modals can only have one level per scope.\n * The default scopes are 'modal' and 'alert', alerts can be openend above modals.\n */\n scope?: ModalScopes | string\n /**\n * The modal type to open.\n * Build in types are 'modal', 'drawer', 'alert', 'confirm'\n *\n * Custom types can be configured using the `modals` prop of `ModalProvider`\n */\n type?: ModalTypes\n /**\n * Render a custom modal component.\n * This will ignore the `type` param.\n */\n component?: React.FC<BaseModalProps>\n /**\n * Whether the modal is open or not.\n * This is used internally to keep track of the modal state.\n */\n isOpen?: boolean\n}\n\nconst initialModalState: ModalConfig = {\n id: null,\n props: null,\n type: 'modal',\n}\n\nconst defaultModals = {\n alert: ConfirmDialog,\n confirm: ConfirmDialog,\n drawer: Drawer,\n modal: Modal,\n menu: MenuDialog,\n form: FormDialog,\n}\n\nexport function ModalsProvider({ children, modals }: ModalsProviderProps) {\n // Note that updating the Set doesn't trigger a re-render,\n // use in conjuction with setActiveModals\n const _instances = React.useMemo(() => new Set<ModalConfig>(), [])\n\n const [activeModals, setActiveModals] = React.useState<\n Record<string, ModalConfig>\n >({\n modal: initialModalState,\n })\n\n const getModalComponent = React.useMemo(() => {\n const _modals: Record<string, React.FC<any>> = {\n ...defaultModals,\n ...modals,\n }\n\n return (type: ModalTypes = 'modal') => {\n const component = _modals[type] || _modals.modal\n\n return component\n }\n }, [modals])\n\n const setActiveModal = (modal: ModalConfig, scope?: string) => {\n if (!scope) {\n return setActiveModals({\n modal,\n })\n }\n setActiveModals((prevState) => ({\n ...prevState,\n [scope]: modal,\n }))\n }\n\n const open = <T extends ModalOptions>(\n options: T | React.FC<BaseModalProps>\n ): ModalId => {\n if (typeof options === 'function') {\n const component: React.FC<BaseModalProps> = options\n options = {\n component,\n } as unknown as T\n }\n\n const {\n id = _instances.size + 1,\n type = 'modal',\n scope = 'modal',\n component,\n ...props\n } = options\n\n const modal: ModalConfig<T> = {\n id,\n props: props as T,\n type,\n scope,\n component,\n isOpen: true,\n }\n\n _instances.add(modal)\n setActiveModal(modal, scope)\n\n return id\n }\n\n const drawer = (options: DrawerOptions): ModalId => {\n return open<DrawerOptions>({\n ...options,\n type: 'drawer',\n })\n }\n\n const alert = (options: ConfirmDialogOptions): ModalId => {\n return open({\n ...options,\n scope: 'alert',\n type: 'alert',\n cancelProps: {\n display: 'none',\n },\n confirmProps: {\n label: 'OK',\n },\n leastDestructiveFocus: 'confirm',\n })\n }\n\n const confirm = (options: ConfirmDialogOptions): ModalId => {\n return open<ConfirmDialogOptions>({\n ...options,\n scope: 'alert',\n type: 'confirm',\n })\n }\n\n const menu = (options: MenuDialogOptions): ModalId => {\n return open<MenuDialogOptions>({\n ...options,\n type: 'menu',\n })\n }\n\n const form = (options: FormDialogOptions): ModalId => {\n return open<FormDialogOptions>({\n ...options,\n type: 'form',\n })\n }\n\n const close = async (id?: ModalId | null, force?: boolean) => {\n const modals = [...Array.from(_instances)]\n const modal = modals.filter((modal) => modal.id === id)[0]\n\n if (!modal) {\n return\n }\n\n const shouldClose = await modal.props?.onClose?.({ force })\n if (shouldClose === false) {\n return\n }\n\n const scoped = modals.filter(({ scope }) => scope === modal.scope)\n\n if (scoped.length === 1) {\n setActiveModal(\n {\n ...modal,\n isOpen: false,\n },\n modal.scope\n )\n } else if (scoped.length > 1) {\n setActiveModal(scoped[scoped.length - 2], modal.scope)\n } else {\n setActiveModal(\n {\n id: null,\n props: null,\n type: modal.type, // Keep type same as last modal type to make sure the animation isn't interrupted\n },\n modal.scope\n )\n }\n }\n\n const closeComplete = (id?: ModalId | null) => {\n const modals = [...Array.from(_instances)]\n const modal = modals.filter((modal) => modal.id === id)[0]\n\n _instances.delete(modal)\n\n const scoped = modals.filter(({ scope }) => scope === modal.scope)\n\n if (scoped.length === 1) {\n setActiveModal(initialModalState, modal.scope)\n }\n }\n\n const closeAll = () => {\n _instances.forEach((modal) => modal.props?.onClose?.({ force: true }))\n _instances.clear()\n\n setActiveModal(initialModalState)\n }\n\n const context = {\n open,\n drawer,\n alert,\n confirm,\n menu,\n form,\n close,\n closeAll,\n }\n\n const content = React.useMemo(\n () =>\n Object.entries(activeModals).map(([scope, config]) => {\n const Component = config.component || getModalComponent(config.type)\n\n const { title, body, children, ...props } = config.props || {}\n\n return (\n <Component\n key={scope}\n title={title}\n children={body || children}\n {...props}\n isOpen={!!config.isOpen}\n onClose={() => close(config.id)}\n onCloseComplete={() => closeComplete(config.id)}\n />\n )\n }),\n [activeModals]\n )\n\n return (\n <ModalsContext.Provider value={context}>\n {content}\n {children}\n </ModalsContext.Provider>\n )\n}\n\nexport const useModalsContext = () =>\n React.useContext(ModalsContext) as ModalsContextValue\n\nexport const useModals = () => {\n return useModalsContext()\n}\n"]}
|