UNPKG

6.1 kBTypeScriptView Raw
1import * as React from "react";
2
3export = ReactModal;
4export as namespace ReactModal;
5
6declare namespace ReactModal {
7 interface Styles {
8 content?: React.CSSProperties | undefined;
9 overlay?: React.CSSProperties | undefined;
10 }
11
12 interface Classes {
13 base: string;
14 afterOpen: string;
15 beforeClose: string;
16 }
17
18 interface Aria {
19 /** Defines a string value that labels the current element. */
20 labelledby?: string | undefined;
21 /** Identifies the element (or elements) that describes the object. */
22 describedby?: string | undefined;
23 /** Indicates whether an element is modal when displayed. */
24 modal?: boolean | "false" | "true" | undefined;
25 }
26
27 /** Describes overlay and content element references passed to onAfterOpen function */
28 interface OnAfterOpenCallbackOptions {
29 /** overlay element reference */
30 overlayEl: Element;
31 /** content element reference */
32 contentEl: HTMLDivElement;
33 }
34
35 /** Describes unction that will be run after the modal has opened */
36 interface OnAfterOpenCallback {
37 (obj?: OnAfterOpenCallbackOptions): void;
38 }
39
40 interface Props {
41 children?: React.ReactNode;
42
43 /* Boolean describing if the modal should be shown or not. Defaults to false. */
44 isOpen: boolean;
45
46 /* Object indicating styles to be used for the modal, divided into overlay and content styles. */
47 style?: Styles | undefined;
48
49 /* String className to be applied to the portal. Defaults to "ReactModalPortal". */
50 portalClassName?: string | undefined;
51
52 /* String className to be applied to the document.body (must be a constant string). When set to null it doesn't add any class to document.body. */
53 bodyOpenClassName?: string | null | undefined;
54
55 /* String className to be applied to the document.html (must be a constant string). Defaults to null. */
56 htmlOpenClassName?: string | null | undefined;
57
58 /* String or object className to be applied to the modal content. */
59 className?: string | Classes | undefined;
60
61 /* String or object className to be applied to the overlay. */
62 overlayClassName?: string | Classes | undefined;
63
64 /* Set this to properly hide your application from assistive screenreaders and other assistive technologies while the modal is open. */
65 appElement?: HTMLElement | HTMLElement[] | HTMLCollection | NodeList | undefined;
66
67 /* Function that will be run after the modal has opened. */
68 onAfterOpen?: OnAfterOpenCallback | undefined;
69
70 /* Function that will be run after the modal has closed. */
71 onAfterClose?(): void;
72
73 /* Function that will be run when the modal is requested to be closed, prior to actually closing. */
74 onRequestClose?(event: React.MouseEvent | React.KeyboardEvent): void;
75
76 /* Number indicating the milliseconds to wait before closing the modal. Defaults to zero (no timeout). */
77 closeTimeoutMS?: number | undefined;
78
79 /* Boolean indicating if the appElement should be hidden. Defaults to true. */
80 ariaHideApp?: boolean | undefined;
81
82 /* Boolean indicating if the modal should be focused after render */
83 shouldFocusAfterRender?: boolean | undefined;
84
85 /* Boolean indicating if the overlay should close the modal. Defaults to true. */
86 shouldCloseOnOverlayClick?: boolean | undefined;
87
88 /* Boolean indicating if pressing the esc key should close the modal */
89 shouldCloseOnEsc?: boolean | undefined;
90
91 /* Boolean indicating if the modal should restore focus to the element that had focus prior to its display. */
92 shouldReturnFocusAfterClose?: boolean | undefined;
93
94 /* Boolean indicating if the modal should use the preventScroll flag when restoring focus to the element that had focus prior to its display. */
95 preventScroll?: boolean | undefined;
96
97 /* Function that will be called to get the parent element that the modal will be attached to. */
98 parentSelector?(): HTMLElement;
99
100 /* Additional aria attributes. */
101 aria?: Aria | undefined;
102
103 /* Additional data attributes to be applied to to the modal content in the form of "data-*" */
104 data?: any;
105
106 /* String indicating the role of the modal, allowing the 'dialog' role to be applied if desired. Defaults to "dialog". */
107 role?: string | null | undefined;
108
109 /* String indicating how the content container should be announced to screenreaders. */
110 contentLabel?: string | undefined;
111
112 /* Function accepting the ref for the content */
113 contentRef?: ((instance: HTMLDivElement) => void) | undefined;
114
115 /* Function accepting the ref for the overlay */
116 overlayRef?: ((instance: HTMLDivElement) => void) | undefined;
117
118 /* Custom Overlay element. */
119 overlayElement?:
120 | ((props: React.ComponentPropsWithRef<"div">, contentEl: React.ReactElement) => React.ReactElement)
121 | undefined;
122 /* Custom Content element. */
123 contentElement?:
124 | ((props: React.ComponentPropsWithRef<"div">, children: React.ReactNode) => React.ReactElement)
125 | undefined;
126
127 /* String value of data-test-id attibute to be applied to to the modal content. */
128 testId?: string | undefined;
129
130 /* String value of an id attribute to be applied to the modal content */
131 id?: string | undefined;
132 }
133}
134
135declare class ReactModal extends React.Component<ReactModal.Props> {
136 /* Override base styles for all instances of this component. */
137 static defaultStyles: ReactModal.Styles;
138 /**
139 * Call this to properly hide your application from assistive screenreaders
140 * and other assistive technologies while the modal is open.
141 */
142 static setAppElement(appElement: string | HTMLElement): void;
143
144 portal: null | {
145 overlay: null | HTMLDivElement;
146 content: null | HTMLDivElement;
147 };
148}
149
\No newline at end of file