1 | import * as React from "react";
|
2 | import { BoxProps } from "../Box";
|
3 | import { CloseButtonProps } from "../CloseButton";
|
4 | import { TransitionProps } from "react-spring/renderprops";
|
5 |
|
6 | type ModalSizes =
|
7 | | "xs"
|
8 | | "sm"
|
9 | | "md"
|
10 | | "lg"
|
11 | | "xl"
|
12 | | "2xl"
|
13 | | "3xl"
|
14 | | "4xl"
|
15 | | "5xl"
|
16 | | "6xl"
|
17 | | "full";
|
18 |
|
19 | export interface IModal {
|
20 | container?: React.RefObject<HTMLElement>;
|
21 | /**
|
22 | * If `true`, the modal when be opened.
|
23 | */
|
24 | isOpen?: boolean;
|
25 | /**
|
26 | * Callback invoked to close the modal.
|
27 | */
|
28 | onClose?: (
|
29 | event: React.MouseEvent | React.KeyboardEvent,
|
30 | reason?: "pressedEscape" | "clickedOverlay",
|
31 | ) => void;
|
32 | /**
|
33 | * If `true`, scrolling will be disabled on the `body` when the modal opens.
|
34 | * @default true
|
35 | */
|
36 | blockScrollOnMount?: boolean;
|
37 | /**
|
38 | * A11y: If `true`, the siblings of the `Modal` will have `aria-hidden`
|
39 | * set to `true` so that screen readers can only see the `Modal`.
|
40 | *
|
41 | * This is commonly known as making the other elements **inert**
|
42 | *
|
43 | * @default true
|
44 | */
|
45 | useInert?: boolean;
|
46 | /**
|
47 | * If `true`, a `padding-right` will be applied to the body element
|
48 | * that's equal to the width of the scrollbar.
|
49 | *
|
50 | * This can help prevent some unpleasant flickering effect
|
51 | * and content adjustment when the modal opens
|
52 | */
|
53 | preserveScrollBarGap?: boolean;
|
54 | /**
|
55 | * The content of the modal.
|
56 | */
|
57 | children: React.ReactNode;
|
58 | /**
|
59 | * The size (maxWidth) of the modal.
|
60 | */
|
61 | size?: ModalSizes | BoxProps["maxWidth"];
|
62 | /**
|
63 | * If `true`, the modal will be centered on screen.
|
64 | */
|
65 | isCentered?: boolean;
|
66 | /**
|
67 | * The `ref` of element to receive focus when the modal opens.
|
68 | */
|
69 | initialFocusRef?: React.RefObject<HTMLElement>;
|
70 | /**
|
71 | * The `ref` of element to receive focus when the modal closes.
|
72 | */
|
73 | finalFocusRef?: React.RefObject<HTMLElement>;
|
74 | /**
|
75 | * Where scroll behaviour should originate.
|
76 | * - If set to `inside`, scroll only occurs within the `ModalBody`.
|
77 | * - If set to `outside`, the entire `ModalContent` will scroll within the viewport.
|
78 | */
|
79 | scrollBehavior?: "inside" | "outside";
|
80 | /**
|
81 | * If `true`, the modal will close when the overlay is clicked
|
82 | * @default true
|
83 | */
|
84 | closeOnOverlayClick?: boolean;
|
85 | /**
|
86 | * If `true`, the modal will close when the `Esc` key is pressed
|
87 | * @default true
|
88 | */
|
89 | closeOnEsc?: boolean;
|
90 | /**
|
91 | * The `id` of the modal
|
92 | */
|
93 | id?: string;
|
94 | /**
|
95 | * If `true`, the modal will return focus to the element that triggered it when it closes.
|
96 | */
|
97 | returnFocusOnClose?: boolean;
|
98 | /**
|
99 | * By default, a unique `id` is passed to the header and body.
|
100 | * These ids are used to add `aria-labelledby` and `aria-describedby` to the `ModalContent`.
|
101 | *
|
102 | * You can configure this behavior:
|
103 | * - Set it to `false` if you'd like to manually add the `aria-*` attributes.
|
104 | * - Set it to `{header: false}` if you don't render the `ModalHeader` within the modal.
|
105 | * We'll remove the `aria-labelledby` prop.
|
106 | *
|
107 | * @default true
|
108 | */
|
109 | addAriaLabels?: boolean | { header?: boolean; body?: boolean };
|
110 | /**
|
111 | * The function to format the `id`s passed to the `ModalHeader`, `Modalbody`, and `ModalContent`
|
112 | */
|
113 | formatIds?: (
|
114 | id: string | number,
|
115 | ) => { content: string; header: string; body: string };
|
116 | }
|
117 |
|
118 | export const Modal: React.FC<IModal>;
|
119 | export const ModalOverlay: React.FC<BoxProps>;
|
120 |
|
121 | interface IModalContent {
|
122 | onClick?: React.KeyboardEventHandler<HTMLElement>;
|
123 | zIndex?: BoxProps["zIndex"];
|
124 | children: React.ReactNode;
|
125 | }
|
126 |
|
127 | type ModalContentProps = IModalContent & BoxProps;
|
128 | export const ModalContent: React.FC<ModalContentProps>;
|
129 | export const ModalHeader: React.FC<BoxProps>;
|
130 | export const ModalFooter: React.FC<BoxProps>;
|
131 | export const ModalBody: React.FC<BoxProps>;
|
132 | export const ModalCloseButton: React.FC<CloseButtonProps>;
|