@purpur/library 9.2.1 → 9.2.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/CHANGELOG.json +21 -0
- package/CHANGELOG.md +14 -1
- package/dist/LICENSE.txt +1 -1
- package/dist/components/drawer/src/drawer-header.d.ts.map +1 -1
- package/dist/components/modal/src/modal-content.d.ts.map +1 -1
- package/dist/{date-picker-D3uJGCjl.js → date-picker-DVrcu2QU.js} +2 -2
- package/dist/{date-picker-D3uJGCjl.js.map → date-picker-DVrcu2QU.js.map} +1 -1
- package/dist/{date-picker-CpDZ0gK9.mjs → date-picker-DwFDRL5Z.mjs} +2 -2
- package/dist/{date-picker-CpDZ0gK9.mjs.map → date-picker-DwFDRL5Z.mjs.map} +1 -1
- package/dist/date-picker.cjs.js +1 -1
- package/dist/date-picker.es.js +1 -1
- package/dist/{drawer-BJ8xwriz.mjs → drawer-Db2Mujc6.mjs} +208 -205
- package/dist/drawer-Db2Mujc6.mjs.map +1 -0
- package/dist/drawer-DlwagnO4.js +2 -0
- package/dist/drawer-DlwagnO4.js.map +1 -0
- package/dist/drawer.cjs.js +1 -1
- package/dist/drawer.es.js +1 -1
- package/dist/library.cjs.js +1 -1
- package/dist/library.es.js +5 -5
- package/dist/modal-BMg43Fvd.mjs +211 -0
- package/dist/modal-BMg43Fvd.mjs.map +1 -0
- package/dist/modal-COF_UhvY.js +2 -0
- package/dist/modal-COF_UhvY.js.map +1 -0
- package/dist/modal.cjs.js +1 -1
- package/dist/modal.es.js +1 -1
- package/dist/purpur.css +1 -1
- package/dist/{search-field-CMBDkydb.mjs → search-field-CZ9mIyZ-.mjs} +56 -56
- package/dist/{search-field-CMBDkydb.mjs.map → search-field-CZ9mIyZ-.mjs.map} +1 -1
- package/dist/search-field-DD9UkOca.js +2 -0
- package/dist/{search-field-CU_tsmHb.js.map → search-field-DD9UkOca.js.map} +1 -1
- package/dist/search-field.cjs.js +1 -1
- package/dist/search-field.es.js +1 -1
- package/dist/{table-BVSBvTYG.js → table-DsgqX7Vv.js} +2 -2
- package/dist/{table-BVSBvTYG.js.map → table-DsgqX7Vv.js.map} +1 -1
- package/dist/{table-CuV3Gda_.mjs → table-Dx_dhGT6.mjs} +2 -2
- package/dist/{table-CuV3Gda_.mjs.map → table-Dx_dhGT6.mjs.map} +1 -1
- package/dist/table.cjs.js +1 -1
- package/dist/table.es.js +1 -1
- package/package.json +26 -26
- package/dist/drawer-BJ8xwriz.mjs.map +0 -1
- package/dist/drawer-CNs9K8Ca.js +0 -2
- package/dist/drawer-CNs9K8Ca.js.map +0 -1
- package/dist/modal-DCfN6q8I.mjs +0 -201
- package/dist/modal-DCfN6q8I.mjs.map +0 -1
- package/dist/modal-DZIdw9xy.js +0 -2
- package/dist/modal-DZIdw9xy.js.map +0 -1
- package/dist/search-field-CU_tsmHb.js +0 -2
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { jsxs as s, jsx as t } from "react/jsx-runtime";
|
|
2
|
+
import { P as k, O as q, C as G, T as J, D, a as Q, b as X, R as Y } from "./index-CKCTy3ZL.mjs";
|
|
3
|
+
import { forwardRef as H, useState as O, useRef as b, useCallback as Z, useEffect as g } from "react";
|
|
4
|
+
import { b as tt } from "./button-4-yWOgtD.mjs";
|
|
5
|
+
import { H as et } from "./heading-xwBuT_-9.mjs";
|
|
6
|
+
import { r as rt } from "./close.es-BPmk2wkU.mjs";
|
|
7
|
+
import { P as nt } from "./paragraph-Ci50OF1u.mjs";
|
|
8
|
+
import { V as ot } from "./visually-hidden-BYFkJEp1.mjs";
|
|
9
|
+
import { c as at } from "./bind-CU-R61T-.mjs";
|
|
10
|
+
const lt = "_fadeIn_1nrj3_1", st = "_fadeOut_1nrj3_1", _t = "_slideUp_1nrj3_1", dt = "_slideDown_1nrj3_1", ct = {
|
|
11
|
+
"purpur-modal-content": "_purpur-modal-content_1nrj3_1",
|
|
12
|
+
fadeIn: lt,
|
|
13
|
+
fadeOut: st,
|
|
14
|
+
slideUp: _t,
|
|
15
|
+
slideDown: dt,
|
|
16
|
+
"purpur-modal-content__overlay": "_purpur-modal-content__overlay_1nrj3_49",
|
|
17
|
+
"purpur-modal-content__close-button": "_purpur-modal-content__close-button_1nrj3_65",
|
|
18
|
+
"purpur-modal-content__wrapper": "_purpur-modal-content__wrapper_1nrj3_75",
|
|
19
|
+
"purpur-modal-content__wrapper-inner": "_purpur-modal-content__wrapper-inner_1nrj3_85",
|
|
20
|
+
"purpur-modal-content__image-wrapper": "_purpur-modal-content__image-wrapper_1nrj3_89",
|
|
21
|
+
"purpur-modal-content__header": "_purpur-modal-content__header_1nrj3_112",
|
|
22
|
+
"purpur-modal-content__title": "_purpur-modal-content__title_1nrj3_125",
|
|
23
|
+
"purpur-modal-content__heading": "_purpur-modal-content__heading_1nrj3_128",
|
|
24
|
+
"purpur-modal-content__description": "_purpur-modal-content__description_1nrj3_131",
|
|
25
|
+
"purpur-modal-content__body": "_purpur-modal-content__body_1nrj3_134",
|
|
26
|
+
"purpur-modal-content__body-inner": "_purpur-modal-content__body-inner_1nrj3_142",
|
|
27
|
+
"purpur-modal-content__actions-buttons": "_purpur-modal-content__actions-buttons_1nrj3_154",
|
|
28
|
+
"purpur-modal-content__notification": "_purpur-modal-content__notification_1nrj3_172",
|
|
29
|
+
"purpur-modal-content--with-image": "_purpur-modal-content--with-image_1nrj3_175",
|
|
30
|
+
"purpur-modal-content--overflow": "_purpur-modal-content--overflow_1nrj3_175",
|
|
31
|
+
"purpur-modal-content__actions": "_purpur-modal-content__actions_1nrj3_154",
|
|
32
|
+
"purpur-modal-content__actions-separator": "_purpur-modal-content__actions-separator_1nrj3_206",
|
|
33
|
+
"purpur-modal-content--sticky-footer": "_purpur-modal-content--sticky-footer_1nrj3_216"
|
|
34
|
+
}, P = (n) => n.showCloseButton === !0, r = at.bind(ct), e = "purpur-modal-content", it = H(
|
|
35
|
+
({
|
|
36
|
+
["data-testid"]: n,
|
|
37
|
+
actions: o,
|
|
38
|
+
children: a,
|
|
39
|
+
className: c,
|
|
40
|
+
description: i,
|
|
41
|
+
disableCloseOnClickOutside: $,
|
|
42
|
+
hideDescription: N,
|
|
43
|
+
image: u,
|
|
44
|
+
stickyButtons: w = !0,
|
|
45
|
+
title: I,
|
|
46
|
+
notification: v = void 0,
|
|
47
|
+
zIndex: C,
|
|
48
|
+
onCloseAutoFocus: M,
|
|
49
|
+
...y
|
|
50
|
+
}, E) => {
|
|
51
|
+
const { closeButtonAriaLabel: m, showCloseButton: S, ...T } = y, [B, V] = O(!1), [W, z] = O(0), p = b(null), h = b(null), A = r(
|
|
52
|
+
e,
|
|
53
|
+
{ [`${e}--with-image`]: !!u },
|
|
54
|
+
{ [`${e}--overflow`]: B },
|
|
55
|
+
{ [`${e}--sticky-footer`]: w },
|
|
56
|
+
c
|
|
57
|
+
), _ = (l) => n ? `${n} ${l}` : void 0, F = (l) => {
|
|
58
|
+
$ && l.preventDefault();
|
|
59
|
+
}, d = Z(() => {
|
|
60
|
+
if (!p.current || !h.current)
|
|
61
|
+
return;
|
|
62
|
+
const l = window.getComputedStyle(p.current, null), f = parseFloat(l.getPropertyValue("height")), K = h.current.offsetHeight;
|
|
63
|
+
V(f < K), z(
|
|
64
|
+
(p.current.offsetWidth ?? 0) - (p.current.clientWidth ?? 0)
|
|
65
|
+
);
|
|
66
|
+
}, []), L = () => {
|
|
67
|
+
const l = h.current;
|
|
68
|
+
if (l) {
|
|
69
|
+
const f = l.querySelector("h2");
|
|
70
|
+
f && setTimeout(() => {
|
|
71
|
+
f.focus();
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}, U = (l) => {
|
|
75
|
+
$ && !S && l.preventDefault();
|
|
76
|
+
};
|
|
77
|
+
return g(() => (window.addEventListener("resize", d), () => {
|
|
78
|
+
window.removeEventListener("resize", d);
|
|
79
|
+
}), [d]), g(() => {
|
|
80
|
+
d();
|
|
81
|
+
}, [v, a, d]), /* @__PURE__ */ s(k, { children: [
|
|
82
|
+
/* @__PURE__ */ t(q, { className: r(`${e}__overlay`), style: { zIndex: C } }),
|
|
83
|
+
/* @__PURE__ */ s(
|
|
84
|
+
G,
|
|
85
|
+
{
|
|
86
|
+
...T,
|
|
87
|
+
className: A,
|
|
88
|
+
"data-testid": n,
|
|
89
|
+
ref: E,
|
|
90
|
+
...!i && { "aria-describedby": void 0 },
|
|
91
|
+
onPointerDownOutside: F,
|
|
92
|
+
onOpenAutoFocus: () => {
|
|
93
|
+
d(), L();
|
|
94
|
+
},
|
|
95
|
+
onEscapeKeyDown: U,
|
|
96
|
+
onCloseAutoFocus: M,
|
|
97
|
+
style: { zIndex: `calc(${C} + 1)` },
|
|
98
|
+
children: [
|
|
99
|
+
/* @__PURE__ */ s("div", { ref: p, className: r(`${e}__wrapper`), children: [
|
|
100
|
+
P(y) && m && u && /* @__PURE__ */ t(
|
|
101
|
+
R,
|
|
102
|
+
{
|
|
103
|
+
"aria-label": m,
|
|
104
|
+
hasImage: !0,
|
|
105
|
+
scrollbarWidth: W,
|
|
106
|
+
"data-testid": _("close-button")
|
|
107
|
+
}
|
|
108
|
+
),
|
|
109
|
+
/* @__PURE__ */ s("div", { ref: h, className: r(`${e}__wrapper-inner`), children: [
|
|
110
|
+
/* @__PURE__ */ s("div", { className: r(`${e}__header`), children: [
|
|
111
|
+
P(y) && m && !u && /* @__PURE__ */ t(
|
|
112
|
+
R,
|
|
113
|
+
{
|
|
114
|
+
"aria-label": m,
|
|
115
|
+
"data-testid": _("close-button")
|
|
116
|
+
}
|
|
117
|
+
),
|
|
118
|
+
/* @__PURE__ */ t(
|
|
119
|
+
J,
|
|
120
|
+
{
|
|
121
|
+
asChild: !0,
|
|
122
|
+
className: r(`${e}__title`),
|
|
123
|
+
"data-testid": _("title"),
|
|
124
|
+
children: /* @__PURE__ */ t(
|
|
125
|
+
et,
|
|
126
|
+
{
|
|
127
|
+
tag: "h2",
|
|
128
|
+
variant: "display-10",
|
|
129
|
+
tabIndex: -1,
|
|
130
|
+
className: r(`${e}__heading`),
|
|
131
|
+
children: I
|
|
132
|
+
}
|
|
133
|
+
)
|
|
134
|
+
}
|
|
135
|
+
)
|
|
136
|
+
] }),
|
|
137
|
+
u && /* @__PURE__ */ t(
|
|
138
|
+
"div",
|
|
139
|
+
{
|
|
140
|
+
className: r(`${e}__image-wrapper`),
|
|
141
|
+
"data-testid": _("image"),
|
|
142
|
+
children: u
|
|
143
|
+
}
|
|
144
|
+
),
|
|
145
|
+
/* @__PURE__ */ t("div", { className: r(`${e}__body`), children: /* @__PURE__ */ s("div", { className: r(`${e}__body-inner`), children: [
|
|
146
|
+
i && N && /* @__PURE__ */ t(ot, { asChild: !0, children: /* @__PURE__ */ t(D, { "data-testid": _("description"), children: i }) }),
|
|
147
|
+
i && !N && /* @__PURE__ */ t(
|
|
148
|
+
D,
|
|
149
|
+
{
|
|
150
|
+
asChild: !0,
|
|
151
|
+
className: r(`${e}__description`),
|
|
152
|
+
"data-testid": _("description"),
|
|
153
|
+
children: /* @__PURE__ */ t(nt, { variant: "paragraph-100", children: i })
|
|
154
|
+
}
|
|
155
|
+
),
|
|
156
|
+
/* @__PURE__ */ t("div", { children: a }),
|
|
157
|
+
!w && /* @__PURE__ */ t(x, { actions: o, notification: v })
|
|
158
|
+
] }) })
|
|
159
|
+
] })
|
|
160
|
+
] }),
|
|
161
|
+
w && /* @__PURE__ */ t(x, { actions: o, notification: v })
|
|
162
|
+
]
|
|
163
|
+
}
|
|
164
|
+
)
|
|
165
|
+
] });
|
|
166
|
+
}
|
|
167
|
+
), R = ({
|
|
168
|
+
["aria-label"]: n,
|
|
169
|
+
hasImage: o,
|
|
170
|
+
scrollbarWidth: a,
|
|
171
|
+
["data-testid"]: c
|
|
172
|
+
}) => /* @__PURE__ */ t(Q, { asChild: !0, children: /* @__PURE__ */ t(
|
|
173
|
+
tt,
|
|
174
|
+
{
|
|
175
|
+
variant: o ? "primary" : "tertiary-purple",
|
|
176
|
+
negative: o,
|
|
177
|
+
size: "sm",
|
|
178
|
+
iconOnly: !0,
|
|
179
|
+
"aria-label": n,
|
|
180
|
+
className: r(`${e}__close-button`),
|
|
181
|
+
style: { right: `calc(var(--purpur-spacing-100) + ${a || 0}px)` },
|
|
182
|
+
"data-testid": c,
|
|
183
|
+
children: /* @__PURE__ */ t(rt, {})
|
|
184
|
+
}
|
|
185
|
+
) }), x = ({
|
|
186
|
+
actions: n,
|
|
187
|
+
notification: o
|
|
188
|
+
}) => {
|
|
189
|
+
const a = b(null);
|
|
190
|
+
return g(() => {
|
|
191
|
+
o && a?.current?.scrollIntoView?.(!1);
|
|
192
|
+
}, [o]), n ? /* @__PURE__ */ s("div", { className: r(`${e}__actions`), children: [
|
|
193
|
+
/* @__PURE__ */ t("div", { className: r(`${e}__actions-buttons`), "data-testid": "modal actions", children: n }),
|
|
194
|
+
o && /* @__PURE__ */ t("div", { className: r(`${e}__notification`), ref: a, children: o }),
|
|
195
|
+
/* @__PURE__ */ t("span", { className: r(`${e}__actions-separator`) })
|
|
196
|
+
] }) : null;
|
|
197
|
+
}, ut = H(
|
|
198
|
+
({ children: n, ...o }, a) => /* @__PURE__ */ t(X, { asChild: !0, ref: a, ...o, children: n })
|
|
199
|
+
), j = ({
|
|
200
|
+
["data-testid"]: n,
|
|
201
|
+
children: o,
|
|
202
|
+
open: a,
|
|
203
|
+
onOpenChange: c
|
|
204
|
+
}) => /* @__PURE__ */ t(Y, { open: a, onOpenChange: c, "data-testid": n, children: o });
|
|
205
|
+
j.Trigger = ut;
|
|
206
|
+
j.Content = it;
|
|
207
|
+
j.displayName = "Modal";
|
|
208
|
+
export {
|
|
209
|
+
j as M
|
|
210
|
+
};
|
|
211
|
+
//# sourceMappingURL=modal-BMg43Fvd.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"modal-BMg43Fvd.mjs","sources":["../../../components/modal/src/modal-content.tsx","../../../components/modal/src/modal-trigger.tsx","../../../components/modal/src/modal.tsx"],"sourcesContent":["import React, { forwardRef, type ReactNode, useCallback, useEffect, useRef, useState } from \"react\";\nimport { Button } from \"@purpur/button\";\nimport type { BaseProps } from \"@purpur/common-types\";\nimport { Heading } from \"@purpur/heading\";\nimport { IconClose } from \"@purpur/icon/close\";\nimport { Paragraph } from \"@purpur/paragraph\";\nimport { VisuallyHidden } from \"@purpur/visually-hidden\";\nimport {\n Close as RadixClose,\n Content as RadixContent,\n Description as RadixDescription,\n Overlay as RadixOverlay,\n Portal as RadixPortal,\n Title as RadixTitle,\n} from \"@radix-ui/react-dialog\";\nimport c from \"classnames/bind\";\n\nimport \"@purpur/notification/styles\";\nimport styles from \"./modal-content.module.scss\";\n\nexport type DefaultProps = Omit<BaseProps, \"children\"> & {\n /**\n * One or several CTA links or buttons\n * */\n actions?: ReactNode;\n children: ReactNode;\n /**\n * An optional accessible description to be announced when the dialog is opened.\n * */\n description?: string;\n /**\n * Prevents the modal from closing on click outside if set to `true`.\n * */\n disableCloseOnClickOutside?: boolean;\n /**\n * Visually hides the description if set to `true`.\n * */\n hideDescription?: boolean;\n /**\n * An optional image to be displayed at the top of the modal.\n * */\n image?: ReactNode;\n /**\n * Provide a Purpur Notification which will render beneath the modal buttons, otherwise leave it undefined.\n * */\n notification?: ReactNode;\n /**\n * Determines whether the button group should be fixed at the bottom or scroll with the content.\n * */\n stickyButtons?: boolean;\n /**\n * An accessible title to be announced when the dialog is opened.\n * */\n title: string;\n /**\n * z-index of the modal\n * */\n zIndex?: number;\n /**\n * Event handler called when focus moves to the trigger after closing.\n * */\n onCloseAutoFocus?: (e: Event) => void;\n};\n\ntype NoCloseButtonProps = {\n /**\n * An accessible label for the close button.\n * */\n closeButtonAriaLabel?: never;\n /**\n * Shows the close button if set to `true`. Must be used in conjunction with `closeButtonAriaLabel`.\n * */\n showCloseButton?: false;\n};\n\ntype CloseButtonProps = {\n /**\n * An accessible label for the close button.\n * */\n closeButtonAriaLabel: string;\n /**\n * Shows the close button if set to `true`. Must be used in conjunction with `closeButtonAriaLabel`.\n * */\n showCloseButton: true;\n};\n\nexport type ModalContentProps = DefaultProps & (CloseButtonProps | NoCloseButtonProps);\n\nconst hasCloseButtonProps = (\n props: CloseButtonProps | NoCloseButtonProps\n): props is CloseButtonProps => (props as CloseButtonProps).showCloseButton === true;\n\nconst cx = c.bind(styles);\nconst rootClassName = \"purpur-modal-content\";\n\nexport const ModalContent = forwardRef<HTMLDivElement, ModalContentProps>(\n (\n {\n [\"data-testid\"]: dataTestId,\n actions,\n children,\n className,\n description,\n disableCloseOnClickOutside,\n hideDescription,\n image,\n stickyButtons = true,\n title,\n notification = undefined,\n zIndex,\n onCloseAutoFocus,\n ...props\n },\n ref\n ) => {\n const { closeButtonAriaLabel, showCloseButton, ...rest } = props;\n const [contentOverflow, setContentOverflow] = useState(false);\n const [scrollbarWidth, setScrollbarWidth] = useState(0);\n const wrapperRef = useRef<HTMLDivElement>(null);\n const wrapperInnerRef = useRef<HTMLDivElement>(null);\n\n const classes = cx(\n rootClassName,\n { [`${rootClassName}--with-image`]: !!image },\n { [`${rootClassName}--overflow`]: contentOverflow },\n { [`${rootClassName}--sticky-footer`]: stickyButtons },\n className\n );\n\n const getTestId = (id: string) => (dataTestId ? `${dataTestId} ${id}` : undefined);\n\n const handlePointerDownOutside = (event: CustomEvent<{ originalEvent: PointerEvent }>) => {\n if (disableCloseOnClickOutside) {\n event.preventDefault();\n }\n };\n\n const handleContentOverflow = useCallback(() => {\n if (!wrapperRef.current || !wrapperInnerRef.current) {\n return;\n }\n\n const computedStyle = window.getComputedStyle(wrapperRef.current, null);\n const wrapperHeight = parseFloat(computedStyle.getPropertyValue(\"height\"));\n const innerHeight = wrapperInnerRef.current.offsetHeight;\n\n setContentOverflow(wrapperHeight < innerHeight);\n\n setScrollbarWidth(\n (wrapperRef.current.offsetWidth ?? 0) - (wrapperRef.current.clientWidth ?? 0)\n );\n }, []);\n\n const handleInitialFocus = () => {\n const frame = wrapperInnerRef.current;\n if (frame) {\n const heading = frame.querySelector(\"h2\");\n\n heading &&\n setTimeout(() => {\n heading.focus();\n });\n }\n };\n\n const handleEscapeKeyDown = (event: KeyboardEvent) => {\n if (disableCloseOnClickOutside && !showCloseButton) {\n event.preventDefault();\n }\n };\n\n useEffect(() => {\n window.addEventListener(\"resize\", handleContentOverflow);\n\n return () => {\n window.removeEventListener(\"resize\", handleContentOverflow);\n };\n }, [handleContentOverflow]);\n\n useEffect(() => {\n handleContentOverflow();\n }, [notification, children, handleContentOverflow]);\n\n return (\n <RadixPortal>\n <RadixOverlay className={cx(`${rootClassName}__overlay`)} style={{ zIndex }} />\n <RadixContent\n {...rest}\n className={classes}\n data-testid={dataTestId}\n ref={ref}\n {...(!description && { [\"aria-describedby\"]: undefined })}\n onPointerDownOutside={handlePointerDownOutside}\n onOpenAutoFocus={() => {\n handleContentOverflow();\n handleInitialFocus();\n }}\n onEscapeKeyDown={handleEscapeKeyDown}\n onCloseAutoFocus={onCloseAutoFocus}\n style={{ zIndex: `calc(${zIndex} + 1)` }}\n >\n <div ref={wrapperRef} className={cx(`${rootClassName}__wrapper`)}>\n {hasCloseButtonProps(props) && closeButtonAriaLabel && image && (\n <CloseButton\n aria-label={closeButtonAriaLabel}\n hasImage\n scrollbarWidth={scrollbarWidth}\n data-testid={getTestId(\"close-button\")}\n />\n )}\n <div ref={wrapperInnerRef} className={cx(`${rootClassName}__wrapper-inner`)}>\n <div className={cx(`${rootClassName}__header`)}>\n {hasCloseButtonProps(props) && closeButtonAriaLabel && !image && (\n <CloseButton\n aria-label={closeButtonAriaLabel}\n data-testid={getTestId(\"close-button\")}\n />\n )}\n <RadixTitle\n asChild\n className={cx(`${rootClassName}__title`)}\n data-testid={getTestId(\"title\")}\n >\n <Heading\n tag=\"h2\"\n variant=\"display-10\"\n tabIndex={-1}\n className={cx(`${rootClassName}__heading`)}\n >\n {title}\n </Heading>\n </RadixTitle>\n </div>\n {image && (\n <div\n className={cx(`${rootClassName}__image-wrapper`)}\n data-testid={getTestId(\"image\")}\n >\n {image}\n </div>\n )}\n <div className={cx(`${rootClassName}__body`)}>\n <div className={cx(`${rootClassName}__body-inner`)}>\n {description && hideDescription && (\n <VisuallyHidden asChild>\n <RadixDescription data-testid={getTestId(\"description\")}>\n {description}\n </RadixDescription>\n </VisuallyHidden>\n )}\n {description && !hideDescription && (\n <RadixDescription\n asChild\n className={cx(`${rootClassName}__description`)}\n data-testid={getTestId(\"description\")}\n >\n <Paragraph variant=\"paragraph-100\">{description}</Paragraph>\n </RadixDescription>\n )}\n <div>{children}</div>\n {!stickyButtons && <ModalActions actions={actions} notification={notification} />}\n </div>\n </div>\n </div>\n </div>\n\n {stickyButtons && <ModalActions actions={actions} notification={notification} />}\n </RadixContent>\n </RadixPortal>\n );\n }\n);\n\nconst CloseButton = ({\n [\"aria-label\"]: ariaLabel,\n hasImage,\n scrollbarWidth,\n [\"data-testid\"]: dataTestId,\n}: {\n [\"aria-label\"]: string;\n hasImage?: boolean;\n scrollbarWidth?: number;\n [\"data-testid\"]?: string;\n}) => (\n <RadixClose asChild>\n <Button\n variant={hasImage ? \"primary\" : \"tertiary-purple\"}\n negative={hasImage}\n size=\"sm\"\n iconOnly\n aria-label={ariaLabel}\n className={cx(`${rootClassName}__close-button`)}\n style={{ right: `calc(var(--purpur-spacing-100) + ${scrollbarWidth || 0}px)` }}\n data-testid={dataTestId}\n >\n <IconClose />\n </Button>\n </RadixClose>\n);\n\nexport const MAX_NUMBER_OF_ACTIONS = 3;\n\nexport const ModalActions = ({\n actions,\n notification,\n}: Pick<ModalContentProps, \"actions\" | \"notification\">) => {\n const notificationRef = useRef<HTMLDivElement>(null);\n\n useEffect(() => {\n if (notification) {\n notificationRef?.current?.scrollIntoView?.(false);\n }\n }, [notification]);\n\n return actions ? (\n <div className={cx(`${rootClassName}__actions`)}>\n <div className={cx(`${rootClassName}__actions-buttons`)} data-testid=\"modal actions\">\n {actions}\n </div>\n {notification && (\n <div className={cx(`${rootClassName}__notification`)} ref={notificationRef}>\n {notification}\n </div>\n )}\n <span className={cx(`${rootClassName}__actions-separator`)} />\n </div>\n ) : null;\n};\n","import React, { forwardRef, type ReactNode } from \"react\";\nimport type { BaseProps } from \"@purpur/common-types\";\nimport { Trigger as RadixTrigger } from \"@radix-ui/react-dialog\";\n\nexport type ModalTriggerProps = Omit<BaseProps<\"button\">, \"children\"> & {\n children: ReactNode;\n};\n\nexport const ModalTrigger = forwardRef<HTMLButtonElement, ModalTriggerProps>(\n ({ children, ...props }, ref) => {\n return (\n <RadixTrigger asChild ref={ref} {...props}>\n {children}\n </RadixTrigger>\n );\n }\n);\n","import React, { type ReactNode } from \"react\";\nimport { Root as RadixRoot } from \"@radix-ui/react-dialog\";\n\nimport { ModalContent } from \"./modal-content\";\nimport { ModalTrigger } from \"./modal-trigger\";\n\nexport type ModalProps = {\n [\"data-testid\"]?: string;\n children: ReactNode;\n /**\n * Event handler called when the open state of the dialog changes.\n * */\n onOpenChange?: (value: boolean) => void;\n /**\n * The controlled open state of the dialog. Must be used in conjunction with `onOpenChange`.\n * */\n open?: boolean;\n};\n\nexport const Modal = ({\n [\"data-testid\"]: dataTestId,\n children,\n open,\n onOpenChange,\n}: ModalProps) => (\n <RadixRoot open={open} onOpenChange={onOpenChange} data-testid={dataTestId}>\n {children}\n </RadixRoot>\n);\n\nModal.Trigger = ModalTrigger;\nModal.Content = ModalContent;\n\nModal.displayName = \"Modal\";\n"],"names":["hasCloseButtonProps","props","cx","c","styles","rootClassName","ModalContent","forwardRef","dataTestId","actions","children","className","description","disableCloseOnClickOutside","hideDescription","image","stickyButtons","title","notification","zIndex","onCloseAutoFocus","ref","closeButtonAriaLabel","showCloseButton","rest","contentOverflow","setContentOverflow","useState","scrollbarWidth","setScrollbarWidth","wrapperRef","useRef","wrapperInnerRef","classes","getTestId","id","handlePointerDownOutside","event","handleContentOverflow","useCallback","computedStyle","wrapperHeight","innerHeight","handleInitialFocus","frame","heading","handleEscapeKeyDown","useEffect","RadixPortal","jsx","RadixOverlay","jsxs","RadixContent","CloseButton","RadixTitle","Heading","VisuallyHidden","RadixDescription","Paragraph","ModalActions","ariaLabel","hasImage","RadixClose","Button","IconClose","notificationRef","ModalTrigger","RadixTrigger","Modal","open","onOpenChange","RadixRoot"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwFMA,IAAsB,CAC1BC,MAC+BA,EAA2B,oBAAoB,IAE1EC,IAAKC,GAAE,KAAKC,EAAM,GAClBC,IAAgB,wBAETC,KAAeC;AAAA,EAC1B,CACE;AAAA,IACE,CAAC,gBAAgBC;AAAA,IACjB,SAAAC;AAAA,IACA,UAAAC;AAAA,IACA,WAAAC;AAAA,IACA,aAAAC;AAAA,IACA,4BAAAC;AAAA,IACA,iBAAAC;AAAA,IACA,OAAAC;AAAA,IACA,eAAAC,IAAgB;AAAA,IAChB,OAAAC;AAAA,IACA,cAAAC,IAAe;AAAA,IACf,QAAAC;AAAA,IACA,kBAAAC;AAAA,IACA,GAAGnB;AAAA,EAAA,GAELoB,MACG;AACH,UAAM,EAAE,sBAAAC,GAAsB,iBAAAC,GAAiB,GAAGC,MAASvB,GACrD,CAACwB,GAAiBC,CAAkB,IAAIC,EAAS,EAAK,GACtD,CAACC,GAAgBC,CAAiB,IAAIF,EAAS,CAAC,GAChDG,IAAaC,EAAuB,IAAI,GACxCC,IAAkBD,EAAuB,IAAI,GAE7CE,IAAU/B;AAAA,MACdG;AAAA,MACA,EAAE,CAAC,GAAGA,CAAa,cAAc,GAAG,CAAC,CAACU,EAAA;AAAA,MACtC,EAAE,CAAC,GAAGV,CAAa,YAAY,GAAGoB,EAAA;AAAA,MAClC,EAAE,CAAC,GAAGpB,CAAa,iBAAiB,GAAGW,EAAA;AAAA,MACvCL;AAAA,IAAA,GAGIuB,IAAY,CAACC,MAAgB3B,IAAa,GAAGA,CAAU,IAAI2B,CAAE,KAAK,QAElEC,IAA2B,CAACC,MAAwD;AACxF,MAAIxB,KACFwB,EAAM,eAAA;AAAA,IAEV,GAEMC,IAAwBC,EAAY,MAAM;AAC9C,UAAI,CAACT,EAAW,WAAW,CAACE,EA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GAAA,EAAU,MAAAF,GAAY,cAAAC,GAA4B,eAAa9D,GAC7D,UAAAE,EAAA,CACH;AAGF0D,EAAM,UAAUF;AAChBE,EAAM,UAAU9D;AAEhB8D,EAAM,cAAc;"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";const e=require("react/jsx-runtime"),c=require("./index-2cFVyGXq.js"),s=require("react"),F=require("./button-DmybVApa.js"),L=require("./heading-drD5ugCC.js"),U=require("./close.es-VL3lKi1O.js"),V=require("./paragraph-BsI53OR0.js"),K=require("./visually-hidden-C2CKovZx.js"),k=require("./bind-DeUYJ6m9.js"),G="_fadeIn_1nrj3_1",J="_fadeOut_1nrj3_1",Q="_slideUp_1nrj3_1",X="_slideDown_1nrj3_1",Y={"purpur-modal-content":"_purpur-modal-content_1nrj3_1",fadeIn:G,fadeOut:J,slideUp:Q,slideDown:X,"purpur-modal-content__overlay":"_purpur-modal-content__overlay_1nrj3_49","purpur-modal-content__close-button":"_purpur-modal-content__close-button_1nrj3_65","purpur-modal-content__wrapper":"_purpur-modal-content__wrapper_1nrj3_75","purpur-modal-content__wrapper-inner":"_purpur-modal-content__wrapper-inner_1nrj3_85","purpur-modal-content__image-wrapper":"_purpur-modal-content__image-wrapper_1nrj3_89","purpur-modal-content__header":"_purpur-modal-content__header_1nrj3_112","purpur-modal-content__title":"_purpur-modal-content__title_1nrj3_125","purpur-modal-content__heading":"_purpur-modal-content__heading_1nrj3_128","purpur-modal-content__description":"_purpur-modal-content__description_1nrj3_131","purpur-modal-content__body":"_purpur-modal-content__body_1nrj3_134","purpur-modal-content__body-inner":"_purpur-modal-content__body-inner_1nrj3_142","purpur-modal-content__actions-buttons":"_purpur-modal-content__actions-buttons_1nrj3_154","purpur-modal-content__notification":"_purpur-modal-content__notification_1nrj3_172","purpur-modal-content--with-image":"_purpur-modal-content--with-image_1nrj3_175","purpur-modal-content--overflow":"_purpur-modal-content--overflow_1nrj3_175","purpur-modal-content__actions":"_purpur-modal-content__actions_1nrj3_154","purpur-modal-content__actions-separator":"_purpur-modal-content__actions-separator_1nrj3_206","purpur-modal-content--sticky-footer":"_purpur-modal-content--sticky-footer_1nrj3_216"},N=n=>n.showCloseButton===!0,r=k.c.bind(Y),t="purpur-modal-content",Z=s.forwardRef(({["data-testid"]:n,actions:o,children:a,className:u,description:i,disableCloseOnClickOutside:y,hideDescription:b,image:p,stickyButtons:v=!0,title:q,notification:x=void 0,zIndex:$,onCloseAutoFocus:D,...g},O)=>{const{closeButtonAriaLabel:h,showCloseButton:E,...H}=g,[I,M]=s.useState(!1),[P,S]=s.useState(0),m=s.useRef(null),j=s.useRef(null),B=r(t,{[`${t}--with-image`]:!!p},{[`${t}--overflow`]:I},{[`${t}--sticky-footer`]:v},u),d=l=>n?`${n} ${l}`:void 0,T=l=>{y&&l.preventDefault()},_=s.useCallback(()=>{if(!m.current||!j.current)return;const l=window.getComputedStyle(m.current,null),f=parseFloat(l.getPropertyValue("height")),A=j.current.offsetHeight;M(f<A),S((m.current.offsetWidth??0)-(m.current.clientWidth??0))},[]),W=()=>{const l=j.current;if(l){const f=l.querySelector("h2");f&&setTimeout(()=>{f.focus()})}},z=l=>{y&&!E&&l.preventDefault()};return s.useEffect(()=>(window.addEventListener("resize",_),()=>{window.removeEventListener("resize",_)}),[_]),s.useEffect(()=>{_()},[x,a,_]),e.jsxs(c.Portal,{children:[e.jsx(c.Overlay,{className:r(`${t}__overlay`),style:{zIndex:$}}),e.jsxs(c.Content,{...H,className:B,"data-testid":n,ref:O,...!i&&{"aria-describedby":void 0},onPointerDownOutside:T,onOpenAutoFocus:()=>{_(),W()},onEscapeKeyDown:z,onCloseAutoFocus:D,style:{zIndex:`calc(${$} + 1)`},children:[e.jsxs("div",{ref:m,className:r(`${t}__wrapper`),children:[N(g)&&h&&p&&e.jsx(C,{"aria-label":h,hasImage:!0,scrollbarWidth:P,"data-testid":d("close-button")}),e.jsxs("div",{ref:j,className:r(`${t}__wrapper-inner`),children:[e.jsxs("div",{className:r(`${t}__header`),children:[N(g)&&h&&!p&&e.jsx(C,{"aria-label":h,"data-testid":d("close-button")}),e.jsx(c.Title,{asChild:!0,className:r(`${t}__title`),"data-testid":d("title"),children:e.jsx(L.Heading,{tag:"h2",variant:"display-10",tabIndex:-1,className:r(`${t}__heading`),children:q})})]}),p&&e.jsx("div",{className:r(`${t}__image-wrapper`),"data-testid":d("image"),children:p}),e.jsx("div",{className:r(`${t}__body`),children:e.jsxs("div",{className:r(`${t}__body-inner`),children:[i&&b&&e.jsx(K.VisuallyHidden,{asChild:!0,children:e.jsx(c.Description,{"data-testid":d("description"),children:i})}),i&&!b&&e.jsx(c.Description,{asChild:!0,className:r(`${t}__description`),"data-testid":d("description"),children:e.jsx(V.Paragraph,{variant:"paragraph-100",children:i})}),e.jsx("div",{children:a}),!v&&e.jsx(R,{actions:o,notification:x})]})})]})]}),v&&e.jsx(R,{actions:o,notification:x})]})]})}),C=({["aria-label"]:n,hasImage:o,scrollbarWidth:a,["data-testid"]:u})=>e.jsx(c.Close,{asChild:!0,children:e.jsx(F.Button,{variant:o?"primary":"tertiary-purple",negative:o,size:"sm",iconOnly:!0,"aria-label":n,className:r(`${t}__close-button`),style:{right:`calc(var(--purpur-spacing-100) + ${a||0}px)`},"data-testid":u,children:e.jsx(U.r,{})})}),R=({actions:n,notification:o})=>{const a=s.useRef(null);return s.useEffect(()=>{o&&a?.current?.scrollIntoView?.(!1)},[o]),n?e.jsxs("div",{className:r(`${t}__actions`),children:[e.jsx("div",{className:r(`${t}__actions-buttons`),"data-testid":"modal actions",children:n}),o&&e.jsx("div",{className:r(`${t}__notification`),ref:a,children:o}),e.jsx("span",{className:r(`${t}__actions-separator`)})]}):null},ee=s.forwardRef(({children:n,...o},a)=>e.jsx(c.Trigger,{asChild:!0,ref:a,...o,children:n})),w=({["data-testid"]:n,children:o,open:a,onOpenChange:u})=>e.jsx(c.Root,{open:a,onOpenChange:u,"data-testid":n,children:o});w.Trigger=ee;w.Content=Z;w.displayName="Modal";exports.Modal=w;
|
|
2
|
+
//# sourceMappingURL=modal-COF_UhvY.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"modal-COF_UhvY.js","sources":["../../../components/modal/src/modal-content.tsx","../../../components/modal/src/modal-trigger.tsx","../../../components/modal/src/modal.tsx"],"sourcesContent":["import React, { forwardRef, type ReactNode, useCallback, useEffect, useRef, useState } from \"react\";\nimport { Button } from \"@purpur/button\";\nimport type { BaseProps } from \"@purpur/common-types\";\nimport { Heading } from \"@purpur/heading\";\nimport { IconClose } from \"@purpur/icon/close\";\nimport { Paragraph } from \"@purpur/paragraph\";\nimport { VisuallyHidden } from \"@purpur/visually-hidden\";\nimport {\n Close as RadixClose,\n Content as RadixContent,\n Description as RadixDescription,\n Overlay as RadixOverlay,\n Portal as RadixPortal,\n Title as RadixTitle,\n} from \"@radix-ui/react-dialog\";\nimport c from \"classnames/bind\";\n\nimport \"@purpur/notification/styles\";\nimport styles from \"./modal-content.module.scss\";\n\nexport type DefaultProps = Omit<BaseProps, \"children\"> & {\n /**\n * One or several CTA links or buttons\n * */\n actions?: ReactNode;\n children: ReactNode;\n /**\n * An optional accessible description to be announced when the dialog is opened.\n * */\n description?: string;\n /**\n * Prevents the modal from closing on click outside if set to `true`.\n * */\n disableCloseOnClickOutside?: boolean;\n /**\n * Visually hides the description if set to `true`.\n * */\n hideDescription?: boolean;\n /**\n * An optional image to be displayed at the top of the modal.\n * */\n image?: ReactNode;\n /**\n * Provide a Purpur Notification which will render beneath the modal buttons, otherwise leave it undefined.\n * */\n notification?: ReactNode;\n /**\n * Determines whether the button group should be fixed at the bottom or scroll with the content.\n * */\n stickyButtons?: boolean;\n /**\n * An accessible title to be announced when the dialog is opened.\n * */\n title: string;\n /**\n * z-index of the modal\n * */\n zIndex?: number;\n /**\n * Event handler called when focus moves to the trigger after closing.\n * */\n onCloseAutoFocus?: (e: Event) => void;\n};\n\ntype NoCloseButtonProps = {\n /**\n * An accessible label for the close button.\n * */\n closeButtonAriaLabel?: never;\n /**\n * Shows the close button if set to `true`. Must be used in conjunction with `closeButtonAriaLabel`.\n * */\n showCloseButton?: false;\n};\n\ntype CloseButtonProps = {\n /**\n * An accessible label for the close button.\n * */\n closeButtonAriaLabel: string;\n /**\n * Shows the close button if set to `true`. Must be used in conjunction with `closeButtonAriaLabel`.\n * */\n showCloseButton: true;\n};\n\nexport type ModalContentProps = DefaultProps & (CloseButtonProps | NoCloseButtonProps);\n\nconst hasCloseButtonProps = (\n props: CloseButtonProps | NoCloseButtonProps\n): props is CloseButtonProps => (props as CloseButtonProps).showCloseButton === true;\n\nconst cx = c.bind(styles);\nconst rootClassName = \"purpur-modal-content\";\n\nexport const ModalContent = forwardRef<HTMLDivElement, ModalContentProps>(\n (\n {\n [\"data-testid\"]: dataTestId,\n actions,\n children,\n className,\n description,\n disableCloseOnClickOutside,\n hideDescription,\n image,\n stickyButtons = true,\n title,\n notification = undefined,\n zIndex,\n onCloseAutoFocus,\n ...props\n },\n ref\n ) => {\n const { closeButtonAriaLabel, showCloseButton, ...rest } = props;\n const [contentOverflow, setContentOverflow] = useState(false);\n const [scrollbarWidth, setScrollbarWidth] = useState(0);\n const wrapperRef = useRef<HTMLDivElement>(null);\n const wrapperInnerRef = useRef<HTMLDivElement>(null);\n\n const classes = cx(\n rootClassName,\n { [`${rootClassName}--with-image`]: !!image },\n { [`${rootClassName}--overflow`]: contentOverflow },\n { [`${rootClassName}--sticky-footer`]: stickyButtons },\n className\n );\n\n const getTestId = (id: string) => (dataTestId ? `${dataTestId} ${id}` : undefined);\n\n const handlePointerDownOutside = (event: CustomEvent<{ originalEvent: PointerEvent }>) => {\n if (disableCloseOnClickOutside) {\n event.preventDefault();\n }\n };\n\n const handleContentOverflow = useCallback(() => {\n if (!wrapperRef.current || !wrapperInnerRef.current) {\n return;\n }\n\n const computedStyle = window.getComputedStyle(wrapperRef.current, null);\n const wrapperHeight = parseFloat(computedStyle.getPropertyValue(\"height\"));\n const innerHeight = wrapperInnerRef.current.offsetHeight;\n\n setContentOverflow(wrapperHeight < innerHeight);\n\n setScrollbarWidth(\n (wrapperRef.current.offsetWidth ?? 0) - (wrapperRef.current.clientWidth ?? 0)\n );\n }, []);\n\n const handleInitialFocus = () => {\n const frame = wrapperInnerRef.current;\n if (frame) {\n const heading = frame.querySelector(\"h2\");\n\n heading &&\n setTimeout(() => {\n heading.focus();\n });\n }\n };\n\n const handleEscapeKeyDown = (event: KeyboardEvent) => {\n if (disableCloseOnClickOutside && !showCloseButton) {\n event.preventDefault();\n }\n };\n\n useEffect(() => {\n window.addEventListener(\"resize\", handleContentOverflow);\n\n return () => {\n window.removeEventListener(\"resize\", handleContentOverflow);\n };\n }, [handleContentOverflow]);\n\n useEffect(() => {\n handleContentOverflow();\n }, [notification, children, handleContentOverflow]);\n\n return (\n <RadixPortal>\n <RadixOverlay className={cx(`${rootClassName}__overlay`)} style={{ zIndex }} />\n <RadixContent\n {...rest}\n className={classes}\n data-testid={dataTestId}\n ref={ref}\n {...(!description && { [\"aria-describedby\"]: undefined })}\n onPointerDownOutside={handlePointerDownOutside}\n onOpenAutoFocus={() => {\n handleContentOverflow();\n handleInitialFocus();\n }}\n onEscapeKeyDown={handleEscapeKeyDown}\n onCloseAutoFocus={onCloseAutoFocus}\n style={{ zIndex: `calc(${zIndex} + 1)` }}\n >\n <div ref={wrapperRef} className={cx(`${rootClassName}__wrapper`)}>\n {hasCloseButtonProps(props) && closeButtonAriaLabel && image && (\n <CloseButton\n aria-label={closeButtonAriaLabel}\n hasImage\n scrollbarWidth={scrollbarWidth}\n data-testid={getTestId(\"close-button\")}\n />\n )}\n <div ref={wrapperInnerRef} className={cx(`${rootClassName}__wrapper-inner`)}>\n <div className={cx(`${rootClassName}__header`)}>\n {hasCloseButtonProps(props) && closeButtonAriaLabel && !image && (\n <CloseButton\n aria-label={closeButtonAriaLabel}\n data-testid={getTestId(\"close-button\")}\n />\n )}\n <RadixTitle\n asChild\n className={cx(`${rootClassName}__title`)}\n data-testid={getTestId(\"title\")}\n >\n <Heading\n tag=\"h2\"\n variant=\"display-10\"\n tabIndex={-1}\n className={cx(`${rootClassName}__heading`)}\n >\n {title}\n </Heading>\n </RadixTitle>\n </div>\n {image && (\n <div\n className={cx(`${rootClassName}__image-wrapper`)}\n data-testid={getTestId(\"image\")}\n >\n {image}\n </div>\n )}\n <div className={cx(`${rootClassName}__body`)}>\n <div className={cx(`${rootClassName}__body-inner`)}>\n {description && hideDescription && (\n <VisuallyHidden asChild>\n <RadixDescription data-testid={getTestId(\"description\")}>\n {description}\n </RadixDescription>\n </VisuallyHidden>\n )}\n {description && !hideDescription && (\n <RadixDescription\n asChild\n className={cx(`${rootClassName}__description`)}\n data-testid={getTestId(\"description\")}\n >\n <Paragraph variant=\"paragraph-100\">{description}</Paragraph>\n </RadixDescription>\n )}\n <div>{children}</div>\n {!stickyButtons && <ModalActions actions={actions} notification={notification} />}\n </div>\n </div>\n </div>\n </div>\n\n {stickyButtons && <ModalActions actions={actions} notification={notification} />}\n </RadixContent>\n </RadixPortal>\n );\n }\n);\n\nconst CloseButton = ({\n [\"aria-label\"]: ariaLabel,\n hasImage,\n scrollbarWidth,\n [\"data-testid\"]: dataTestId,\n}: {\n [\"aria-label\"]: string;\n hasImage?: boolean;\n scrollbarWidth?: number;\n [\"data-testid\"]?: string;\n}) => (\n <RadixClose asChild>\n <Button\n variant={hasImage ? \"primary\" : \"tertiary-purple\"}\n negative={hasImage}\n size=\"sm\"\n iconOnly\n aria-label={ariaLabel}\n className={cx(`${rootClassName}__close-button`)}\n style={{ right: `calc(var(--purpur-spacing-100) + ${scrollbarWidth || 0}px)` }}\n data-testid={dataTestId}\n >\n <IconClose />\n </Button>\n </RadixClose>\n);\n\nexport const MAX_NUMBER_OF_ACTIONS = 3;\n\nexport const ModalActions = ({\n actions,\n notification,\n}: Pick<ModalContentProps, \"actions\" | \"notification\">) => {\n const notificationRef = useRef<HTMLDivElement>(null);\n\n useEffect(() => {\n if (notification) {\n notificationRef?.current?.scrollIntoView?.(false);\n }\n }, [notification]);\n\n return actions ? (\n <div className={cx(`${rootClassName}__actions`)}>\n <div className={cx(`${rootClassName}__actions-buttons`)} data-testid=\"modal actions\">\n {actions}\n </div>\n {notification && (\n <div className={cx(`${rootClassName}__notification`)} ref={notificationRef}>\n {notification}\n </div>\n )}\n <span className={cx(`${rootClassName}__actions-separator`)} />\n </div>\n ) : null;\n};\n","import React, { forwardRef, type ReactNode } from \"react\";\nimport type { BaseProps } from \"@purpur/common-types\";\nimport { Trigger as RadixTrigger } from \"@radix-ui/react-dialog\";\n\nexport type ModalTriggerProps = Omit<BaseProps<\"button\">, \"children\"> & {\n children: ReactNode;\n};\n\nexport const ModalTrigger = forwardRef<HTMLButtonElement, ModalTriggerProps>(\n ({ children, ...props }, ref) => {\n return (\n <RadixTrigger asChild ref={ref} {...props}>\n {children}\n </RadixTrigger>\n );\n }\n);\n","import React, { type ReactNode } from \"react\";\nimport { Root as RadixRoot } from \"@radix-ui/react-dialog\";\n\nimport { ModalContent } from \"./modal-content\";\nimport { ModalTrigger } from \"./modal-trigger\";\n\nexport type ModalProps = {\n [\"data-testid\"]?: string;\n children: ReactNode;\n /**\n * Event handler called when the open state of the dialog changes.\n * */\n onOpenChange?: (value: boolean) => void;\n /**\n * The controlled open state of the dialog. Must be used in conjunction with `onOpenChange`.\n * */\n open?: boolean;\n};\n\nexport const Modal = ({\n [\"data-testid\"]: dataTestId,\n children,\n open,\n onOpenChange,\n}: ModalProps) => (\n <RadixRoot open={open} onOpenChange={onOpenChange} data-testid={dataTestId}>\n {children}\n </RadixRoot>\n);\n\nModal.Trigger = ModalTrigger;\nModal.Content = ModalContent;\n\nModal.displayName = \"Modal\";\n"],"names":["hasCloseButtonProps","props","cx","c","styles","rootClassName","ModalContent","forwardRef","dataTestId","actions","children","className","description","disableCloseOnClickOutside","hideDescription","image","stickyButtons","title","notification","zIndex","onCloseAutoFocus","ref","closeButtonAriaLabel","showCloseButton","rest","contentOverflow","setContentOverflow","useState","scrollbarWidth","setScrollbarWidth","wrapperRef","useRef","wrapperInnerRef","classes","getTestId","id","handlePointerDownOutside","event","handleContentOverflow","useCallback","computedStyle","wrapperHeight","innerHeight","handleInitialFocus","frame","heading","handleEscapeKeyDown","useEffect","RadixPortal","jsx","RadixOverlay","jsxs","RadixContent","CloseButton","RadixTitle","Heading","VisuallyHidden","RadixDescription","Paragraph","ModalActions","ariaLabel","hasImage","RadixClose","Button","IconClose","notificationRef","ModalTrigger","RadixTrigger","Modal","open","onOpenChange","RadixRoot"],"mappings":"+5DAwFMA,EACJC,GAC+BA,EAA2B,kBAAoB,GAE1EC,EAAKC,EAAAA,EAAE,KAAKC,CAAM,EAClBC,EAAgB,uBAETC,EAAeC,EAAAA,WAC1B,CACE,CACE,CAAC,eAAgBC,EACjB,QAAAC,EACA,SAAAC,EACA,UAAAC,EACA,YAAAC,EACA,2BAAAC,EACA,gBAAAC,EACA,MAAAC,EACA,cAAAC,EAAgB,GAChB,MAAAC,EACA,aAAAC,EAAe,OACf,OAAAC,EACA,iBAAAC,EACA,GAAGnB,CAAA,EAELoB,IACG,CACH,KAAM,CAAE,qBAAAC,EAAsB,gBAAAC,EAAiB,GAAGC,GAASvB,EACrD,CAACwB,EAAiBC,CAAkB,EAAIC,EAAAA,SAAS,EAAK,EACtD,CAACC,EAAgBC,CAAiB,EAAIF,EAAAA,SAAS,CAAC,EAChDG,EAAaC,EAAAA,OAAuB,IAAI,EACxCC,EAAkBD,EAAAA,OAAuB,IAAI,EAE7CE,EAAU/B,EACdG,EACA,CAAE,CAAC,GAAGA,CAAa,cAAc,EAAG,CAAC,CAACU,CAAA,EACtC,CAAE,CAAC,GAAGV,CAAa,YAAY,EAAGoB,CAAA,EAClC,CAAE,CAAC,GAAGpB,CAAa,iBAAiB,EAAGW,CAAA,EACvCL,CAAA,EAGIuB,EAAaC,GAAgB3B,EAAa,GAAGA,CAAU,IAAI2B,CAAE,GAAK,OAElEC,EAA4BC,GAAwD,CACpFxB,GACFwB,EAAM,eAAA,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AAI,UAAW/C,EAAG,GAAGG,CAAa,mBAAmB,EAAG,cAAY,gBAClE,SAAAI,CAAA,CACH,EACCS,GACC+B,EAAAA,IAAC,MAAA,CAAI,UAAW/C,EAAG,GAAGG,CAAa,gBAAgB,EAAG,IAAK4D,EACxD,SAAA/C,CAAA,CACH,QAED,OAAA,CAAK,UAAWhB,EAAG,GAAGG,CAAa,qBAAqB,CAAA,CAAG,CAAA,CAAA,CAC9D,EACE,IACN,EC/Ta6D,GAAe3D,EAAAA,WAC1B,CAAC,CAAE,SAAAG,EAAU,GAAGT,CAAA,EAASoB,UAEpB8C,EAAAA,QAAA,CAAa,QAAO,GAAC,IAAA9C,EAAW,GAAGpB,EACjC,SAAAS,EACH,CAGN,ECGa0D,EAAQ,CAAC,CACpB,CAAC,eAAgB5D,EACjB,SAAAE,EACA,KAAA2D,EACA,aAAAC,CACF,UACGC,EAAAA,KAAA,CAAU,KAAAF,EAAY,aAAAC,EAA4B,cAAa9D,EAC7D,SAAAE,CAAA,CACH,EAGF0D,EAAM,QAAUF,GAChBE,EAAM,QAAU9D,EAEhB8D,EAAM,YAAc"}
|
package/dist/modal.cjs.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./modal-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./modal-COF_UhvY.js");exports.Modal=e.Modal;
|
|
2
2
|
//# sourceMappingURL=modal.cjs.js.map
|
package/dist/modal.es.js
CHANGED