@overdoser/react-toolkit 0.8.0 → 0.8.1
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/components/Modal/Modal.js +61 -56
- package/package.json +1 -1
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import { jsx as l, jsxs as
|
|
2
|
-
import { forwardRef as
|
|
1
|
+
import { jsx as l, jsxs as T } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef as j, useRef as v, useId as D, useMemo as P, useEffect as U, createContext as E, useContext as y } from "react";
|
|
3
3
|
import { createPortal as K } from "react-dom";
|
|
4
|
-
import
|
|
5
|
-
import { useFocusTrap as
|
|
6
|
-
import { useKeyboard as
|
|
7
|
-
import
|
|
8
|
-
const
|
|
9
|
-
const { classes:
|
|
10
|
-
return /* @__PURE__ */
|
|
4
|
+
import d from "clsx";
|
|
5
|
+
import { useFocusTrap as O } from "../../hooks/useFocusTrap.js";
|
|
6
|
+
import { useKeyboard as S } from "../../hooks/useKeyboard.js";
|
|
7
|
+
import a from "./Modal.module.scss.js";
|
|
8
|
+
const u = E({ classes: {}, titleId: "" }), M = ({ children: e, className: r, style: s, onClose: t }) => {
|
|
9
|
+
const { classes: n, titleId: c } = y(u);
|
|
10
|
+
return /* @__PURE__ */ T(
|
|
11
11
|
"div",
|
|
12
12
|
{
|
|
13
|
-
id:
|
|
14
|
-
className:
|
|
15
|
-
style:
|
|
13
|
+
id: c,
|
|
14
|
+
className: d(a.header, t && a.headerWithClose, n.header, r),
|
|
15
|
+
style: s,
|
|
16
16
|
children: [
|
|
17
17
|
e,
|
|
18
|
-
|
|
18
|
+
t && /* @__PURE__ */ l(
|
|
19
19
|
"button",
|
|
20
20
|
{
|
|
21
21
|
type: "button",
|
|
22
|
-
className:
|
|
23
|
-
onClick:
|
|
22
|
+
className: d(a.closeButton, n.closeButton),
|
|
23
|
+
onClick: t,
|
|
24
24
|
"aria-label": "Close",
|
|
25
25
|
children: "×"
|
|
26
26
|
}
|
|
@@ -29,69 +29,74 @@ const n = E({ classes: {}, titleId: "" }), p = ({ children: e, className: t, sty
|
|
|
29
29
|
}
|
|
30
30
|
);
|
|
31
31
|
};
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
const { classes:
|
|
35
|
-
return /* @__PURE__ */ l("div", { className:
|
|
32
|
+
M.displayName = "Modal.Header";
|
|
33
|
+
const N = ({ children: e, className: r, style: s }) => {
|
|
34
|
+
const { classes: t } = y(u);
|
|
35
|
+
return /* @__PURE__ */ l("div", { className: d(a.body, t.body, r), style: s, children: e });
|
|
36
36
|
};
|
|
37
|
-
|
|
38
|
-
const
|
|
39
|
-
const { classes:
|
|
40
|
-
return /* @__PURE__ */ l("div", { className:
|
|
37
|
+
N.displayName = "Modal.Body";
|
|
38
|
+
const B = ({ children: e, className: r, style: s }) => {
|
|
39
|
+
const { classes: t } = y(u);
|
|
40
|
+
return /* @__PURE__ */ l("div", { className: d(a.footer, t.footer, r), style: s, children: e });
|
|
41
41
|
};
|
|
42
|
-
|
|
43
|
-
const m =
|
|
42
|
+
B.displayName = "Modal.Footer";
|
|
43
|
+
const m = j(
|
|
44
44
|
({
|
|
45
45
|
open: e,
|
|
46
|
-
onClose:
|
|
47
|
-
closeOnBackdrop:
|
|
48
|
-
closeOnEscape:
|
|
49
|
-
size:
|
|
50
|
-
classes:
|
|
51
|
-
className:
|
|
52
|
-
style:
|
|
46
|
+
onClose: r,
|
|
47
|
+
closeOnBackdrop: s = !0,
|
|
48
|
+
closeOnEscape: t = !0,
|
|
49
|
+
size: n = "md",
|
|
50
|
+
classes: c,
|
|
51
|
+
className: k,
|
|
52
|
+
style: w,
|
|
53
53
|
children: x,
|
|
54
|
-
"aria-label":
|
|
55
|
-
"aria-labelledby":
|
|
56
|
-
},
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
54
|
+
"aria-label": p,
|
|
55
|
+
"aria-labelledby": g
|
|
56
|
+
}, i) => {
|
|
57
|
+
const b = v(null), C = (o) => {
|
|
58
|
+
b.current = o, typeof i == "function" ? i(o) : i && (i.current = o);
|
|
59
|
+
}, I = D(), h = g ?? `${I}-title`;
|
|
60
|
+
O(b, e);
|
|
61
|
+
const F = P(
|
|
60
62
|
() => ({
|
|
61
63
|
Escape: () => {
|
|
62
|
-
|
|
64
|
+
t && r();
|
|
63
65
|
}
|
|
64
66
|
}),
|
|
65
|
-
[
|
|
67
|
+
[t, r]
|
|
66
68
|
);
|
|
67
|
-
|
|
69
|
+
S(F, e), U(() => {
|
|
68
70
|
if (!e) return;
|
|
69
|
-
const
|
|
71
|
+
const o = document.body.style.overflow;
|
|
70
72
|
return document.body.style.overflow = "hidden", () => {
|
|
71
|
-
document.body.style.overflow =
|
|
73
|
+
document.body.style.overflow = o;
|
|
72
74
|
};
|
|
73
75
|
}, [e]);
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
+
const f = v(!1), H = (o) => {
|
|
77
|
+
f.current = o.target === o.currentTarget;
|
|
78
|
+
}, R = (o) => {
|
|
79
|
+
s && f.current && o.target === o.currentTarget && r(), f.current = !1;
|
|
76
80
|
};
|
|
77
81
|
return e ? K(
|
|
78
82
|
/* @__PURE__ */ l(
|
|
79
83
|
"div",
|
|
80
84
|
{
|
|
81
|
-
className:
|
|
82
|
-
|
|
85
|
+
className: d(a.backdrop, c?.backdrop),
|
|
86
|
+
onMouseDown: H,
|
|
87
|
+
onMouseUp: R,
|
|
83
88
|
role: "presentation",
|
|
84
89
|
children: /* @__PURE__ */ l(
|
|
85
90
|
"div",
|
|
86
91
|
{
|
|
87
|
-
ref:
|
|
88
|
-
className:
|
|
89
|
-
style:
|
|
92
|
+
ref: C,
|
|
93
|
+
className: d(a.modal, a[n], c?.modal, k),
|
|
94
|
+
style: w,
|
|
90
95
|
role: "dialog",
|
|
91
96
|
"aria-modal": "true",
|
|
92
|
-
"aria-label":
|
|
93
|
-
"aria-labelledby":
|
|
94
|
-
children: /* @__PURE__ */ l(
|
|
97
|
+
"aria-label": p,
|
|
98
|
+
"aria-labelledby": p ? void 0 : h,
|
|
99
|
+
children: /* @__PURE__ */ l(u.Provider, { value: { classes: c ?? {}, titleId: h }, children: x })
|
|
95
100
|
}
|
|
96
101
|
)
|
|
97
102
|
}
|
|
@@ -101,9 +106,9 @@ const m = R(
|
|
|
101
106
|
}
|
|
102
107
|
);
|
|
103
108
|
m.displayName = "Modal";
|
|
104
|
-
m.Header =
|
|
105
|
-
m.Body =
|
|
106
|
-
m.Footer =
|
|
109
|
+
m.Header = M;
|
|
110
|
+
m.Body = N;
|
|
111
|
+
m.Footer = B;
|
|
107
112
|
export {
|
|
108
113
|
m as Modal
|
|
109
114
|
};
|