@overdoser/react-toolkit 0.16.0 → 0.18.0
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/AGENTS.md +1 -1
- package/CHANGELOG.md +74 -0
- package/components/Chart/AreaChart.d.ts +5 -1
- package/components/Chart/AreaChart.js +155 -144
- package/components/Chart/BarChart.js +5 -5
- package/components/Chart/PieChart.js +2 -5
- package/components/Chart/RadarChart.js +2 -5
- package/components/Chart/TradingChart.js +258 -257
- package/components/Drawer/Drawer.js +69 -70
- package/components/Dropdown/Dropdown.js +51 -56
- package/components/Loader/Loader.d.ts +104 -0
- package/components/Loader/Loader.js +186 -0
- package/components/Loader/Loader.module.scss.js +70 -0
- package/components/Loader/index.d.ts +2 -0
- package/components/Modal/Modal.js +42 -47
- package/components/Popover/Popover.js +52 -55
- package/components/SplitButton/SplitButton.js +50 -55
- package/components/inputs/DatePicker/DatePicker.js +82 -76
- package/components/inputs/DateTimePicker/DateTimePicker.js +4 -2
- package/components/inputs/DateTimePicker/DateTimeSegments.d.ts +2 -1
- package/components/inputs/DateTimePicker/DateTimeSegments.js +1 -1
- package/components/inputs/NumberInput/NumberInput.js +79 -81
- package/components/inputs/Select/Select.d.ts +5 -0
- package/components/inputs/Select/Select.js +340 -285
- package/hooks/useEscapeLayer.d.ts +36 -0
- package/hooks/useEscapeLayer.js +33 -0
- package/index.css +1 -1
- package/index.d.ts +2 -0
- package/index.js +74 -72
- package/index.layered.css +1 -1
- package/llms.txt +43 -2
- package/manifest.json +73 -0
- package/package.json +1 -1
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { jsxs as V, jsx as m } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef as D, useRef as P, useLayoutEffect as Y, useEffect as _, useState as $ } from "react";
|
|
3
|
+
import { createPortal as q } from "react-dom";
|
|
4
|
+
import c from "clsx";
|
|
5
|
+
import t from "./Loader.module.scss.js";
|
|
6
|
+
const G = {
|
|
7
|
+
dots: 3,
|
|
8
|
+
pulse: 3,
|
|
9
|
+
spinner: 1,
|
|
10
|
+
grid: 9,
|
|
11
|
+
morph: 2
|
|
12
|
+
};
|
|
13
|
+
function I(l) {
|
|
14
|
+
const o = l.getBoundingClientRect();
|
|
15
|
+
let e = Math.max(o.top, 0), r = Math.min(o.bottom, window.innerHeight);
|
|
16
|
+
for (let n = l.parentElement; n && n !== document.body; n = n.parentElement) {
|
|
17
|
+
const u = getComputedStyle(n).overflowY;
|
|
18
|
+
if (u === "visible" || u === "") continue;
|
|
19
|
+
const v = n.getBoundingClientRect();
|
|
20
|
+
e = Math.max(e, v.top), r = Math.min(r, v.bottom);
|
|
21
|
+
}
|
|
22
|
+
return { top: e, bottom: r };
|
|
23
|
+
}
|
|
24
|
+
function z(l, o) {
|
|
25
|
+
Y(() => {
|
|
26
|
+
const e = l.current;
|
|
27
|
+
if (!o || !e) return;
|
|
28
|
+
let r = 0;
|
|
29
|
+
const n = () => {
|
|
30
|
+
r = 0;
|
|
31
|
+
const f = e.getBoundingClientRect(), b = e.firstElementChild, { top: h, bottom: g } = I(e);
|
|
32
|
+
let d = 0;
|
|
33
|
+
if (g > h && f.height > 0) {
|
|
34
|
+
d = (h + g) / 2 - (f.top + f.bottom) / 2;
|
|
35
|
+
const i = Math.max(0, f.height / 2 - (b?.offsetHeight ?? 0) / 2 - 8);
|
|
36
|
+
d = Math.max(-i, Math.min(i, d));
|
|
37
|
+
}
|
|
38
|
+
e.style.setProperty("--_shift-y", `${Math.round(d)}px`);
|
|
39
|
+
}, u = () => {
|
|
40
|
+
r || (r = requestAnimationFrame(n));
|
|
41
|
+
};
|
|
42
|
+
n(), window.addEventListener("scroll", u, { capture: !0, passive: !0 }), window.addEventListener("resize", u);
|
|
43
|
+
const v = new ResizeObserver(u);
|
|
44
|
+
return v.observe(e), () => {
|
|
45
|
+
r && cancelAnimationFrame(r), window.removeEventListener("scroll", u, { capture: !0 }), window.removeEventListener("resize", u), v.disconnect();
|
|
46
|
+
};
|
|
47
|
+
}, [l, o]);
|
|
48
|
+
}
|
|
49
|
+
function J(l, o) {
|
|
50
|
+
const [e, r] = $(l && o <= 0);
|
|
51
|
+
return _(() => {
|
|
52
|
+
if (!l) {
|
|
53
|
+
r(!1);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
if (o <= 0) {
|
|
57
|
+
r(!0);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const n = setTimeout(() => r(!0), o);
|
|
61
|
+
return () => clearTimeout(n);
|
|
62
|
+
}, [l, o]), l && e;
|
|
63
|
+
}
|
|
64
|
+
const K = D(
|
|
65
|
+
({
|
|
66
|
+
variant: l = "dots",
|
|
67
|
+
size: o = "md",
|
|
68
|
+
mode: e = "inline",
|
|
69
|
+
loading: r = !0,
|
|
70
|
+
children: n,
|
|
71
|
+
delay: u = 0,
|
|
72
|
+
backdrop: v = "dim",
|
|
73
|
+
interactive: f = !1,
|
|
74
|
+
color: b,
|
|
75
|
+
label: h = "Loading",
|
|
76
|
+
showLabel: g = !1,
|
|
77
|
+
minHeight: d,
|
|
78
|
+
classes: i,
|
|
79
|
+
className: w,
|
|
80
|
+
style: x,
|
|
81
|
+
...E
|
|
82
|
+
}, L) => {
|
|
83
|
+
const a = J(r, u), p = n != null, N = P(null), S = P(null), k = P(null), R = (s) => {
|
|
84
|
+
N.current = s, typeof L == "function" ? L(s) : L && (L.current = s);
|
|
85
|
+
}, H = !p && e === "overlay" && a;
|
|
86
|
+
Y(() => {
|
|
87
|
+
if (!H) return;
|
|
88
|
+
const s = N.current?.parentElement;
|
|
89
|
+
if (!s) return;
|
|
90
|
+
const M = s.getAttribute("aria-busy");
|
|
91
|
+
s.setAttribute("aria-busy", "true");
|
|
92
|
+
const F = getComputedStyle(s).position, O = F === "static" || F === "", j = s.style.position;
|
|
93
|
+
return O && (s.style.position = "relative"), () => {
|
|
94
|
+
O && (s.style.position = j), M === null ? s.removeAttribute("aria-busy") : s.setAttribute("aria-busy", M);
|
|
95
|
+
};
|
|
96
|
+
}, [H]), z(p ? k : N, a && e !== "fullscreen" && (p || e === "overlay")), _(() => {
|
|
97
|
+
S.current?.toggleAttribute("inert", a && !f);
|
|
98
|
+
}, [a, f]);
|
|
99
|
+
const y = b ? { "--crk-loader-color": b } : void 0, A = typeof d == "number" ? `${d}px` : d, C = /* @__PURE__ */ V(
|
|
100
|
+
"span",
|
|
101
|
+
{
|
|
102
|
+
role: "status",
|
|
103
|
+
"aria-live": "polite",
|
|
104
|
+
className: c(t.indicator, i?.indicator),
|
|
105
|
+
children: [
|
|
106
|
+
/* @__PURE__ */ m("span", { className: c(t.glyph, t[l], i?.glyph), "aria-hidden": "true", children: Array.from({ length: G[l] }, (s, M) => /* @__PURE__ */ m("span", {}, M)) }),
|
|
107
|
+
h ? /* @__PURE__ */ m("span", { className: c(g ? t.label : t.srLabel, i?.label), children: h }) : null
|
|
108
|
+
]
|
|
109
|
+
}
|
|
110
|
+
), B = {
|
|
111
|
+
dim: t.backdropDim,
|
|
112
|
+
blur: t.backdropBlur,
|
|
113
|
+
none: void 0
|
|
114
|
+
}[v], T = a && e === "fullscreen" && typeof document < "u" ? q(
|
|
115
|
+
/* @__PURE__ */ m(
|
|
116
|
+
"div",
|
|
117
|
+
{
|
|
118
|
+
ref: p ? void 0 : R,
|
|
119
|
+
className: c(
|
|
120
|
+
// Portaled out of the wrapper, so it carries the tokens itself.
|
|
121
|
+
t.root,
|
|
122
|
+
t[o],
|
|
123
|
+
t.overlay,
|
|
124
|
+
t.fullscreen,
|
|
125
|
+
B,
|
|
126
|
+
i?.overlay,
|
|
127
|
+
!p && [i?.root, w]
|
|
128
|
+
),
|
|
129
|
+
style: p ? y : { ...y, ...x },
|
|
130
|
+
...p ? {} : E,
|
|
131
|
+
children: C
|
|
132
|
+
}
|
|
133
|
+
),
|
|
134
|
+
document.body
|
|
135
|
+
) : null;
|
|
136
|
+
return p ? /* @__PURE__ */ V(
|
|
137
|
+
"div",
|
|
138
|
+
{
|
|
139
|
+
ref: R,
|
|
140
|
+
className: c(t.root, t[o], t.wrap, a && t.wrapBusy, i?.root, w),
|
|
141
|
+
style: { ...y, ...a && A ? { minHeight: A } : null, ...x },
|
|
142
|
+
"aria-busy": r || void 0,
|
|
143
|
+
...E,
|
|
144
|
+
children: [
|
|
145
|
+
/* @__PURE__ */ m("div", { ref: S, className: c(t.content, i?.content), children: n }),
|
|
146
|
+
a && e !== "fullscreen" && /* @__PURE__ */ m(
|
|
147
|
+
"div",
|
|
148
|
+
{
|
|
149
|
+
ref: k,
|
|
150
|
+
className: c(
|
|
151
|
+
t.overlay,
|
|
152
|
+
B,
|
|
153
|
+
f && t.passThrough,
|
|
154
|
+
i?.overlay
|
|
155
|
+
),
|
|
156
|
+
children: C
|
|
157
|
+
}
|
|
158
|
+
),
|
|
159
|
+
T
|
|
160
|
+
]
|
|
161
|
+
}
|
|
162
|
+
) : a ? e === "fullscreen" ? T : e === "overlay" ? /* @__PURE__ */ m(
|
|
163
|
+
"div",
|
|
164
|
+
{
|
|
165
|
+
ref: R,
|
|
166
|
+
className: c(t.root, t[o], t.overlay, B, i?.root, i?.overlay, w),
|
|
167
|
+
style: { ...y, ...x },
|
|
168
|
+
...E,
|
|
169
|
+
children: C
|
|
170
|
+
}
|
|
171
|
+
) : /* @__PURE__ */ m(
|
|
172
|
+
"div",
|
|
173
|
+
{
|
|
174
|
+
ref: R,
|
|
175
|
+
className: c(t.root, t[o], t.inline, i?.root, w),
|
|
176
|
+
style: { ...y, ...A ? { minHeight: A } : null, ...x },
|
|
177
|
+
...E,
|
|
178
|
+
children: C
|
|
179
|
+
}
|
|
180
|
+
) : null;
|
|
181
|
+
}
|
|
182
|
+
);
|
|
183
|
+
K.displayName = "Loader";
|
|
184
|
+
export {
|
|
185
|
+
K as Loader
|
|
186
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
const r = "crk-root-u1D7u", o = "crk-sm-M6Sb3", c = "crk-md-5c9sz", e = "crk-lg-PaoKK", t = "crk-inline-neVjU", a = "crk-wrap-BaBNd", k = "crk-wrapBusy-a4D7Z", l = "crk-content-bw8zV", n = "crk-overlay-B-AIp", s = "crk-crk-loader-enter-VxXmo", d = "crk-indicator-LqmYc", p = "crk-fullscreen-BXAhh", h = "crk-backdropDim-JqArB", u = "crk-backdropBlur-wV2vo", i = "crk-passThrough-NCa9b", b = "crk-glyph-L8nf5", L = "crk-label-yMjMY", m = "crk-srLabel-PDGoC", B = "crk-dots-KfhUo", g = "crk-pulse-wPxve", y = "crk-crk-loader-dot-bounce-NtrLY", D = "crk-crk-loader-dot-pulse-AolCU", w = "crk-spinner-xG6h2", C = "crk-crk-loader-rotate-yVTPr", A = "crk-grid-5nFwV", V = "crk-crk-loader-cell-A7li4", v = "crk-morph-DAgji", x = "crk-crk-loader-morph-1hxzv", P = "crk-crk-loader-breathe-RCpGC", f = {
|
|
2
|
+
root: r,
|
|
3
|
+
sm: o,
|
|
4
|
+
md: c,
|
|
5
|
+
lg: e,
|
|
6
|
+
inline: t,
|
|
7
|
+
wrap: a,
|
|
8
|
+
wrapBusy: k,
|
|
9
|
+
content: l,
|
|
10
|
+
overlay: n,
|
|
11
|
+
"crk-loader-enter": "crk-crk-loader-enter-VxXmo",
|
|
12
|
+
crkLoaderEnter: s,
|
|
13
|
+
indicator: d,
|
|
14
|
+
fullscreen: p,
|
|
15
|
+
backdropDim: h,
|
|
16
|
+
backdropBlur: u,
|
|
17
|
+
passThrough: i,
|
|
18
|
+
glyph: b,
|
|
19
|
+
label: L,
|
|
20
|
+
srLabel: m,
|
|
21
|
+
dots: B,
|
|
22
|
+
pulse: g,
|
|
23
|
+
"crk-loader-dot-bounce": "crk-crk-loader-dot-bounce-NtrLY",
|
|
24
|
+
crkLoaderDotBounce: y,
|
|
25
|
+
"crk-loader-dot-pulse": "crk-crk-loader-dot-pulse-AolCU",
|
|
26
|
+
crkLoaderDotPulse: D,
|
|
27
|
+
spinner: w,
|
|
28
|
+
"crk-loader-rotate": "crk-crk-loader-rotate-yVTPr",
|
|
29
|
+
crkLoaderRotate: C,
|
|
30
|
+
grid: A,
|
|
31
|
+
"crk-loader-cell": "crk-crk-loader-cell-A7li4",
|
|
32
|
+
crkLoaderCell: V,
|
|
33
|
+
morph: v,
|
|
34
|
+
"crk-loader-morph": "crk-crk-loader-morph-1hxzv",
|
|
35
|
+
crkLoaderMorph: x,
|
|
36
|
+
"crk-loader-breathe": "crk-crk-loader-breathe-RCpGC",
|
|
37
|
+
crkLoaderBreathe: P
|
|
38
|
+
};
|
|
39
|
+
export {
|
|
40
|
+
u as backdropBlur,
|
|
41
|
+
h as backdropDim,
|
|
42
|
+
l as content,
|
|
43
|
+
P as crkLoaderBreathe,
|
|
44
|
+
V as crkLoaderCell,
|
|
45
|
+
y as crkLoaderDotBounce,
|
|
46
|
+
D as crkLoaderDotPulse,
|
|
47
|
+
s as crkLoaderEnter,
|
|
48
|
+
x as crkLoaderMorph,
|
|
49
|
+
C as crkLoaderRotate,
|
|
50
|
+
f as default,
|
|
51
|
+
B as dots,
|
|
52
|
+
p as fullscreen,
|
|
53
|
+
b as glyph,
|
|
54
|
+
A as grid,
|
|
55
|
+
d as indicator,
|
|
56
|
+
t as inline,
|
|
57
|
+
L as label,
|
|
58
|
+
e as lg,
|
|
59
|
+
c as md,
|
|
60
|
+
v as morph,
|
|
61
|
+
n as overlay,
|
|
62
|
+
i as passThrough,
|
|
63
|
+
g as pulse,
|
|
64
|
+
r as root,
|
|
65
|
+
o as sm,
|
|
66
|
+
w as spinner,
|
|
67
|
+
m as srLabel,
|
|
68
|
+
a as wrap,
|
|
69
|
+
k as wrapBusy
|
|
70
|
+
};
|
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import { jsx as l, jsxs as
|
|
2
|
-
import { forwardRef as
|
|
3
|
-
import { createPortal as
|
|
1
|
+
import { jsx as l, jsxs as E } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef as H, useRef as h, useId as P, useEffect as j, createContext as D, useContext as p } from "react";
|
|
3
|
+
import { createPortal as L } from "react-dom";
|
|
4
4
|
import d from "clsx";
|
|
5
5
|
import { useFocusTrap as O } from "../../hooks/useFocusTrap.js";
|
|
6
|
-
import {
|
|
6
|
+
import { useEscapeLayer as U, EscapeLayerProvider as S } from "../../hooks/useEscapeLayer.js";
|
|
7
7
|
import a from "./Modal.module.scss.js";
|
|
8
|
-
const u =
|
|
9
|
-
const { classes: n, titleId: c } =
|
|
10
|
-
return /* @__PURE__ */
|
|
8
|
+
const u = D({ classes: {}, titleId: "" }), M = ({ children: e, className: t, style: s, onClose: r }) => {
|
|
9
|
+
const { classes: n, titleId: c } = p(u);
|
|
10
|
+
return /* @__PURE__ */ E(
|
|
11
11
|
"div",
|
|
12
12
|
{
|
|
13
13
|
id: c,
|
|
14
|
-
className: d(a.header,
|
|
14
|
+
className: d(a.header, r && a.headerWithClose, n.header, t),
|
|
15
15
|
style: s,
|
|
16
16
|
children: [
|
|
17
17
|
e,
|
|
18
|
-
|
|
18
|
+
r && /* @__PURE__ */ l(
|
|
19
19
|
"button",
|
|
20
20
|
{
|
|
21
21
|
type: "button",
|
|
22
22
|
className: d(a.closeButton, n.closeButton),
|
|
23
|
-
onClick:
|
|
23
|
+
onClick: r,
|
|
24
24
|
"aria-label": "Close",
|
|
25
25
|
children: "×"
|
|
26
26
|
}
|
|
@@ -30,73 +30,68 @@ const u = E({ classes: {}, titleId: "" }), M = ({ children: e, className: r, sty
|
|
|
30
30
|
);
|
|
31
31
|
};
|
|
32
32
|
M.displayName = "Modal.Header";
|
|
33
|
-
const N = ({ children: e, className:
|
|
34
|
-
const { classes:
|
|
35
|
-
return /* @__PURE__ */ l("div", { className: d(a.body,
|
|
33
|
+
const N = ({ children: e, className: t, style: s }) => {
|
|
34
|
+
const { classes: r } = p(u);
|
|
35
|
+
return /* @__PURE__ */ l("div", { className: d(a.body, r.body, t), style: s, children: e });
|
|
36
36
|
};
|
|
37
37
|
N.displayName = "Modal.Body";
|
|
38
|
-
const B = ({ children: e, className:
|
|
39
|
-
const { classes:
|
|
40
|
-
return /* @__PURE__ */ l("div", { className: d(a.footer,
|
|
38
|
+
const B = ({ children: e, className: t, style: s }) => {
|
|
39
|
+
const { classes: r } = p(u);
|
|
40
|
+
return /* @__PURE__ */ l("div", { className: d(a.footer, r.footer, t), style: s, children: e });
|
|
41
41
|
};
|
|
42
42
|
B.displayName = "Modal.Footer";
|
|
43
|
-
const m =
|
|
43
|
+
const m = H(
|
|
44
44
|
({
|
|
45
45
|
open: e,
|
|
46
|
-
onClose:
|
|
46
|
+
onClose: t,
|
|
47
47
|
closeOnBackdrop: s = !0,
|
|
48
|
-
closeOnEscape:
|
|
48
|
+
closeOnEscape: r = !0,
|
|
49
49
|
size: n = "md",
|
|
50
50
|
classes: c,
|
|
51
|
-
className:
|
|
52
|
-
style:
|
|
53
|
-
children:
|
|
54
|
-
"aria-label":
|
|
55
|
-
"aria-labelledby":
|
|
51
|
+
className: w,
|
|
52
|
+
style: x,
|
|
53
|
+
children: k,
|
|
54
|
+
"aria-label": y,
|
|
55
|
+
"aria-labelledby": C
|
|
56
56
|
}, i) => {
|
|
57
|
-
const b =
|
|
57
|
+
const b = h(null), g = (o) => {
|
|
58
58
|
b.current = o, typeof i == "function" ? i(o) : i && (i.current = o);
|
|
59
|
-
}, I =
|
|
59
|
+
}, I = P(), v = C ?? `${I}-title`;
|
|
60
60
|
O(b, e);
|
|
61
|
-
const F =
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
}),
|
|
67
|
-
[t, r]
|
|
68
|
-
);
|
|
69
|
-
S(F, e), U(() => {
|
|
61
|
+
const F = U(() => {
|
|
62
|
+
r && t();
|
|
63
|
+
}, e);
|
|
64
|
+
j(() => {
|
|
70
65
|
if (!e) return;
|
|
71
66
|
const o = document.body.style.overflow;
|
|
72
67
|
return document.body.style.overflow = "hidden", () => {
|
|
73
68
|
document.body.style.overflow = o;
|
|
74
69
|
};
|
|
75
70
|
}, [e]);
|
|
76
|
-
const f =
|
|
71
|
+
const f = h(!1), R = (o) => {
|
|
77
72
|
f.current = o.target === o.currentTarget;
|
|
78
|
-
},
|
|
79
|
-
s && f.current && o.target === o.currentTarget &&
|
|
73
|
+
}, T = (o) => {
|
|
74
|
+
s && f.current && o.target === o.currentTarget && t(), f.current = !1;
|
|
80
75
|
};
|
|
81
|
-
return e ?
|
|
76
|
+
return e ? L(
|
|
82
77
|
/* @__PURE__ */ l(
|
|
83
78
|
"div",
|
|
84
79
|
{
|
|
85
80
|
className: d(a.backdrop, c?.backdrop),
|
|
86
|
-
onMouseDown:
|
|
87
|
-
onMouseUp:
|
|
81
|
+
onMouseDown: R,
|
|
82
|
+
onMouseUp: T,
|
|
88
83
|
role: "presentation",
|
|
89
84
|
children: /* @__PURE__ */ l(
|
|
90
85
|
"div",
|
|
91
86
|
{
|
|
92
|
-
ref:
|
|
93
|
-
className: d(a.modal, a[n], c?.modal,
|
|
94
|
-
style:
|
|
87
|
+
ref: g,
|
|
88
|
+
className: d(a.modal, a[n], c?.modal, w),
|
|
89
|
+
style: x,
|
|
95
90
|
role: "dialog",
|
|
96
91
|
"aria-modal": "true",
|
|
97
|
-
"aria-label":
|
|
98
|
-
"aria-labelledby":
|
|
99
|
-
children: /* @__PURE__ */ l(u.Provider, { value: { classes: c ?? {}, titleId:
|
|
92
|
+
"aria-label": y,
|
|
93
|
+
"aria-labelledby": y ? void 0 : v,
|
|
94
|
+
children: /* @__PURE__ */ l(u.Provider, { value: { classes: c ?? {}, titleId: v }, children: /* @__PURE__ */ l(S, { value: F, children: k }) })
|
|
100
95
|
}
|
|
101
96
|
)
|
|
102
97
|
}
|
|
@@ -1,75 +1,72 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { forwardRef as
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import { useClickOutside as
|
|
6
|
-
import {
|
|
7
|
-
function
|
|
1
|
+
import { jsx as y, jsxs as K } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef as Q, useState as E, useRef as B, useId as U, useCallback as O, useLayoutEffect as Z, useEffect as _, isValidElement as ee, cloneElement as te } from "react";
|
|
3
|
+
import R from "clsx";
|
|
4
|
+
import L from "./Popover.module.scss.js";
|
|
5
|
+
import { useClickOutside as oe } from "../../hooks/useClickOutside.js";
|
|
6
|
+
import { useEscapeLayer as re, EscapeLayerProvider as ne } from "../../hooks/useEscapeLayer.js";
|
|
7
|
+
function ie(...a) {
|
|
8
8
|
return (h) => {
|
|
9
|
-
for (const
|
|
10
|
-
|
|
9
|
+
for (const l of a)
|
|
10
|
+
l && (typeof l == "function" ? l(h) : l.current = h);
|
|
11
11
|
};
|
|
12
12
|
}
|
|
13
|
-
const
|
|
13
|
+
const se = Q(
|
|
14
14
|
({
|
|
15
15
|
trigger: a,
|
|
16
16
|
asChild: h = !1,
|
|
17
|
-
content:
|
|
17
|
+
content: l,
|
|
18
18
|
position: n = "bottom",
|
|
19
19
|
autoPosition: m = !0,
|
|
20
20
|
open: j,
|
|
21
21
|
onOpenChange: z,
|
|
22
22
|
classes: g,
|
|
23
|
-
className:
|
|
24
|
-
style:
|
|
25
|
-
},
|
|
26
|
-
const [
|
|
23
|
+
className: H,
|
|
24
|
+
style: T
|
|
25
|
+
}, V) => {
|
|
26
|
+
const [W, A] = E(!1), [D, M] = E(n), [F, P] = E(0), [G, X] = E(0), Y = B(null), u = B(null), v = B(null), k = U(), C = j !== void 0, o = C ? j : W, w = O(
|
|
27
27
|
(t) => {
|
|
28
|
-
C ||
|
|
28
|
+
C || A(t), z?.(t);
|
|
29
29
|
},
|
|
30
30
|
[C, z]
|
|
31
|
-
),
|
|
31
|
+
), $ = O(() => {
|
|
32
32
|
w(!1), v.current?.focus();
|
|
33
|
-
}, [w]),
|
|
33
|
+
}, [w]), q = O(() => {
|
|
34
34
|
w(!o);
|
|
35
35
|
}, [o, w]);
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
},
|
|
40
|
-
o
|
|
41
|
-
), U(() => {
|
|
36
|
+
oe(Y, $, o);
|
|
37
|
+
const J = re($, o);
|
|
38
|
+
Z(() => {
|
|
42
39
|
if (!o || !m) {
|
|
43
|
-
M(n),
|
|
40
|
+
M(n), P(0), X(0);
|
|
44
41
|
return;
|
|
45
42
|
}
|
|
46
43
|
if (typeof window > "u") return;
|
|
47
44
|
const t = () => {
|
|
48
45
|
const b = v.current, x = u.current;
|
|
49
46
|
if (!b || !x) return;
|
|
50
|
-
const s = b.getBoundingClientRect(), i = x.getBoundingClientRect(),
|
|
47
|
+
const s = b.getBoundingClientRect(), i = x.getBoundingClientRect(), I = window.innerWidth, S = window.innerHeight, r = 8;
|
|
51
48
|
let c = n;
|
|
52
49
|
if (n === "bottom" || n === "top") {
|
|
53
|
-
const e = s.bottom + r + i.height <=
|
|
50
|
+
const e = s.bottom + r + i.height <= S, p = s.top - r - i.height >= 0;
|
|
54
51
|
n === "bottom" && !e && p ? c = "top" : n === "top" && !p && e && (c = "bottom");
|
|
55
52
|
} else {
|
|
56
|
-
const e = s.right + r + i.width <=
|
|
53
|
+
const e = s.right + r + i.width <= I, p = s.left - r - i.width >= 0;
|
|
57
54
|
n === "right" && !e && p ? c = "left" : n === "left" && !p && e && (c = "right");
|
|
58
55
|
}
|
|
59
|
-
let
|
|
56
|
+
let f = 0, d = 0;
|
|
60
57
|
if (c === "bottom" || c === "top") {
|
|
61
58
|
const e = s.left + s.width / 2 - i.width / 2;
|
|
62
|
-
e < r ?
|
|
59
|
+
e < r ? f = r - e : e + i.width > I - r && (f = I - r - (e + i.width));
|
|
63
60
|
} else {
|
|
64
61
|
const e = s.top + s.height / 2 - i.height / 2;
|
|
65
|
-
e < r ? d = r - e : e + i.height >
|
|
62
|
+
e < r ? d = r - e : e + i.height > S - r && (d = S - r - (e + i.height));
|
|
66
63
|
}
|
|
67
|
-
|
|
64
|
+
f = Math.round(f), d = Math.round(d), M((e) => e === c ? e : c), P((e) => e === f ? e : f), X((e) => e === d ? e : d);
|
|
68
65
|
};
|
|
69
66
|
return t(), window.addEventListener("scroll", t, !0), window.addEventListener("resize", t), () => {
|
|
70
67
|
window.removeEventListener("scroll", t, !0), window.removeEventListener("resize", t);
|
|
71
68
|
};
|
|
72
|
-
}, [o, m, n]),
|
|
69
|
+
}, [o, m, n]), _(() => {
|
|
73
70
|
if (o && u.current) {
|
|
74
71
|
const t = u.current.querySelector(
|
|
75
72
|
'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])'
|
|
@@ -77,54 +74,54 @@ const ne = J(
|
|
|
77
74
|
t ? t.focus() : u.current.focus();
|
|
78
75
|
}
|
|
79
76
|
}, [o]);
|
|
80
|
-
let
|
|
81
|
-
if (h &&
|
|
77
|
+
let N;
|
|
78
|
+
if (h && ee(a)) {
|
|
82
79
|
const t = a, b = t.ref;
|
|
83
|
-
|
|
84
|
-
ref:
|
|
80
|
+
N = te(t, {
|
|
81
|
+
ref: ie(v, b),
|
|
85
82
|
onClick: (x) => {
|
|
86
|
-
t.props.onClick?.(x),
|
|
83
|
+
t.props.onClick?.(x), q();
|
|
87
84
|
},
|
|
88
|
-
className:
|
|
85
|
+
className: R(t.props.className, g?.trigger),
|
|
89
86
|
"aria-expanded": o,
|
|
90
87
|
"aria-haspopup": "dialog",
|
|
91
88
|
"aria-controls": o ? k : void 0
|
|
92
89
|
});
|
|
93
90
|
} else
|
|
94
|
-
|
|
91
|
+
N = /* @__PURE__ */ y(
|
|
95
92
|
"button",
|
|
96
93
|
{
|
|
97
94
|
ref: v,
|
|
98
95
|
type: "button",
|
|
99
|
-
className:
|
|
100
|
-
onClick:
|
|
96
|
+
className: R(L.trigger, g?.trigger),
|
|
97
|
+
onClick: q,
|
|
101
98
|
"aria-expanded": o,
|
|
102
99
|
"aria-haspopup": "dialog",
|
|
103
100
|
"aria-controls": o ? k : void 0,
|
|
104
101
|
children: a
|
|
105
102
|
}
|
|
106
103
|
);
|
|
107
|
-
return /* @__PURE__ */
|
|
104
|
+
return /* @__PURE__ */ y(
|
|
108
105
|
"div",
|
|
109
106
|
{
|
|
110
|
-
ref:
|
|
111
|
-
className:
|
|
112
|
-
style:
|
|
113
|
-
children: /* @__PURE__ */
|
|
114
|
-
|
|
115
|
-
o && /* @__PURE__ */
|
|
107
|
+
ref: V,
|
|
108
|
+
className: R(L.root, g?.root, H),
|
|
109
|
+
style: T,
|
|
110
|
+
children: /* @__PURE__ */ K("div", { ref: Y, children: [
|
|
111
|
+
N,
|
|
112
|
+
o && /* @__PURE__ */ y(
|
|
116
113
|
"div",
|
|
117
114
|
{
|
|
118
115
|
ref: u,
|
|
119
116
|
id: k,
|
|
120
117
|
role: "dialog",
|
|
121
118
|
tabIndex: -1,
|
|
122
|
-
className:
|
|
119
|
+
className: R(L.popover, L[m ? D : n], g?.popover),
|
|
123
120
|
style: m ? {
|
|
124
|
-
"--crk-popover-shift-x": `${
|
|
125
|
-
"--crk-popover-shift-y": `${
|
|
121
|
+
"--crk-popover-shift-x": `${F}px`,
|
|
122
|
+
"--crk-popover-shift-y": `${G}px`
|
|
126
123
|
} : void 0,
|
|
127
|
-
children:
|
|
124
|
+
children: /* @__PURE__ */ y(ne, { value: J, children: l })
|
|
128
125
|
}
|
|
129
126
|
)
|
|
130
127
|
] })
|
|
@@ -132,7 +129,7 @@ const ne = J(
|
|
|
132
129
|
);
|
|
133
130
|
}
|
|
134
131
|
);
|
|
135
|
-
|
|
132
|
+
se.displayName = "Popover";
|
|
136
133
|
export {
|
|
137
|
-
|
|
134
|
+
se as Popover
|
|
138
135
|
};
|