@saas-ui/modals 1.5.5 → 2.0.0-next.0
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 +13 -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 +11 -9
- 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/CHANGELOG.md
CHANGED
@@ -1,11 +1,21 @@
|
|
1
1
|
# @saas-ui/modals
|
2
2
|
|
3
|
-
##
|
3
|
+
## 2.0.0-next.0
|
4
|
+
|
5
|
+
### Major Changes
|
6
|
+
|
7
|
+
- f1e99198: Restructured packages.
|
4
8
|
|
5
9
|
### Patch Changes
|
6
10
|
|
7
|
-
-
|
8
|
-
|
11
|
+
- f1e99198: Migrated from microbundle to tsup for builds
|
12
|
+
- Updated dependencies [d7c87a31]
|
13
|
+
- Updated dependencies [f1e99198]
|
14
|
+
- Updated dependencies [8b82d945]
|
15
|
+
- Updated dependencies [f1e99198]
|
16
|
+
- @saas-ui/forms@2.0.0-next.0
|
17
|
+
- @saas-ui/hooks@2.0.0-next.0
|
18
|
+
- @saas-ui/react-utils@2.0.0-next.0
|
9
19
|
|
10
20
|
## 1.5.4
|
11
21
|
|
package/dist/index.d.ts
CHANGED
@@ -1,7 +1,218 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
1
|
+
import * as React from 'react';
|
2
|
+
import { AlertDialogProps, ButtonProps, ButtonGroupProps, DrawerProps as DrawerProps$1, ModalProps, MenuListProps } from '@chakra-ui/react';
|
3
|
+
import * as _chakra_ui_system_dist_system_types from '@chakra-ui/system/dist/system.types';
|
4
|
+
import { FieldValues, FormProps, FieldResolver } from '@saas-ui/forms';
|
5
|
+
|
6
|
+
interface ConfirmDialogProps extends Omit<AlertDialogProps, 'leastDestructiveRef'> {
|
7
|
+
/**
|
8
|
+
* The dialog title
|
9
|
+
*/
|
10
|
+
title?: React.ReactNode;
|
11
|
+
/**
|
12
|
+
* The cancel button label
|
13
|
+
*/
|
14
|
+
cancelLabel?: React.ReactNode;
|
15
|
+
/**
|
16
|
+
* The confirm button label
|
17
|
+
*/
|
18
|
+
confirmLabel?: React.ReactNode;
|
19
|
+
/**
|
20
|
+
* The cancel button props
|
21
|
+
*/
|
22
|
+
cancelProps?: ButtonProps;
|
23
|
+
/**
|
24
|
+
* The confirm button props
|
25
|
+
*/
|
26
|
+
confirmProps?: ButtonProps;
|
27
|
+
/**
|
28
|
+
* The button group props
|
29
|
+
*/
|
30
|
+
buttonGroupProps?: ButtonGroupProps;
|
31
|
+
/**
|
32
|
+
* Close the dialog on cancel
|
33
|
+
* @default true
|
34
|
+
*/
|
35
|
+
closeOnCancel?: boolean;
|
36
|
+
/**
|
37
|
+
* Close the dialog on confirm
|
38
|
+
* @default true
|
39
|
+
*/
|
40
|
+
closeOnConfirm?: boolean;
|
41
|
+
/**
|
42
|
+
* Defines which button gets initial focus
|
43
|
+
* https://www.w3.org/TR/wai-aria-practices/#alertdialog
|
44
|
+
*/
|
45
|
+
leastDestructiveFocus?: 'cancel' | 'confirm';
|
46
|
+
/**
|
47
|
+
* Function that's called when cancel is clicked
|
48
|
+
*/
|
49
|
+
onCancel?: () => void;
|
50
|
+
/**
|
51
|
+
* Function that's called when confirm is clicked
|
52
|
+
*/
|
53
|
+
onConfirm?: () => void;
|
54
|
+
}
|
55
|
+
declare const ConfirmDialog: React.FC<ConfirmDialogProps>;
|
56
|
+
|
57
|
+
interface BaseDrawerProps extends Omit<DrawerProps$1, 'children'> {
|
58
|
+
/**
|
59
|
+
* The drawer title
|
60
|
+
*/
|
61
|
+
title: React.ReactNode;
|
62
|
+
/**
|
63
|
+
* Hide the close button
|
64
|
+
*/
|
65
|
+
hideCloseButton?: boolean;
|
66
|
+
/**
|
67
|
+
* Hide the overflow
|
68
|
+
*/
|
69
|
+
hideOverlay?: boolean;
|
70
|
+
children?: React.ReactNode;
|
71
|
+
}
|
72
|
+
declare const BaseDrawer: React.FC<BaseDrawerProps>;
|
73
|
+
interface DrawerProps extends BaseDrawerProps {
|
74
|
+
/**
|
75
|
+
* Drawer footer content, wrapped with `DrawerFooter`
|
76
|
+
*/
|
77
|
+
footer?: React.ReactNode;
|
78
|
+
}
|
79
|
+
declare const Drawer: React.FC<DrawerProps>;
|
80
|
+
|
81
|
+
interface BaseModalProps extends ModalProps {
|
82
|
+
/**
|
83
|
+
* The modal title
|
84
|
+
*/
|
85
|
+
title?: React.ReactNode;
|
86
|
+
/**
|
87
|
+
* The modal footer
|
88
|
+
*/
|
89
|
+
footer?: React.ReactNode;
|
90
|
+
/**
|
91
|
+
* Hide the close button
|
92
|
+
*/
|
93
|
+
hideCloseButton?: boolean;
|
94
|
+
/**
|
95
|
+
* Hide the overlay
|
96
|
+
*/
|
97
|
+
hideOverlay?: boolean;
|
98
|
+
}
|
99
|
+
declare const BaseModal: React.FC<BaseModalProps>;
|
100
|
+
declare const Modal: React.FC<BaseModalProps>;
|
101
|
+
|
102
|
+
interface MenuDialogProps extends BaseModalProps {
|
103
|
+
/**
|
104
|
+
* The modal footer, wrapped with `ModalFooter`
|
105
|
+
*/
|
106
|
+
footer?: React.ReactNode;
|
107
|
+
}
|
108
|
+
declare const MenuDialog: React.FC<MenuDialogProps>;
|
109
|
+
interface MenuDialogListProps extends Omit<BaseModalProps, 'isOpen' | 'onClose' | 'children' | 'scrollBehavior'>, Omit<MenuListProps, 'title'> {
|
110
|
+
}
|
111
|
+
declare const MenuDialogList: _chakra_ui_system_dist_system_types.ComponentWithAs<"div", MenuDialogListProps>;
|
112
|
+
|
113
|
+
interface FormDialogProps<TFieldValues extends FieldValues = FieldValues, TContext extends object = object> extends Omit<BaseModalProps, 'children'>, Pick<FormProps<TFieldValues, TContext>, 'schema' | 'defaultValues' | 'values' | 'context' | 'onChange' | 'onSubmit' | 'onError' | 'resolver' | 'mode' | 'reValidateMode' | 'shouldFocusError' | 'shouldUnregister' | 'shouldUseNativeValidation' | 'criteriaMode' | 'delayError'> {
|
114
|
+
/**
|
115
|
+
* The modal footer, will be wrapped with `ModalFooter`.
|
116
|
+
* Defaults to a cancel and submit button.
|
117
|
+
*/
|
118
|
+
footer?: React.ReactNode;
|
119
|
+
/**
|
120
|
+
* The cancel button label
|
121
|
+
* @default "Cancel"
|
122
|
+
*/
|
123
|
+
cancelLabel?: React.ReactNode;
|
124
|
+
/**
|
125
|
+
* The submit button label
|
126
|
+
* @default "Submit"
|
127
|
+
*/
|
128
|
+
submitLabel?: React.ReactNode;
|
129
|
+
/**
|
130
|
+
* If no children are passed, this will auto render fields based on the supplied schema.
|
131
|
+
*/
|
132
|
+
children?: React.ReactNode;
|
133
|
+
/**
|
134
|
+
* A schema field resolver used to auto generate form fields.
|
135
|
+
*/
|
136
|
+
fieldResolver?: FieldResolver;
|
137
|
+
}
|
138
|
+
declare const FormDialog: <TFieldValues extends FieldValues>(props: FormDialogProps<TFieldValues, object> & {
|
139
|
+
ref?: React.ForwardedRef<HTMLFormElement> | undefined;
|
140
|
+
}) => React.ReactElement;
|
141
|
+
|
142
|
+
interface ModalsContextValue {
|
143
|
+
open: (options: OpenOptions) => ModalId;
|
144
|
+
drawer: (options: DrawerOptions) => ModalId;
|
145
|
+
alert: (options: ConfirmDialogOptions) => ModalId;
|
146
|
+
confirm: (options: ConfirmDialogOptions) => ModalId;
|
147
|
+
menu: (options: MenuDialogOptions) => ModalId;
|
148
|
+
form: (options: FormDialogOptions) => ModalId;
|
149
|
+
close: (id: ModalId) => void;
|
150
|
+
closeAll: () => void;
|
151
|
+
}
|
152
|
+
declare const ModalsContext: React.Context<ModalsContextValue | null>;
|
153
|
+
interface ModalsProviderProps {
|
154
|
+
children: React.ReactNode;
|
155
|
+
modals?: Record<string, React.FC<any>>;
|
156
|
+
}
|
157
|
+
type ModalId = string | number;
|
158
|
+
interface ModalOptions extends Omit<BaseModalProps, 'onClose' | 'isOpen' | 'children'> {
|
159
|
+
onClose?: (args: {
|
160
|
+
force?: boolean;
|
161
|
+
}) => Promise<boolean | undefined> | void;
|
162
|
+
body?: React.ReactNode;
|
163
|
+
children?: React.ReactNode;
|
164
|
+
[key: string]: any;
|
165
|
+
}
|
166
|
+
interface DrawerOptions extends ModalOptions, Omit<DrawerProps, 'onClose' | 'isOpen' | 'children' | 'title' | 'size'> {
|
167
|
+
}
|
168
|
+
interface ConfirmDialogOptions extends ModalOptions, Omit<ConfirmDialogProps, 'onClose' | 'isOpen' | 'children'> {
|
169
|
+
}
|
170
|
+
interface MenuDialogOptions extends ModalOptions, Omit<MenuDialogProps, 'onClose' | 'isOpen' | 'children'> {
|
171
|
+
}
|
172
|
+
interface FormDialogOptions extends ModalOptions, Omit<FormDialogProps, 'onClose' | 'isOpen' | 'children'> {
|
173
|
+
}
|
174
|
+
interface OpenOptions extends ModalOptions {
|
175
|
+
type?: ModalTypes;
|
176
|
+
scope?: ModalScopes;
|
177
|
+
}
|
178
|
+
type ModalScopes = 'modal' | 'alert';
|
179
|
+
type ModalTypes = 'modal' | 'drawer' | 'alert' | 'confirm' | 'menu' | string;
|
180
|
+
interface ModalConfig<TModalOptions extends ModalOptions = ModalOptions> {
|
181
|
+
/**
|
182
|
+
* The modal id, autogenerated when not set.
|
183
|
+
* Can be used to close modals.
|
184
|
+
*/
|
185
|
+
id?: ModalId | null;
|
186
|
+
/**
|
187
|
+
* The modal props
|
188
|
+
*/
|
189
|
+
props?: TModalOptions | null;
|
190
|
+
/**
|
191
|
+
* The modal scope
|
192
|
+
* Modals can only have one level per scope.
|
193
|
+
* The default scopes are 'modal' and 'alert', alerts can be openend above modals.
|
194
|
+
*/
|
195
|
+
scope?: ModalScopes | string;
|
196
|
+
/**
|
197
|
+
* The modal type to open.
|
198
|
+
* Build in types are 'modal', 'drawer', 'alert', 'confirm'
|
199
|
+
*
|
200
|
+
* Custom types can be configured using the `modals` prop of `ModalProvider`
|
201
|
+
*/
|
202
|
+
type?: ModalTypes;
|
203
|
+
/**
|
204
|
+
* Render a custom modal component.
|
205
|
+
* This will ignore the `type` param.
|
206
|
+
*/
|
207
|
+
component?: React.FC<BaseModalProps>;
|
208
|
+
/**
|
209
|
+
* Whether the modal is open or not.
|
210
|
+
* This is used internally to keep track of the modal state.
|
211
|
+
*/
|
212
|
+
isOpen?: boolean;
|
213
|
+
}
|
214
|
+
declare function ModalsProvider({ children, modals }: ModalsProviderProps): JSX.Element;
|
215
|
+
declare const useModalsContext: () => ModalsContextValue;
|
216
|
+
declare const useModals: () => ModalsContextValue;
|
217
|
+
|
218
|
+
export { BaseDrawer, BaseDrawerProps, BaseModal, BaseModalProps, ConfirmDialog, ConfirmDialogOptions, ConfirmDialogProps, Drawer, DrawerOptions, DrawerProps, FormDialog, FormDialogOptions, FormDialogProps, MenuDialog, MenuDialogList, MenuDialogListProps, MenuDialogOptions, MenuDialogProps, Modal, ModalConfig, ModalId, ModalScopes, ModalTypes, ModalsContext, ModalsContextValue, ModalsProvider, OpenOptions, useModals, useModalsContext };
|
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
|