UNPKG

5.65 kBTypeScriptView Raw
1import * as React from 'react';
2import { Simplify } from '@mui/types';
3import { PortalProps } from '../Portal';
4import { PolymorphicProps, SlotComponentProps } from '../utils';
5export interface ModalRootSlotPropsOverrides {
6}
7export interface ModalBackdropSlotPropsOverrides {
8}
9export interface ModalOwnProps {
10 /**
11 * A single child content element.
12 */
13 children: React.ReactElement;
14 /**
15 * When set to true the Modal waits until a nested Transition is completed before closing.
16 * @default false
17 */
18 closeAfterTransition?: boolean;
19 /**
20 * An HTML element or function that returns one.
21 * The `container` will have the portal children appended to it.
22 *
23 * You can also provide a callback, which is called in a React layout effect.
24 * This lets you set the container from a ref, and also makes server-side rendering possible.
25 *
26 * By default, it uses the body of the top-level document object,
27 * so it's simply `document.body` most of the time.
28 */
29 container?: PortalProps['container'];
30 /**
31 * If `true`, the modal will not automatically shift focus to itself when it opens, and
32 * replace it to the last focused element when it closes.
33 * This also works correctly with any modal children that have the `disableAutoFocus` prop.
34 *
35 * Generally this should never be set to `true` as it makes the modal less
36 * accessible to assistive technologies, like screen readers.
37 * @default false
38 */
39 disableAutoFocus?: boolean;
40 /**
41 * If `true`, the modal will not prevent focus from leaving the modal while open.
42 *
43 * Generally this should never be set to `true` as it makes the modal less
44 * accessible to assistive technologies, like screen readers.
45 * @default false
46 */
47 disableEnforceFocus?: boolean;
48 /**
49 * If `true`, hitting escape will not fire the `onClose` callback.
50 * @default false
51 */
52 disableEscapeKeyDown?: boolean;
53 /**
54 * The `children` will be under the DOM hierarchy of the parent component.
55 * @default false
56 */
57 disablePortal?: PortalProps['disablePortal'];
58 /**
59 * If `true`, the modal will not restore focus to previously focused element once
60 * modal is hidden or unmounted.
61 * @default false
62 */
63 disableRestoreFocus?: boolean;
64 /**
65 * Disable the scroll lock behavior.
66 * @default false
67 */
68 disableScrollLock?: boolean;
69 /**
70 * If `true`, the backdrop is not rendered.
71 * @default false
72 */
73 hideBackdrop?: boolean;
74 /**
75 * Always keep the children in the DOM.
76 * This prop can be useful in SEO situation or
77 * when you want to maximize the responsiveness of the Modal.
78 * @default false
79 */
80 keepMounted?: boolean;
81 /**
82 * Callback fired when the backdrop is clicked.
83 * @deprecated Use the `onClose` prop with the `reason` argument to handle the `backdropClick` events.
84 */
85 onBackdropClick?: React.ReactEventHandler<{}>;
86 /**
87 * Callback fired when the component requests to be closed.
88 * The `reason` parameter can optionally be used to control the response to `onClose`.
89 *
90 * @param {object} event The event source of the callback.
91 * @param {string} reason Can be: `"escapeKeyDown"`, `"backdropClick"`.
92 */
93 onClose?: {
94 bivarianceHack(event: {}, reason: 'backdropClick' | 'escapeKeyDown'): void;
95 }['bivarianceHack'];
96 /**
97 * A function called when a transition enters.
98 */
99 onTransitionEnter?: () => void;
100 /**
101 * A function called when a transition has exited.
102 */
103 onTransitionExited?: () => void;
104 /**
105 * If `true`, the component is shown.
106 */
107 open: boolean;
108 /**
109 * The props used for each slot inside the Modal.
110 * @default {}
111 */
112 slotProps?: {
113 root?: SlotComponentProps<'div', ModalRootSlotPropsOverrides, ModalOwnerState>;
114 backdrop?: SlotComponentProps<'div', ModalBackdropSlotPropsOverrides, ModalOwnerState>;
115 };
116 /**
117 * The components used for each slot inside the Modal.
118 * Either a string to use a HTML element or a component.
119 * @default {}
120 */
121 slots?: ModalSlots;
122}
123export interface ModalSlots {
124 /**
125 * The component that renders the root.
126 * @default 'div'
127 */
128 root?: React.ElementType;
129 /**
130 * The component that renders the backdrop.
131 */
132 backdrop?: React.ElementType;
133}
134export interface ModalTypeMap<AdditionalProps = {}, RootComponentType extends React.ElementType = 'div'> {
135 props: ModalOwnProps & AdditionalProps;
136 defaultComponent: RootComponentType;
137}
138export type ModalProps<RootComponentType extends React.ElementType = ModalTypeMap['defaultComponent']> = PolymorphicProps<ModalTypeMap<{}, RootComponentType>, RootComponentType>;
139export type ModalOwnerState = Simplify<ModalOwnProps & {
140 closeAfterTransition: boolean;
141 disableAutoFocus: boolean;
142 disableEnforceFocus: boolean;
143 disableEscapeKeyDown: boolean;
144 disablePortal: boolean;
145 disableRestoreFocus: boolean;
146 disableScrollLock: boolean;
147 exited: boolean;
148 hideBackdrop: boolean;
149 keepMounted: boolean;
150}>;
151export interface ModalRootSlotProps {
152 children: React.ReactNode;
153 className?: string;
154 onKeyDown: React.KeyboardEventHandler;
155 ownerState: ModalOwnerState;
156 role: React.AriaRole;
157}
158export interface ModalBackdropSlotProps {
159 'aria-hidden': React.AriaAttributes['aria-hidden'];
160 children?: React.ReactNode;
161 onClick: React.MouseEventHandler;
162 open: boolean;
163 ownerState: ModalOwnerState;
164}