UNPKG

3.36 kBTypeScriptView Raw
1import React from 'react';
2export interface ModalProps {
3 /**
4 * Control if the modal is open or not.
5 */
6 open: boolean;
7 /**
8 * Should the dialog be centered.
9 *
10 * Default to false.
11 */
12 center?: boolean;
13 /**
14 * Is the modal closable when user press esc key.
15 *
16 * Default to true.
17 */
18 closeOnEsc?: boolean;
19 /**
20 * Is the modal closable when user click on overlay.
21 *
22 * Default to true.
23 */
24 closeOnOverlayClick?: boolean;
25 /**
26 * Whether to block scrolling when dialog is open.
27 *
28 * Default to true.
29 */
30 blockScroll?: boolean;
31 /**
32 * Show the close icon.
33 */
34 showCloseIcon?: boolean;
35 /**
36 * id attribute for the close icon button.
37 */
38 closeIconId?: string;
39 /**
40 * Custom icon to render (svg, img, etc...).
41 */
42 closeIcon?: React.ReactNode;
43 /**
44 * When the modal is open, trap focus within it.
45 *
46 * Default to true.
47 */
48 focusTrapped?: boolean;
49 /**
50 * You can specify a container prop which should be of type `Element`.
51 * The portal will be rendered inside that element.
52 * The default behavior will create a div node and render it at the at the end of document.body.
53 */
54 container?: Element;
55 /**
56 * An object containing classNames to style the modal.
57 */
58 classNames?: {
59 overlay?: string;
60 modal?: string;
61 closeButton?: string;
62 closeIcon?: string;
63 animationIn?: string;
64 animationOut?: string;
65 };
66 /**
67 * An object containing the styles objects to style the modal.
68 */
69 styles?: {
70 overlay?: React.CSSProperties;
71 modal?: React.CSSProperties;
72 closeButton?: React.CSSProperties;
73 closeIcon?: React.CSSProperties;
74 };
75 /**
76 * Animation duration in milliseconds.
77 *
78 * Default to 500.
79 */
80 animationDuration?: number;
81 /**
82 * ARIA role for modal
83 *
84 * Default to 'dialog'.
85 */
86 role?: string;
87 /**
88 * ARIA label for modal
89 */
90 ariaLabelledby?: string;
91 /**
92 * ARIA description for modal
93 */
94 ariaDescribedby?: string;
95 /**
96 * id attribute for modal
97 */
98 modalId?: string;
99 /**
100 * Callback fired when the Modal is requested to be closed by a click on the overlay or when user press esc key.
101 */
102 onClose: () => void;
103 /**
104 * Callback fired when the escape key is pressed.
105 */
106 onEscKeyDown?: (event: KeyboardEvent) => void;
107 /**
108 * Callback fired when the overlay is clicked.
109 */
110 onOverlayClick?: (event: React.MouseEvent<HTMLDivElement, MouseEvent>) => void;
111 /**
112 * Callback fired when the Modal has exited and the animation is finished.
113 */
114 onAnimationEnd?: () => void;
115 children?: React.ReactNode;
116}
117export declare const Modal: ({ open, center, blockScroll, closeOnEsc, closeOnOverlayClick, container, showCloseIcon, closeIconId, closeIcon, focusTrapped, animationDuration, classNames, styles, role, ariaDescribedby, ariaLabelledby, modalId, onClose, onEscKeyDown, onOverlayClick, onAnimationEnd, children, }: ModalProps) => React.ReactPortal | null;
118export default Modal;