UNPKG

7.92 kBTypeScriptView Raw
1import * as React from 'react';
2import { SxProps } from '@mui/system';
3import { OverrideProps } from '@mui/types';
4import { SlotComponentProps } from '../utils/types';
5import { PortalProps } from '../Portal';
6import { Theme } from '../styles';
7import Backdrop, { BackdropProps } from '../Backdrop';
8import { OverridableComponent } from '../OverridableComponent';
9import { ModalClasses } from './modalClasses';
10
11export interface ModalComponentsPropsOverrides {}
12
13export interface ModalOwnerState extends ModalProps {
14 exited: boolean;
15}
16
17export interface ModalSlots {
18 /**
19 * The component that renders the root.
20 * @default 'div'
21 */
22 root?: React.ElementType;
23 /**
24 * The component that renders the backdrop.
25 */
26 backdrop?: React.ElementType;
27}
28
29export interface ModalOwnProps {
30 /**
31 * A backdrop component. This prop enables custom backdrop rendering.
32 * @deprecated Use `slots.backdrop` instead. While this prop currently works, it will be removed in the next major version.
33 * Use the `slots.backdrop` prop to make your application ready for the next version of Material UI.
34 * @default styled(Backdrop, {
35 * name: 'MuiModal',
36 * slot: 'Backdrop',
37 * overridesResolver: (props, styles) => {
38 * return styles.backdrop;
39 * },
40 * })({
41 * zIndex: -1,
42 * })
43 */
44 BackdropComponent?: React.ElementType<BackdropProps>;
45 /**
46 * Props applied to the [`Backdrop`](https://mui.com/material-ui/api/backdrop/) element.
47 * @deprecated Use `slotProps.backdrop` instead.
48 */
49 BackdropProps?: Partial<BackdropProps>;
50 /**
51 * A single child content element.
52 */
53 children: React.ReactElement<unknown>;
54 /**
55 * Override or extend the styles applied to the component.
56 */
57 classes?: Partial<ModalClasses>;
58 /**
59 * @ignore
60 */
61 className?: string;
62 /**
63 * When set to true the Modal waits until a nested Transition is completed before closing.
64 * @default false
65 */
66 closeAfterTransition?: boolean;
67 /**
68 * The components used for each slot inside.
69 *
70 * @deprecated Use the `slots` prop instead. This prop will be removed in v7. See [Migrating from deprecated APIs](https://mui.com/material-ui/migration/migrating-from-deprecated-apis/) for more details.
71 *
72 * @default {}
73 */
74 components?: {
75 Root?: React.ElementType;
76 Backdrop?: React.ElementType;
77 };
78 /**
79 * The extra props for the slot components.
80 * You can override the existing props or add new ones.
81 *
82 * @deprecated Use the `slotProps` prop instead. This prop will be removed in v7. See [Migrating from deprecated APIs](https://mui.com/material-ui/migration/migrating-from-deprecated-apis/) for more details.
83 *
84 * @default {}
85 */
86 componentsProps?: {
87 root?: SlotComponentProps<'div', ModalComponentsPropsOverrides, ModalOwnerState>;
88 backdrop?: SlotComponentProps<typeof Backdrop, ModalComponentsPropsOverrides, ModalOwnerState>;
89 };
90 /**
91 * An HTML element or function that returns one.
92 * The `container` will have the portal children appended to it.
93 *
94 * You can also provide a callback, which is called in a React layout effect.
95 * This lets you set the container from a ref, and also makes server-side rendering possible.
96 *
97 * By default, it uses the body of the top-level document object,
98 * so it's simply `document.body` most of the time.
99 */
100 container?: PortalProps['container'];
101 /**
102 * If `true`, the modal will not automatically shift focus to itself when it opens, and
103 * replace it to the last focused element when it closes.
104 * This also works correctly with any modal children that have the `disableAutoFocus` prop.
105 *
106 * Generally this should never be set to `true` as it makes the modal less
107 * accessible to assistive technologies, like screen readers.
108 * @default false
109 */
110 disableAutoFocus?: boolean;
111 /**
112 * If `true`, the modal will not prevent focus from leaving the modal while open.
113 *
114 * Generally this should never be set to `true` as it makes the modal less
115 * accessible to assistive technologies, like screen readers.
116 * @default false
117 */
118 disableEnforceFocus?: boolean;
119 /**
120 * If `true`, hitting escape will not fire the `onClose` callback.
121 * @default false
122 */
123 disableEscapeKeyDown?: boolean;
124 /**
125 * The `children` will be under the DOM hierarchy of the parent component.
126 * @default false
127 */
128 disablePortal?: PortalProps['disablePortal'];
129 /**
130 * If `true`, the modal will not restore focus to previously focused element once
131 * modal is hidden or unmounted.
132 * @default false
133 */
134 disableRestoreFocus?: boolean;
135 /**
136 * Disable the scroll lock behavior.
137 * @default false
138 */
139 disableScrollLock?: boolean;
140 /**
141 * If `true`, the backdrop is not rendered.
142 * @default false
143 */
144 hideBackdrop?: boolean;
145 /**
146 * Always keep the children in the DOM.
147 * This prop can be useful in SEO situation or
148 * when you want to maximize the responsiveness of the Modal.
149 * @default false
150 */
151 keepMounted?: boolean;
152 /**
153 * Callback fired when the backdrop is clicked.
154 * @deprecated Use the `onClose` prop with the `reason` argument to handle the `backdropClick` events.
155 */
156 onBackdropClick?: React.ReactEventHandler<{}>;
157 /**
158 * Callback fired when the component requests to be closed.
159 * The `reason` parameter can optionally be used to control the response to `onClose`.
160 *
161 * @param {object} event The event source of the callback.
162 * @param {string} reason Can be: `"escapeKeyDown"`, `"backdropClick"`.
163 */
164 onClose?: {
165 bivarianceHack(event: {}, reason: 'backdropClick' | 'escapeKeyDown'): void;
166 }['bivarianceHack'];
167 /**
168 * A function called when a transition enters.
169 */
170 onTransitionEnter?: () => void;
171 /**
172 * A function called when a transition has exited.
173 */
174 onTransitionExited?: () => void;
175 /**
176 * If `true`, the component is shown.
177 */
178 open: boolean;
179 /**
180 * The components used for each slot inside the Modal.
181 * Either a string to use a HTML element or a component.
182 * @default {}
183 */
184 slots?: ModalSlots;
185 /**
186 * The props used for each slot inside the Modal.
187 * @default {}
188 */
189 slotProps?: {
190 root?: SlotComponentProps<'div', ModalComponentsPropsOverrides, ModalOwnerState>;
191 backdrop?: SlotComponentProps<typeof Backdrop, ModalComponentsPropsOverrides, ModalOwnerState>;
192 };
193 /**
194 * The system prop that allows defining system overrides as well as additional CSS styles.
195 */
196 sx?: SxProps<Theme>;
197}
198
199export interface ModalTypeMap<
200 RootComponent extends React.ElementType = 'div',
201 AdditionalProps = {},
202> {
203 props: AdditionalProps & ModalOwnProps;
204 defaultComponent: RootComponent;
205}
206
207type ModalRootProps = NonNullable<ModalTypeMap['props']['slotProps']>['root'];
208
209export declare const ModalRoot: React.FC<ModalRootProps>;
210
211/**
212 * Modal is a lower-level construct that is leveraged by the following components:
213 *
214 * * [Dialog](https://mui.com/material-ui/api/dialog/)
215 * * [Drawer](https://mui.com/material-ui/api/drawer/)
216 * * [Menu](https://mui.com/material-ui/api/menu/)
217 * * [Popover](https://mui.com/material-ui/api/popover/)
218 *
219 * If you are creating a modal dialog, you probably want to use the [Dialog](https://mui.com/material-ui/api/dialog/) component
220 * rather than directly using Modal.
221 *
222 * This component shares many concepts with [react-overlays](https://react-bootstrap.github.io/react-overlays/#modals).
223 *
224 * Demos:
225 *
226 * - [Modal](https://mui.com/material-ui/react-modal/)
227 *
228 * API:
229 *
230 * - [Modal API](https://mui.com/material-ui/api/modal/)
231 */
232declare const Modal: OverridableComponent<ModalTypeMap>;
233
234export type ModalProps<
235 RootComponent extends React.ElementType = ModalTypeMap['defaultComponent'],
236 AdditionalProps = {},
237> = OverrideProps<ModalTypeMap<RootComponent, AdditionalProps>, RootComponent> & {
238 component?: React.ElementType;
239};
240
241export default Modal;