UNPKG

4.08 kBTypeScriptView Raw
1import { PortalProps } from '../Portal';
2import { EventHandlers } from '../utils/types';
3export interface UseModalRootSlotOwnProps {
4 role: React.AriaRole;
5 onKeyDown: React.KeyboardEventHandler;
6 ref: React.RefCallback<Element> | null;
7}
8export interface UseModalBackdropSlotOwnProps {
9 'aria-hidden': React.AriaAttributes['aria-hidden'];
10 onClick: React.MouseEventHandler;
11 open?: boolean;
12}
13export type UseModalBackdropSlotProps<TOther = {}> = TOther & UseModalBackdropSlotOwnProps;
14export type UseModalRootSlotProps<TOther = {}> = TOther & UseModalRootSlotOwnProps;
15export type UseModalParameters = {
16 'aria-hidden'?: React.AriaAttributes['aria-hidden'];
17 /**
18 * A single child content element.
19 */
20 children: React.ReactElement<any> | undefined | null;
21 /**
22 * When set to true the Modal waits until a nested Transition is completed before closing.
23 * @default false
24 */
25 closeAfterTransition?: boolean;
26 /**
27 * An HTML element or function that returns one.
28 * The `container` will have the portal children appended to it.
29 *
30 * You can also provide a callback, which is called in a React layout effect.
31 * This lets you set the container from a ref, and also makes server-side rendering possible.
32 *
33 * By default, it uses the body of the top-level document object,
34 * so it's simply `document.body` most of the time.
35 */
36 container?: PortalProps['container'];
37 /**
38 * If `true`, hitting escape will not fire the `onClose` callback.
39 * @default false
40 */
41 disableEscapeKeyDown?: boolean;
42 /**
43 * Disable the scroll lock behavior.
44 * @default false
45 */
46 disableScrollLock?: boolean;
47 /**
48 * Callback fired when the component requests to be closed.
49 * The `reason` parameter can optionally be used to control the response to `onClose`.
50 *
51 * @param {object} event The event source of the callback.
52 * @param {string} reason Can be: `"escapeKeyDown"`, `"backdropClick"`.
53 */
54 onClose?: {
55 bivarianceHack(event: {}, reason: 'backdropClick' | 'escapeKeyDown'): void;
56 }['bivarianceHack'];
57 onKeyDown?: React.KeyboardEventHandler;
58 /**
59 * A function called when a transition enters.
60 */
61 onTransitionEnter?: () => void;
62 /**
63 * A function called when a transition has exited.
64 */
65 onTransitionExited?: () => void;
66 /**
67 * If `true`, the component is shown.
68 */
69 open: boolean;
70 rootRef: React.Ref<Element>;
71};
72export interface UseModalReturnValue {
73 /**
74 * Resolver for the root slot's props.
75 * @param externalProps props for the root slot
76 * @returns props that should be spread on the root slot
77 */
78 getRootProps: <TOther extends EventHandlers = {}>(externalProps?: TOther) => UseModalRootSlotProps<TOther>;
79 /**
80 * Resolver for the backdrop slot's props.
81 * @param externalProps props for the backdrop slot
82 * @returns props that should be spread on the backdrop slot
83 */
84 getBackdropProps: <TOther extends EventHandlers = {}>(externalProps?: TOther) => UseModalBackdropSlotProps<TOther>;
85 /**
86 * Resolver for the transition related props.
87 * @param externalProps props for the transition element
88 * @returns props that should be spread on the transition element
89 */
90 getTransitionProps: <TOther extends EventHandlers = {}>(externalProps?: TOther) => {
91 onEnter: () => void;
92 onExited: () => void;
93 };
94 /**
95 * A ref to the component's root DOM element.
96 */
97 rootRef: React.RefCallback<Element> | null;
98 /**
99 * A ref to the component's portal DOM element.
100 */
101 portalRef: React.RefCallback<Element> | null;
102 /**
103 * If `true`, the modal is the top most one.
104 */
105 isTopModal: () => boolean;
106 /**
107 * If `true`, the exiting transition finished (to be used for unmounting the component).
108 */
109 exited: boolean;
110 /**
111 * If `true`, the component's child is transition component.
112 */
113 hasTransition: boolean;
114}