UNPKG

16.2 kBJavaScriptView Raw
1"use strict";
2
3var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
4
5var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
6
7Object.defineProperty(exports, "__esModule", {
8 value: true
9});
10exports.default = exports.styles = void 0;
11
12var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
13
14var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
15
16var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
17
18var React = _interopRequireWildcard(require("react"));
19
20var _propTypes = _interopRequireDefault(require("prop-types"));
21
22var _clsx = _interopRequireDefault(require("clsx"));
23
24var _withStyles = _interopRequireDefault(require("../styles/withStyles"));
25
26var _capitalize = _interopRequireDefault(require("../utils/capitalize"));
27
28var _deprecatedPropType = _interopRequireDefault(require("../utils/deprecatedPropType"));
29
30var _Modal = _interopRequireDefault(require("../Modal"));
31
32var _Backdrop = _interopRequireDefault(require("../Backdrop"));
33
34var _Fade = _interopRequireDefault(require("../Fade"));
35
36var _transitions = require("../styles/transitions");
37
38var _Paper = _interopRequireDefault(require("../Paper"));
39
40var styles = function styles(theme) {
41 return {
42 /* Styles applied to the root element. */
43 root: {
44 '@media print': {
45 // Use !important to override the Modal inline-style.
46 position: 'absolute !important'
47 }
48 },
49
50 /* Styles applied to the container element if `scroll="paper"`. */
51 scrollPaper: {
52 display: 'flex',
53 justifyContent: 'center',
54 alignItems: 'center'
55 },
56
57 /* Styles applied to the container element if `scroll="body"`. */
58 scrollBody: {
59 overflowY: 'auto',
60 overflowX: 'hidden',
61 textAlign: 'center',
62 '&:after': {
63 content: '""',
64 display: 'inline-block',
65 verticalAlign: 'middle',
66 height: '100%',
67 width: '0'
68 }
69 },
70
71 /* Styles applied to the container element. */
72 container: {
73 height: '100%',
74 '@media print': {
75 height: 'auto'
76 },
77 // We disable the focus ring for mouse, touch and keyboard users.
78 outline: 0
79 },
80
81 /* Styles applied to the `Paper` component. */
82 paper: {
83 margin: 32,
84 position: 'relative',
85 overflowY: 'auto',
86 // Fix IE 11 issue, to remove at some point.
87 '@media print': {
88 overflowY: 'visible',
89 boxShadow: 'none'
90 }
91 },
92
93 /* Styles applied to the `Paper` component if `scroll="paper"`. */
94 paperScrollPaper: {
95 display: 'flex',
96 flexDirection: 'column',
97 maxHeight: 'calc(100% - 64px)'
98 },
99
100 /* Styles applied to the `Paper` component if `scroll="body"`. */
101 paperScrollBody: {
102 display: 'inline-block',
103 verticalAlign: 'middle',
104 textAlign: 'left' // 'initial' doesn't work on IE 11
105
106 },
107
108 /* Styles applied to the `Paper` component if `maxWidth=false`. */
109 paperWidthFalse: {
110 maxWidth: 'calc(100% - 64px)'
111 },
112
113 /* Styles applied to the `Paper` component if `maxWidth="xs"`. */
114 paperWidthXs: {
115 maxWidth: Math.max(theme.breakpoints.values.xs, 444),
116 '&$paperScrollBody': (0, _defineProperty2.default)({}, theme.breakpoints.down(Math.max(theme.breakpoints.values.xs, 444) + 32 * 2), {
117 maxWidth: 'calc(100% - 64px)'
118 })
119 },
120
121 /* Styles applied to the `Paper` component if `maxWidth="sm"`. */
122 paperWidthSm: {
123 maxWidth: theme.breakpoints.values.sm,
124 '&$paperScrollBody': (0, _defineProperty2.default)({}, theme.breakpoints.down(theme.breakpoints.values.sm + 32 * 2), {
125 maxWidth: 'calc(100% - 64px)'
126 })
127 },
128
129 /* Styles applied to the `Paper` component if `maxWidth="md"`. */
130 paperWidthMd: {
131 maxWidth: theme.breakpoints.values.md,
132 '&$paperScrollBody': (0, _defineProperty2.default)({}, theme.breakpoints.down(theme.breakpoints.values.md + 32 * 2), {
133 maxWidth: 'calc(100% - 64px)'
134 })
135 },
136
137 /* Styles applied to the `Paper` component if `maxWidth="lg"`. */
138 paperWidthLg: {
139 maxWidth: theme.breakpoints.values.lg,
140 '&$paperScrollBody': (0, _defineProperty2.default)({}, theme.breakpoints.down(theme.breakpoints.values.lg + 32 * 2), {
141 maxWidth: 'calc(100% - 64px)'
142 })
143 },
144
145 /* Styles applied to the `Paper` component if `maxWidth="xl"`. */
146 paperWidthXl: {
147 maxWidth: theme.breakpoints.values.xl,
148 '&$paperScrollBody': (0, _defineProperty2.default)({}, theme.breakpoints.down(theme.breakpoints.values.xl + 32 * 2), {
149 maxWidth: 'calc(100% - 64px)'
150 })
151 },
152
153 /* Styles applied to the `Paper` component if `fullWidth={true}`. */
154 paperFullWidth: {
155 width: 'calc(100% - 64px)'
156 },
157
158 /* Styles applied to the `Paper` component if `fullScreen={true}`. */
159 paperFullScreen: {
160 margin: 0,
161 width: '100%',
162 maxWidth: '100%',
163 height: '100%',
164 maxHeight: 'none',
165 borderRadius: 0,
166 '&$paperScrollBody': {
167 margin: 0,
168 maxWidth: '100%'
169 }
170 }
171 };
172};
173
174exports.styles = styles;
175var defaultTransitionDuration = {
176 enter: _transitions.duration.enteringScreen,
177 exit: _transitions.duration.leavingScreen
178};
179/**
180 * Dialogs are overlaid modal paper based components with a backdrop.
181 */
182
183var Dialog = /*#__PURE__*/React.forwardRef(function Dialog(props, ref) {
184 var BackdropProps = props.BackdropProps,
185 children = props.children,
186 classes = props.classes,
187 className = props.className,
188 _props$disableBackdro = props.disableBackdropClick,
189 disableBackdropClick = _props$disableBackdro === void 0 ? false : _props$disableBackdro,
190 _props$disableEscapeK = props.disableEscapeKeyDown,
191 disableEscapeKeyDown = _props$disableEscapeK === void 0 ? false : _props$disableEscapeK,
192 _props$fullScreen = props.fullScreen,
193 fullScreen = _props$fullScreen === void 0 ? false : _props$fullScreen,
194 _props$fullWidth = props.fullWidth,
195 fullWidth = _props$fullWidth === void 0 ? false : _props$fullWidth,
196 _props$maxWidth = props.maxWidth,
197 maxWidth = _props$maxWidth === void 0 ? 'sm' : _props$maxWidth,
198 onBackdropClick = props.onBackdropClick,
199 onClose = props.onClose,
200 onEnter = props.onEnter,
201 onEntered = props.onEntered,
202 onEntering = props.onEntering,
203 onEscapeKeyDown = props.onEscapeKeyDown,
204 onExit = props.onExit,
205 onExited = props.onExited,
206 onExiting = props.onExiting,
207 open = props.open,
208 _props$PaperComponent = props.PaperComponent,
209 PaperComponent = _props$PaperComponent === void 0 ? _Paper.default : _props$PaperComponent,
210 _props$PaperProps = props.PaperProps,
211 PaperProps = _props$PaperProps === void 0 ? {} : _props$PaperProps,
212 _props$scroll = props.scroll,
213 scroll = _props$scroll === void 0 ? 'paper' : _props$scroll,
214 _props$TransitionComp = props.TransitionComponent,
215 TransitionComponent = _props$TransitionComp === void 0 ? _Fade.default : _props$TransitionComp,
216 _props$transitionDura = props.transitionDuration,
217 transitionDuration = _props$transitionDura === void 0 ? defaultTransitionDuration : _props$transitionDura,
218 TransitionProps = props.TransitionProps,
219 ariaDescribedby = props['aria-describedby'],
220 ariaLabelledby = props['aria-labelledby'],
221 other = (0, _objectWithoutProperties2.default)(props, ["BackdropProps", "children", "classes", "className", "disableBackdropClick", "disableEscapeKeyDown", "fullScreen", "fullWidth", "maxWidth", "onBackdropClick", "onClose", "onEnter", "onEntered", "onEntering", "onEscapeKeyDown", "onExit", "onExited", "onExiting", "open", "PaperComponent", "PaperProps", "scroll", "TransitionComponent", "transitionDuration", "TransitionProps", "aria-describedby", "aria-labelledby"]);
222 var mouseDownTarget = React.useRef();
223
224 var handleMouseDown = function handleMouseDown(event) {
225 mouseDownTarget.current = event.target;
226 };
227
228 var handleBackdropClick = function handleBackdropClick(event) {
229 // Ignore the events not coming from the "backdrop"
230 // We don't want to close the dialog when clicking the dialog content.
231 if (event.target !== event.currentTarget) {
232 return;
233 } // Make sure the event starts and ends on the same DOM element.
234
235
236 if (event.target !== mouseDownTarget.current) {
237 return;
238 }
239
240 mouseDownTarget.current = null;
241
242 if (onBackdropClick) {
243 onBackdropClick(event);
244 }
245
246 if (!disableBackdropClick && onClose) {
247 onClose(event, 'backdropClick');
248 }
249 };
250
251 return /*#__PURE__*/React.createElement(_Modal.default, (0, _extends2.default)({
252 className: (0, _clsx.default)(classes.root, className),
253 BackdropComponent: _Backdrop.default,
254 BackdropProps: (0, _extends2.default)({
255 transitionDuration: transitionDuration
256 }, BackdropProps),
257 closeAfterTransition: true
258 }, disableBackdropClick ? {
259 disableBackdropClick: disableBackdropClick
260 } : {}, {
261 disableEscapeKeyDown: disableEscapeKeyDown,
262 onEscapeKeyDown: onEscapeKeyDown,
263 onClose: onClose,
264 open: open,
265 ref: ref
266 }, other), /*#__PURE__*/React.createElement(TransitionComponent, (0, _extends2.default)({
267 appear: true,
268 in: open,
269 timeout: transitionDuration,
270 onEnter: onEnter,
271 onEntering: onEntering,
272 onEntered: onEntered,
273 onExit: onExit,
274 onExiting: onExiting,
275 onExited: onExited,
276 role: "none presentation"
277 }, TransitionProps), /*#__PURE__*/React.createElement("div", {
278 className: (0, _clsx.default)(classes.container, classes["scroll".concat((0, _capitalize.default)(scroll))]),
279 onMouseUp: handleBackdropClick,
280 onMouseDown: handleMouseDown
281 }, /*#__PURE__*/React.createElement(PaperComponent, (0, _extends2.default)({
282 elevation: 24,
283 role: "dialog",
284 "aria-describedby": ariaDescribedby,
285 "aria-labelledby": ariaLabelledby
286 }, PaperProps, {
287 className: (0, _clsx.default)(classes.paper, classes["paperScroll".concat((0, _capitalize.default)(scroll))], classes["paperWidth".concat((0, _capitalize.default)(String(maxWidth)))], PaperProps.className, fullScreen && classes.paperFullScreen, fullWidth && classes.paperFullWidth)
288 }), children))));
289});
290process.env.NODE_ENV !== "production" ? Dialog.propTypes = {
291 // ----------------------------- Warning --------------------------------
292 // | These PropTypes are generated from the TypeScript type definitions |
293 // | To update them edit the d.ts file and run "yarn proptypes" |
294 // ----------------------------------------------------------------------
295
296 /**
297 * The id(s) of the element(s) that describe the dialog.
298 */
299 'aria-describedby': _propTypes.default.string,
300
301 /**
302 * The id(s) of the element(s) that label the dialog.
303 */
304 'aria-labelledby': _propTypes.default.string,
305
306 /**
307 * @ignore
308 */
309 BackdropProps: _propTypes.default.object,
310
311 /**
312 * Dialog children, usually the included sub-components.
313 */
314 children: _propTypes.default.node,
315
316 /**
317 * Override or extend the styles applied to the component.
318 * See [CSS API](#css) below for more details.
319 */
320 classes: _propTypes.default.object,
321
322 /**
323 * @ignore
324 */
325 className: _propTypes.default.string,
326
327 /**
328 * If `true`, clicking the backdrop will not fire the `onClose` callback.
329 * @deprecated Use the onClose prop with the `reason` argument to filter the `backdropClick` events.
330 */
331 disableBackdropClick: (0, _deprecatedPropType.default)(_propTypes.default.bool, 'Use the onClose prop with the `reason` argument to filter the `backdropClick` events.'),
332
333 /**
334 * If `true`, hitting escape will not fire the `onClose` callback.
335 */
336 disableEscapeKeyDown: _propTypes.default.bool,
337
338 /**
339 * If `true`, the dialog will be full-screen
340 */
341 fullScreen: _propTypes.default.bool,
342
343 /**
344 * If `true`, the dialog stretches to `maxWidth`.
345 *
346 * Notice that the dialog width grow is limited by the default margin.
347 */
348 fullWidth: _propTypes.default.bool,
349
350 /**
351 * Determine the max-width of the dialog.
352 * The dialog width grows with the size of the screen.
353 * Set to `false` to disable `maxWidth`.
354 */
355 maxWidth: _propTypes.default.oneOf(['lg', 'md', 'sm', 'xl', 'xs', false]),
356
357 /**
358 * Callback fired when the backdrop is clicked.
359 * @deprecated Use the onClose prop with the `reason` argument to handle the `backdropClick` events.
360 */
361 onBackdropClick: (0, _deprecatedPropType.default)(_propTypes.default.func, 'Use the onClose prop with the `reason` argument to handle the `backdropClick` events.'),
362
363 /**
364 * Callback fired when the component requests to be closed.
365 *
366 * @param {object} event The event source of the callback.
367 * @param {string} reason Can be: `"escapeKeyDown"`, `"backdropClick"`.
368 */
369 onClose: _propTypes.default.func,
370
371 /**
372 * Callback fired before the dialog enters.
373 * @deprecated Use the `TransitionProps` prop instead.
374 */
375 onEnter: (0, _deprecatedPropType.default)(_propTypes.default.func, 'Use the `TransitionProps` prop instead.'),
376
377 /**
378 * Callback fired when the dialog has entered.
379 * @deprecated Use the `TransitionProps` prop instead.
380 */
381 onEntered: (0, _deprecatedPropType.default)(_propTypes.default.func, 'Use the `TransitionProps` prop instead.'),
382
383 /**
384 * Callback fired when the dialog is entering.
385 * @deprecated Use the `TransitionProps` prop instead.
386 */
387 onEntering: (0, _deprecatedPropType.default)(_propTypes.default.func, 'Use the `TransitionProps` prop instead.'),
388
389 /**
390 * Callback fired when the escape key is pressed,
391 * `disableKeyboard` is false and the modal is in focus.
392 * @deprecated Use the onClose prop with the `reason` argument to handle the `escapeKeyDown` events.
393 */
394 onEscapeKeyDown: (0, _deprecatedPropType.default)(_propTypes.default.func, 'Use the onClose prop with the `reason` argument to handle the `escapeKeyDown` events.'),
395
396 /**
397 * Callback fired before the dialog exits.
398 * @deprecated Use the `TransitionProps` prop instead.
399 */
400 onExit: (0, _deprecatedPropType.default)(_propTypes.default.func, 'Use the `TransitionProps` prop instead.'),
401
402 /**
403 * Callback fired when the dialog has exited.
404 * @deprecated Use the `TransitionProps` prop instead.
405 */
406 onExited: (0, _deprecatedPropType.default)(_propTypes.default.func, 'Use the `TransitionProps` prop instead.'),
407
408 /**
409 * Callback fired when the dialog is exiting.
410 * @deprecated Use the `TransitionProps` prop instead.
411 */
412 onExiting: (0, _deprecatedPropType.default)(_propTypes.default.func, 'Use the `TransitionProps` prop instead.'),
413
414 /**
415 * If `true`, the Dialog is open.
416 */
417 open: _propTypes.default.bool.isRequired,
418
419 /**
420 * The component used to render the body of the dialog.
421 */
422 PaperComponent: _propTypes.default.elementType,
423
424 /**
425 * Props applied to the [`Paper`](/api/paper/) element.
426 */
427 PaperProps: _propTypes.default.object,
428
429 /**
430 * Determine the container for scrolling the dialog.
431 */
432 scroll: _propTypes.default.oneOf(['body', 'paper']),
433
434 /**
435 * The component used for the transition.
436 * [Follow this guide](/components/transitions/#transitioncomponent-prop) to learn more about the requirements for this component.
437 */
438 TransitionComponent: _propTypes.default.elementType,
439
440 /**
441 * The duration for the transition, in milliseconds.
442 * You may specify a single timeout for all transitions, or individually with an object.
443 */
444 transitionDuration: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.shape({
445 appear: _propTypes.default.number,
446 enter: _propTypes.default.number,
447 exit: _propTypes.default.number
448 })]),
449
450 /**
451 * Props applied to the [`Transition`](http://reactcommunity.org/react-transition-group/transition#Transition-props) element.
452 */
453 TransitionProps: _propTypes.default.object
454} : void 0;
455
456var _default = (0, _withStyles.default)(styles, {
457 name: 'MuiDialog'
458})(Dialog);
459
460exports.default = _default;
\No newline at end of file