@purpurds/modal 6.1.2 → 6.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/LICENSE.txt +5 -5
- package/dist/modal-content.d.ts +6 -2
- package/dist/modal-content.d.ts.map +1 -1
- package/dist/modal-trigger.d.ts.map +1 -1
- package/dist/modal.cjs.js +14 -14
- package/dist/modal.cjs.js.map +1 -1
- package/dist/modal.d.ts.map +1 -1
- package/dist/modal.es.js +360 -368
- package/dist/modal.es.js.map +1 -1
- package/package.json +9 -9
- package/src/modal-content.tsx +29 -16
- package/src/modal-trigger.tsx +3 -9
- package/src/modal.tsx +6 -8
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@purpurds/modal",
|
|
3
|
-
"version": "6.1.
|
|
3
|
+
"version": "6.1.3",
|
|
4
4
|
"license": "AGPL-3.0-only",
|
|
5
5
|
"main": "./dist/modal.cjs.js",
|
|
6
6
|
"types": "./dist/modal.d.ts",
|
|
@@ -17,14 +17,14 @@
|
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"@radix-ui/react-dialog": "~1.1.6",
|
|
19
19
|
"classnames": "~2.5.0",
|
|
20
|
-
"@purpurds/
|
|
21
|
-
"@purpurds/
|
|
22
|
-
"@purpurds/
|
|
23
|
-
"@purpurds/
|
|
24
|
-
"@purpurds/
|
|
25
|
-
"@purpurds/tokens": "6.1.
|
|
26
|
-
"@purpurds/visually-hidden": "6.1.
|
|
27
|
-
"@purpurds/notification": "6.1.
|
|
20
|
+
"@purpurds/heading": "6.1.3",
|
|
21
|
+
"@purpurds/icon": "6.1.3",
|
|
22
|
+
"@purpurds/button": "6.1.3",
|
|
23
|
+
"@purpurds/text-spacing": "6.1.3",
|
|
24
|
+
"@purpurds/paragraph": "6.1.3",
|
|
25
|
+
"@purpurds/tokens": "6.1.3",
|
|
26
|
+
"@purpurds/visually-hidden": "6.1.3",
|
|
27
|
+
"@purpurds/notification": "6.1.3"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@rushstack/eslint-patch": "~1.10.0",
|
package/src/modal-content.tsx
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
1
|
-
import type { ForwardedRef, ReactNode } from "react";
|
|
1
|
+
import type { ForwardedRef, MouseEventHandler, ReactNode } from "react";
|
|
2
2
|
import React, { forwardRef, useCallback, useEffect, useRef, useState } from "react";
|
|
3
3
|
import { Button, ButtonVariant } from "@purpurds/button";
|
|
4
4
|
import { Heading } from "@purpurds/heading";
|
|
5
5
|
import { IconClose } from "@purpurds/icon/close";
|
|
6
6
|
import { Paragraph } from "@purpurds/paragraph";
|
|
7
7
|
import { VisuallyHidden } from "@purpurds/visually-hidden";
|
|
8
|
-
import
|
|
8
|
+
import {
|
|
9
|
+
Close as RadixClose,
|
|
10
|
+
Content as RadixContent,
|
|
11
|
+
Description as RadixDescription,
|
|
12
|
+
Overlay as RadixOverlay,
|
|
13
|
+
Portal as RadixPortal,
|
|
14
|
+
Title as RadixTitle,
|
|
15
|
+
} from "@radix-ui/react-dialog";
|
|
9
16
|
import c from "classnames/bind";
|
|
10
17
|
|
|
11
18
|
import "@purpurds/notification/styles";
|
|
@@ -22,7 +29,7 @@ export type DefaultProps = {
|
|
|
22
29
|
* */
|
|
23
30
|
actions?: ({
|
|
24
31
|
label: string;
|
|
25
|
-
onClick:
|
|
32
|
+
onClick: MouseEventHandler<HTMLButtonElement>;
|
|
26
33
|
disabled?: boolean;
|
|
27
34
|
loading?: boolean;
|
|
28
35
|
icon?: ReactNode;
|
|
@@ -67,6 +74,10 @@ export type DefaultProps = {
|
|
|
67
74
|
* z-index of the modal
|
|
68
75
|
* */
|
|
69
76
|
zIndex?: number;
|
|
77
|
+
/**
|
|
78
|
+
* Event handler called when focus moves to the trigger after closing.
|
|
79
|
+
* */
|
|
80
|
+
onCloseAutoFocus?: (e: Event) => void;
|
|
70
81
|
};
|
|
71
82
|
|
|
72
83
|
type NoCloseButtonProps = {
|
|
@@ -116,6 +127,7 @@ export const ModalContent = forwardRef(
|
|
|
116
127
|
title,
|
|
117
128
|
notification = undefined,
|
|
118
129
|
zIndex,
|
|
130
|
+
onCloseAutoFocus,
|
|
119
131
|
...props
|
|
120
132
|
}: ModalContentProps & { primaryActionVariant?: "primary" | "expressive" | "destructive" },
|
|
121
133
|
ref: ForwardedRef<HTMLDivElement>
|
|
@@ -172,9 +184,9 @@ export const ModalContent = forwardRef(
|
|
|
172
184
|
}, [notification, children, handleContentOverflow]);
|
|
173
185
|
|
|
174
186
|
return (
|
|
175
|
-
<
|
|
176
|
-
<
|
|
177
|
-
<
|
|
187
|
+
<RadixPortal>
|
|
188
|
+
<RadixOverlay className={cx(`${rootClassName}__overlay`)} style={{ zIndex }} />
|
|
189
|
+
<RadixContent
|
|
178
190
|
{...rest}
|
|
179
191
|
className={classes}
|
|
180
192
|
data-testid={dataTestId}
|
|
@@ -183,6 +195,7 @@ export const ModalContent = forwardRef(
|
|
|
183
195
|
onPointerDownOutside={handlePointerDownOutside}
|
|
184
196
|
onOpenAutoFocus={handleContentOverflow}
|
|
185
197
|
onEscapeKeyDown={handleEscapeKeyDown}
|
|
198
|
+
onCloseAutoFocus={onCloseAutoFocus}
|
|
186
199
|
style={{ zIndex: `calc(${zIndex} + 1)` }}
|
|
187
200
|
>
|
|
188
201
|
<div ref={wrapperRef} className={cx(`${rootClassName}__wrapper`)}>
|
|
@@ -201,7 +214,7 @@ export const ModalContent = forwardRef(
|
|
|
201
214
|
data-testid={getTestId("close-button")}
|
|
202
215
|
/>
|
|
203
216
|
)}
|
|
204
|
-
<
|
|
217
|
+
<RadixTitle
|
|
205
218
|
asChild
|
|
206
219
|
className={cx(`${rootClassName}__title`)}
|
|
207
220
|
data-testid={getTestId("title")}
|
|
@@ -209,7 +222,7 @@ export const ModalContent = forwardRef(
|
|
|
209
222
|
<Heading tag="h2" variant="title-200">
|
|
210
223
|
{title}
|
|
211
224
|
</Heading>
|
|
212
|
-
</
|
|
225
|
+
</RadixTitle>
|
|
213
226
|
</div>
|
|
214
227
|
{image && (
|
|
215
228
|
<div
|
|
@@ -223,19 +236,19 @@ export const ModalContent = forwardRef(
|
|
|
223
236
|
<div className={cx(`${rootClassName}__body-inner`)}>
|
|
224
237
|
{description && hideDescription && (
|
|
225
238
|
<VisuallyHidden asChild>
|
|
226
|
-
<
|
|
239
|
+
<RadixDescription data-testid={getTestId("description")}>
|
|
227
240
|
{description}
|
|
228
|
-
</
|
|
241
|
+
</RadixDescription>
|
|
229
242
|
</VisuallyHidden>
|
|
230
243
|
)}
|
|
231
244
|
{description && !hideDescription && (
|
|
232
|
-
<
|
|
245
|
+
<RadixDescription
|
|
233
246
|
asChild
|
|
234
247
|
className={cx(`${rootClassName}__description`)}
|
|
235
248
|
data-testid={getTestId("description")}
|
|
236
249
|
>
|
|
237
250
|
<Paragraph variant="paragraph-100">{description}</Paragraph>
|
|
238
|
-
</
|
|
251
|
+
</RadixDescription>
|
|
239
252
|
)}
|
|
240
253
|
<div>{children}</div>
|
|
241
254
|
{!stickyButtons && (
|
|
@@ -257,8 +270,8 @@ export const ModalContent = forwardRef(
|
|
|
257
270
|
notification={notification}
|
|
258
271
|
/>
|
|
259
272
|
)}
|
|
260
|
-
</
|
|
261
|
-
</
|
|
273
|
+
</RadixContent>
|
|
274
|
+
</RadixPortal>
|
|
262
275
|
);
|
|
263
276
|
}
|
|
264
277
|
);
|
|
@@ -272,7 +285,7 @@ const CloseButton = ({
|
|
|
272
285
|
hasImage?: boolean;
|
|
273
286
|
["data-testid"]?: string;
|
|
274
287
|
}) => (
|
|
275
|
-
<
|
|
288
|
+
<RadixClose asChild>
|
|
276
289
|
<Button
|
|
277
290
|
variant={hasImage ? "primary" : "tertiary-purple"}
|
|
278
291
|
negative={hasImage}
|
|
@@ -284,7 +297,7 @@ const CloseButton = ({
|
|
|
284
297
|
>
|
|
285
298
|
<IconClose />
|
|
286
299
|
</Button>
|
|
287
|
-
</
|
|
300
|
+
</RadixClose>
|
|
288
301
|
);
|
|
289
302
|
|
|
290
303
|
export const MAX_NUMBER_OF_ACTIONS = 3;
|
package/src/modal-trigger.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { ForwardedRef, forwardRef, ReactNode } from "react";
|
|
2
|
-
import
|
|
2
|
+
import { Trigger as RadixTrigger } from "@radix-ui/react-dialog";
|
|
3
3
|
|
|
4
4
|
export type ModalTriggerProps = {
|
|
5
5
|
["data-testid"]?: string;
|
|
@@ -13,15 +13,9 @@ export const ModalTrigger = forwardRef(
|
|
|
13
13
|
ref: ForwardedRef<HTMLButtonElement>
|
|
14
14
|
) => {
|
|
15
15
|
return (
|
|
16
|
-
<
|
|
17
|
-
asChild
|
|
18
|
-
ref={ref}
|
|
19
|
-
data-testid={dataTestId}
|
|
20
|
-
className={className}
|
|
21
|
-
{...props}
|
|
22
|
-
>
|
|
16
|
+
<RadixTrigger asChild ref={ref} data-testid={dataTestId} className={className} {...props}>
|
|
23
17
|
{children}
|
|
24
|
-
</
|
|
18
|
+
</RadixTrigger>
|
|
25
19
|
);
|
|
26
20
|
}
|
|
27
21
|
);
|
package/src/modal.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { ReactNode } from "react";
|
|
2
|
-
import
|
|
2
|
+
import { Root as RadixRoot } from "@radix-ui/react-dialog";
|
|
3
3
|
|
|
4
4
|
import { ModalContent } from "./modal-content";
|
|
5
5
|
import { ModalTrigger } from "./modal-trigger";
|
|
@@ -22,13 +22,11 @@ export const Modal = ({
|
|
|
22
22
|
children,
|
|
23
23
|
open,
|
|
24
24
|
onOpenChange,
|
|
25
|
-
}: ModalProps) =>
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
);
|
|
31
|
-
};
|
|
25
|
+
}: ModalProps) => (
|
|
26
|
+
<RadixRoot open={open} onOpenChange={onOpenChange} data-testid={dataTestId}>
|
|
27
|
+
{children}
|
|
28
|
+
</RadixRoot>
|
|
29
|
+
);
|
|
32
30
|
|
|
33
31
|
Modal.Trigger = ModalTrigger;
|
|
34
32
|
Modal.Content = ModalContent;
|