"use strict"; 'use client'; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.Modal = void 0; var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose")); var React = _interopRequireWildcard(require("react")); var _propTypes = _interopRequireDefault(require("prop-types")); var _utils = require("@mui/utils"); var _utils2 = require("../utils"); var _ClassNameConfigurator = require("../utils/ClassNameConfigurator"); var _composeClasses = require("../composeClasses"); var _Portal = require("../Portal"); var _unstable_useModal = require("../unstable_useModal"); var _FocusTrap = require("../FocusTrap"); var _modalClasses = require("./modalClasses"); var _jsxRuntime = require("react/jsx-runtime"); const _excluded = ["children", "closeAfterTransition", "container", "disableAutoFocus", "disableEnforceFocus", "disableEscapeKeyDown", "disablePortal", "disableRestoreFocus", "disableScrollLock", "hideBackdrop", "keepMounted", "onBackdropClick", "onClose", "onKeyDown", "open", "onTransitionEnter", "onTransitionExited", "slotProps", "slots"]; function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); } function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; } const useUtilityClasses = ownerState => { const { open, exited } = ownerState; const slots = { root: ['root', !open && exited && 'hidden'], backdrop: ['backdrop'] }; return (0, _composeClasses.unstable_composeClasses)(slots, (0, _ClassNameConfigurator.useClassNamesOverride)(_modalClasses.getModalUtilityClass)); }; /** * Modal is a lower-level construct that is leveraged by the following components: * * * [Dialog](https://mui.com/material-ui/api/dialog/) * * [Drawer](https://mui.com/material-ui/api/drawer/) * * [Menu](https://mui.com/material-ui/api/menu/) * * [Popover](https://mui.com/material-ui/api/popover/) * * If you are creating a modal dialog, you probably want to use the [Dialog](https://mui.com/material-ui/api/dialog/) component * rather than directly using Modal. * * This component shares many concepts with [react-overlays](https://react-bootstrap.github.io/react-overlays/#modals). * * Demos: * * - [Modal](https://mui.com/base-ui/react-modal/) * * API: * * - [Modal API](https://mui.com/base-ui/react-modal/components-api/#modal) */ const Modal = exports.Modal = /*#__PURE__*/React.forwardRef(function Modal(props, forwardedRef) { var _slots$root; const { children, closeAfterTransition = false, container, disableAutoFocus = false, disableEnforceFocus = false, disableEscapeKeyDown = false, disablePortal = false, disableRestoreFocus = false, disableScrollLock = false, hideBackdrop = false, keepMounted = false, onBackdropClick, open, slotProps = {}, slots = {} } = props, other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded); const propsWithDefaults = (0, _extends2.default)({}, props, { closeAfterTransition, disableAutoFocus, disableEnforceFocus, disableEscapeKeyDown, disablePortal, disableRestoreFocus, disableScrollLock, hideBackdrop, keepMounted }); const { getRootProps, getBackdropProps, getTransitionProps, portalRef, isTopModal, exited, hasTransition } = (0, _unstable_useModal.unstable_useModal)((0, _extends2.default)({}, propsWithDefaults, { rootRef: forwardedRef })); const ownerState = (0, _extends2.default)({}, propsWithDefaults, { exited, hasTransition }); const classes = useUtilityClasses(ownerState); const childProps = {}; if (children.props.tabIndex === undefined) { childProps.tabIndex = '-1'; } // It's a Transition like component if (hasTransition) { const { onEnter, onExited } = getTransitionProps(); childProps.onEnter = onEnter; childProps.onExited = onExited; } const Root = (_slots$root = slots.root) != null ? _slots$root : 'div'; const rootProps = (0, _utils2.useSlotProps)({ elementType: Root, externalSlotProps: slotProps.root, externalForwardedProps: other, getSlotProps: getRootProps, className: classes.root, ownerState }); const BackdropComponent = slots.backdrop; const backdropProps = (0, _utils2.useSlotProps)({ elementType: BackdropComponent, externalSlotProps: slotProps.backdrop, getSlotProps: otherHandlers => { return getBackdropProps((0, _extends2.default)({}, otherHandlers, { onClick: e => { if (onBackdropClick) { onBackdropClick(e); } if (otherHandlers != null && otherHandlers.onClick) { otherHandlers.onClick(e); } } })); }, className: classes.backdrop, ownerState }); if (!keepMounted && !open && (!hasTransition || exited)) { return null; } return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Portal.Portal, { ref: portalRef, container: container, disablePortal: disablePortal, children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(Root, (0, _extends2.default)({}, rootProps, { children: [!hideBackdrop && BackdropComponent ? /*#__PURE__*/(0, _jsxRuntime.jsx)(BackdropComponent, (0, _extends2.default)({}, backdropProps)) : null, /*#__PURE__*/(0, _jsxRuntime.jsx)(_FocusTrap.FocusTrap, { disableEnforceFocus: disableEnforceFocus, disableAutoFocus: disableAutoFocus, disableRestoreFocus: disableRestoreFocus, isEnabled: isTopModal, open: open, children: /*#__PURE__*/React.cloneElement(children, childProps) })] })) }); }); process.env.NODE_ENV !== "production" ? Modal.propTypes /* remove-proptypes */ = { // ┌────────────────────────────── Warning ──────────────────────────────┐ // │ These PropTypes are generated from the TypeScript type definitions. │ // │ To update them, edit the TypeScript types and run `pnpm proptypes`. │ // └─────────────────────────────────────────────────────────────────────┘ /** * A single child content element. */ children: _utils.elementAcceptingRef.isRequired, /** * When set to true the Modal waits until a nested Transition is completed before closing. * @default false */ closeAfterTransition: _propTypes.default.bool, /** * An HTML element or function that returns one. * The `container` will have the portal children appended to it. * * You can also provide a callback, which is called in a React layout effect. * This lets you set the container from a ref, and also makes server-side rendering possible. * * By default, it uses the body of the top-level document object, * so it's simply `document.body` most of the time. */ container: _propTypes.default /* @typescript-to-proptypes-ignore */.oneOfType([_utils.HTMLElementType, _propTypes.default.func]), /** * If `true`, the modal will not automatically shift focus to itself when it opens, and * replace it to the last focused element when it closes. * This also works correctly with any modal children that have the `disableAutoFocus` prop. * * Generally this should never be set to `true` as it makes the modal less * accessible to assistive technologies, like screen readers. * @default false */ disableAutoFocus: _propTypes.default.bool, /** * If `true`, the modal will not prevent focus from leaving the modal while open. * * Generally this should never be set to `true` as it makes the modal less * accessible to assistive technologies, like screen readers. * @default false */ disableEnforceFocus: _propTypes.default.bool, /** * If `true`, hitting escape will not fire the `onClose` callback. * @default false */ disableEscapeKeyDown: _propTypes.default.bool, /** * The `children` will be under the DOM hierarchy of the parent component. * @default false */ disablePortal: _propTypes.default.bool, /** * If `true`, the modal will not restore focus to previously focused element once * modal is hidden or unmounted. * @default false */ disableRestoreFocus: _propTypes.default.bool, /** * Disable the scroll lock behavior. * @default false */ disableScrollLock: _propTypes.default.bool, /** * If `true`, the backdrop is not rendered. * @default false */ hideBackdrop: _propTypes.default.bool, /** * Always keep the children in the DOM. * This prop can be useful in SEO situation or * when you want to maximize the responsiveness of the Modal. * @default false */ keepMounted: _propTypes.default.bool, /** * Callback fired when the backdrop is clicked. * @deprecated Use the `onClose` prop with the `reason` argument to handle the `backdropClick` events. */ onBackdropClick: _propTypes.default.func, /** * Callback fired when the component requests to be closed. * The `reason` parameter can optionally be used to control the response to `onClose`. * * @param {object} event The event source of the callback. * @param {string} reason Can be: `"escapeKeyDown"`, `"backdropClick"`. */ onClose: _propTypes.default.func, /** * A function called when a transition enters. */ onTransitionEnter: _propTypes.default.func, /** * A function called when a transition has exited. */ onTransitionExited: _propTypes.default.func, /** * If `true`, the component is shown. */ open: _propTypes.default.bool.isRequired, /** * The props used for each slot inside the Modal. * @default {} */ slotProps: _propTypes.default.shape({ backdrop: _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.object]), root: _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.object]) }), /** * The components used for each slot inside the Modal. * Either a string to use a HTML element or a component. * @default {} */ slots: _propTypes.default.shape({ backdrop: _propTypes.default.elementType, root: _propTypes.default.elementType }) } : void 0;