1 | 'use client';
|
2 |
|
3 | import _extends from "@babel/runtime/helpers/esm/extends";
|
4 | import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
5 | const _excluded = ["children", "closeAfterTransition", "container", "disableAutoFocus", "disableEnforceFocus", "disableEscapeKeyDown", "disablePortal", "disableRestoreFocus", "disableScrollLock", "hideBackdrop", "keepMounted", "onBackdropClick", "onClose", "onKeyDown", "open", "onTransitionEnter", "onTransitionExited", "slotProps", "slots"];
|
6 | import * as React from 'react';
|
7 | import PropTypes from 'prop-types';
|
8 | import { elementAcceptingRef, HTMLElementType } from '@mui/utils';
|
9 | import { useSlotProps } from '../utils';
|
10 | import { useClassNamesOverride } from '../utils/ClassNameConfigurator';
|
11 | import { unstable_composeClasses as composeClasses } from '../composeClasses';
|
12 | import { Portal } from '../Portal';
|
13 | import { unstable_useModal as useModal } from '../unstable_useModal';
|
14 | import { FocusTrap } from '../FocusTrap';
|
15 | import { getModalUtilityClass } from './modalClasses';
|
16 | import { jsx as _jsx } from "react/jsx-runtime";
|
17 | import { jsxs as _jsxs } from "react/jsx-runtime";
|
18 | const useUtilityClasses = ownerState => {
|
19 | const {
|
20 | open,
|
21 | exited
|
22 | } = ownerState;
|
23 | const slots = {
|
24 | root: ['root', !open && exited && 'hidden'],
|
25 | backdrop: ['backdrop']
|
26 | };
|
27 | return composeClasses(slots, useClassNamesOverride(getModalUtilityClass));
|
28 | };
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 | const Modal = React.forwardRef(function Modal(props, forwardedRef) {
|
52 | const {
|
53 | children,
|
54 | closeAfterTransition = false,
|
55 | container,
|
56 | disableAutoFocus = false,
|
57 | disableEnforceFocus = false,
|
58 | disableEscapeKeyDown = false,
|
59 | disablePortal = false,
|
60 | disableRestoreFocus = false,
|
61 | disableScrollLock = false,
|
62 | hideBackdrop = false,
|
63 | keepMounted = false,
|
64 | onBackdropClick,
|
65 | open,
|
66 | slotProps = {},
|
67 | slots = {}
|
68 | } = props,
|
69 | other = _objectWithoutPropertiesLoose(props, _excluded);
|
70 | const propsWithDefaults = _extends({}, props, {
|
71 | closeAfterTransition,
|
72 | disableAutoFocus,
|
73 | disableEnforceFocus,
|
74 | disableEscapeKeyDown,
|
75 | disablePortal,
|
76 | disableRestoreFocus,
|
77 | disableScrollLock,
|
78 | hideBackdrop,
|
79 | keepMounted
|
80 | });
|
81 | const {
|
82 | getRootProps,
|
83 | getBackdropProps,
|
84 | getTransitionProps,
|
85 | portalRef,
|
86 | isTopModal,
|
87 | exited,
|
88 | hasTransition
|
89 | } = useModal(_extends({}, propsWithDefaults, {
|
90 | rootRef: forwardedRef
|
91 | }));
|
92 | const ownerState = _extends({}, propsWithDefaults, {
|
93 | exited,
|
94 | hasTransition
|
95 | });
|
96 | const classes = useUtilityClasses(ownerState);
|
97 | const childProps = {};
|
98 | if (children.props.tabIndex === undefined) {
|
99 | childProps.tabIndex = '-1';
|
100 | }
|
101 |
|
102 |
|
103 | if (hasTransition) {
|
104 | const {
|
105 | onEnter,
|
106 | onExited
|
107 | } = getTransitionProps();
|
108 | childProps.onEnter = onEnter;
|
109 | childProps.onExited = onExited;
|
110 | }
|
111 | const Root = slots.root ?? 'div';
|
112 | const rootProps = useSlotProps({
|
113 | elementType: Root,
|
114 | externalSlotProps: slotProps.root,
|
115 | externalForwardedProps: other,
|
116 | getSlotProps: getRootProps,
|
117 | className: classes.root,
|
118 | ownerState
|
119 | });
|
120 | const BackdropComponent = slots.backdrop;
|
121 | const backdropProps = useSlotProps({
|
122 | elementType: BackdropComponent,
|
123 | externalSlotProps: slotProps.backdrop,
|
124 | getSlotProps: otherHandlers => {
|
125 | return getBackdropProps(_extends({}, otherHandlers, {
|
126 | onClick: e => {
|
127 | if (onBackdropClick) {
|
128 | onBackdropClick(e);
|
129 | }
|
130 | if (otherHandlers?.onClick) {
|
131 | otherHandlers.onClick(e);
|
132 | }
|
133 | }
|
134 | }));
|
135 | },
|
136 | className: classes.backdrop,
|
137 | ownerState
|
138 | });
|
139 | if (!keepMounted && !open && (!hasTransition || exited)) {
|
140 | return null;
|
141 | }
|
142 | return _jsx(Portal, {
|
143 | ref: portalRef,
|
144 | container: container,
|
145 | disablePortal: disablePortal,
|
146 | children: _jsxs(Root, _extends({}, rootProps, {
|
147 | children: [!hideBackdrop && BackdropComponent ? _jsx(BackdropComponent, _extends({}, backdropProps)) : null, _jsx(FocusTrap, {
|
148 | disableEnforceFocus: disableEnforceFocus,
|
149 | disableAutoFocus: disableAutoFocus,
|
150 | disableRestoreFocus: disableRestoreFocus,
|
151 | isEnabled: isTopModal,
|
152 | open: open,
|
153 | children: React.cloneElement(children, childProps)
|
154 | })]
|
155 | }))
|
156 | });
|
157 | });
|
158 | process.env.NODE_ENV !== "production" ? Modal.propTypes = {
|
159 |
|
160 |
|
161 |
|
162 |
|
163 | |
164 |
|
165 |
|
166 | children: elementAcceptingRef.isRequired,
|
167 | |
168 |
|
169 |
|
170 |
|
171 | closeAfterTransition: PropTypes.bool,
|
172 | |
173 |
|
174 |
|
175 |
|
176 |
|
177 |
|
178 |
|
179 |
|
180 |
|
181 |
|
182 | container: PropTypes .oneOfType([HTMLElementType, PropTypes.func]),
|
183 | |
184 |
|
185 |
|
186 |
|
187 |
|
188 |
|
189 |
|
190 |
|
191 |
|
192 | disableAutoFocus: PropTypes.bool,
|
193 | |
194 |
|
195 |
|
196 |
|
197 |
|
198 |
|
199 |
|
200 | disableEnforceFocus: PropTypes.bool,
|
201 | |
202 |
|
203 |
|
204 |
|
205 | disableEscapeKeyDown: PropTypes.bool,
|
206 | |
207 |
|
208 |
|
209 |
|
210 | disablePortal: PropTypes.bool,
|
211 | |
212 |
|
213 |
|
214 |
|
215 |
|
216 | disableRestoreFocus: PropTypes.bool,
|
217 | |
218 |
|
219 |
|
220 |
|
221 | disableScrollLock: PropTypes.bool,
|
222 | |
223 |
|
224 |
|
225 |
|
226 | hideBackdrop: PropTypes.bool,
|
227 | |
228 |
|
229 |
|
230 |
|
231 |
|
232 |
|
233 | keepMounted: PropTypes.bool,
|
234 | |
235 |
|
236 |
|
237 |
|
238 | onBackdropClick: PropTypes.func,
|
239 | |
240 |
|
241 |
|
242 |
|
243 |
|
244 |
|
245 |
|
246 | onClose: PropTypes.func,
|
247 | |
248 |
|
249 |
|
250 | onTransitionEnter: PropTypes.func,
|
251 | |
252 |
|
253 |
|
254 | onTransitionExited: PropTypes.func,
|
255 | |
256 |
|
257 |
|
258 | open: PropTypes.bool.isRequired,
|
259 | |
260 |
|
261 |
|
262 |
|
263 | slotProps: PropTypes.shape({
|
264 | backdrop: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
265 | root: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
|
266 | }),
|
267 | |
268 |
|
269 |
|
270 |
|
271 |
|
272 | slots: PropTypes.shape({
|
273 | backdrop: PropTypes.elementType,
|
274 | root: PropTypes.elementType
|
275 | })
|
276 | } : void 0;
|
277 | export { Modal }; |
\ | No newline at end of file |