@caseparts-org/caseblocks 0.0.104 → 0.0.105
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/atoms/Tooltip/Tooltip.js +41 -38
- package/package.json +1 -1
|
@@ -6,22 +6,22 @@ import '../../assets/Tooltip.css';const I = "_tooltip_17o7a_1", O = "_content_17
|
|
|
6
6
|
tooltip: I,
|
|
7
7
|
content: O
|
|
8
8
|
};
|
|
9
|
-
function $(
|
|
10
|
-
return
|
|
9
|
+
function $(l) {
|
|
10
|
+
return l ? l.includes(" ") ? l : `${l} center` : "top center";
|
|
11
11
|
}
|
|
12
|
-
function q(
|
|
13
|
-
const w = $(
|
|
12
|
+
function q(l) {
|
|
13
|
+
const w = $(l).toLowerCase(), [s, t] = w.split(" ");
|
|
14
14
|
return { side: ["top", "right", "bottom", "left"].includes(s) ? s : "top", align: t === "left" || t === "top" ? "start" : t === "right" || t === "bottom" ? "end" : "center" };
|
|
15
15
|
}
|
|
16
|
-
function G(
|
|
17
|
-
const n =
|
|
16
|
+
function G(l, w, s, t, d = 0) {
|
|
17
|
+
const n = l.getBoundingClientRect(), f = w.getBoundingClientRect();
|
|
18
18
|
let a = 0, c = 0;
|
|
19
19
|
s === "top" ? a = n.top - f.height - d : s === "bottom" ? a = n.bottom + d : s === "left" ? c = n.left - f.width - d : s === "right" && (c = n.right + d), s === "top" || s === "bottom" ? t === "start" ? c = n.left : t === "end" ? c = n.right - f.width : c = n.left + n.width / 2 - f.width / 2 : t === "start" ? a = n.top : t === "end" ? a = n.bottom - f.height : a = n.top + n.height / 2 - f.height / 2;
|
|
20
|
-
const
|
|
21
|
-
return a = Math.max(4, Math.min(v - f.height - 4, a)), c = Math.max(4, Math.min(
|
|
20
|
+
const y = window.innerWidth, v = window.innerHeight;
|
|
21
|
+
return a = Math.max(4, Math.min(v - f.height - 4, a)), c = Math.max(4, Math.min(y - f.width - 4, c)), { top: a, left: c };
|
|
22
22
|
}
|
|
23
23
|
const U = ({
|
|
24
|
-
tooltipClassName:
|
|
24
|
+
tooltipClassName: l,
|
|
25
25
|
contentClassName: w,
|
|
26
26
|
children: s,
|
|
27
27
|
trigger: t,
|
|
@@ -30,50 +30,53 @@ const U = ({
|
|
|
30
30
|
openDelay: f = 150,
|
|
31
31
|
closeDelay: a = 100,
|
|
32
32
|
leaveGraceMs: c = 0,
|
|
33
|
-
tooltipOffset:
|
|
33
|
+
tooltipOffset: y = 4
|
|
34
34
|
}) => {
|
|
35
|
-
const { side: v, align:
|
|
35
|
+
const { side: v, align: T } = q(d), [o, L] = i.useState(!1), [m, C] = i.useState(null), P = i.useRef(null), g = i.useRef(null), x = i.useRef(null), E = i.useRef(null), R = i.useRef(null), h = i.useRef(!1), p = (e) => {
|
|
36
36
|
e.current && (window.clearTimeout(e.current), e.current = null);
|
|
37
37
|
}, B = () => {
|
|
38
|
-
p(x), p(
|
|
38
|
+
p(x), p(E), p(R);
|
|
39
39
|
};
|
|
40
40
|
i.useEffect(() => () => B(), []);
|
|
41
41
|
const k = () => {
|
|
42
|
-
n || o || (p(x), x.current = window.setTimeout(() =>
|
|
42
|
+
n || o || (p(x), x.current = window.setTimeout(() => L(!0), f));
|
|
43
43
|
}, _ = () => {
|
|
44
|
-
o && (p(
|
|
45
|
-
|
|
44
|
+
o && (p(E), E.current = window.setTimeout(() => {
|
|
45
|
+
const e = P.current;
|
|
46
|
+
e && e.matches(":hover") || h.current || L(!1);
|
|
46
47
|
}, a));
|
|
47
48
|
}, z = () => {
|
|
48
49
|
if (o) {
|
|
49
|
-
if (p(
|
|
50
|
+
if (p(R), c <= 0) {
|
|
50
51
|
_();
|
|
51
52
|
return;
|
|
52
53
|
}
|
|
53
|
-
|
|
54
|
+
R.current = window.setTimeout(() => {
|
|
54
55
|
h.current || _();
|
|
55
56
|
}, c);
|
|
56
57
|
}
|
|
57
|
-
},
|
|
58
|
-
e == null || e(
|
|
58
|
+
}, b = (e, r) => (u) => {
|
|
59
|
+
e == null || e(u), r == null || r(u);
|
|
59
60
|
}, N = i.cloneElement(t, {
|
|
60
61
|
ref: (e) => {
|
|
61
62
|
const { ref: r } = t;
|
|
62
|
-
typeof r == "function" ? r(e) : r && (r.current = e),
|
|
63
|
+
typeof r == "function" ? r(e) : r && (r.current = e), P.current = e;
|
|
63
64
|
},
|
|
64
|
-
onPointerEnter:
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
65
|
+
onPointerEnter: b(t.props.onPointerEnter, () => {
|
|
66
|
+
p(E), p(R), o || k();
|
|
67
|
+
}),
|
|
68
|
+
onPointerLeave: b(t.props.onPointerLeave, z),
|
|
69
|
+
onFocus: b(t.props.onFocus, k),
|
|
70
|
+
onBlur: b(t.props.onBlur, _),
|
|
68
71
|
"aria-describedby": o ? "tooltip-popup" : void 0,
|
|
69
72
|
style: { ...t.props.style || {}, outline: "none" }
|
|
70
73
|
});
|
|
71
74
|
return i.useEffect(() => {
|
|
72
|
-
n && o && (B(),
|
|
75
|
+
n && o && (B(), L(!1));
|
|
73
76
|
}, [n]), i.useEffect(() => {
|
|
74
77
|
if (!o) return;
|
|
75
78
|
const e = (r) => {
|
|
76
|
-
r.key === "Escape" &&
|
|
79
|
+
r.key === "Escape" && L(!1);
|
|
77
80
|
};
|
|
78
81
|
return window.addEventListener("keydown", e), () => window.removeEventListener("keydown", e);
|
|
79
82
|
}, [o]), i.useLayoutEffect(() => {
|
|
@@ -81,21 +84,21 @@ const U = ({
|
|
|
81
84
|
C(null);
|
|
82
85
|
return;
|
|
83
86
|
}
|
|
84
|
-
const e =
|
|
87
|
+
const e = P.current, r = g.current;
|
|
85
88
|
if (!e || !r) return;
|
|
86
|
-
const
|
|
87
|
-
C(G(e, r, v,
|
|
89
|
+
const u = () => {
|
|
90
|
+
C(G(e, r, v, T, y));
|
|
88
91
|
};
|
|
89
|
-
return
|
|
90
|
-
window.removeEventListener("resize",
|
|
92
|
+
return u(), window.addEventListener("resize", u), window.addEventListener("scroll", u, !0), () => {
|
|
93
|
+
window.removeEventListener("resize", u), window.removeEventListener("scroll", u, !0);
|
|
91
94
|
};
|
|
92
|
-
}, [o, v,
|
|
95
|
+
}, [o, v, T, s, y]), i.useEffect(() => {
|
|
93
96
|
if (!o) return;
|
|
94
97
|
const e = (r) => {
|
|
95
|
-
const
|
|
96
|
-
if (!
|
|
98
|
+
const u = P.current, F = g.current;
|
|
99
|
+
if (!u || !F) return;
|
|
97
100
|
const M = r.target;
|
|
98
|
-
!
|
|
101
|
+
!u.contains(M) && !F.contains(M) && (h.current = !1, z());
|
|
99
102
|
};
|
|
100
103
|
return document.addEventListener("pointermove", e), () => document.removeEventListener("pointermove", e);
|
|
101
104
|
}, [o]), i.useEffect(() => {
|
|
@@ -111,8 +114,8 @@ const U = ({
|
|
|
111
114
|
role: "tooltip",
|
|
112
115
|
"aria-hidden": !o,
|
|
113
116
|
"data-side": v,
|
|
114
|
-
"data-align":
|
|
115
|
-
className: j(H.tooltip,
|
|
117
|
+
"data-align": T,
|
|
118
|
+
className: j(H.tooltip, l),
|
|
116
119
|
style: {
|
|
117
120
|
position: "absolute",
|
|
118
121
|
top: (m == null ? void 0 : m.top) ?? 0,
|
|
@@ -121,7 +124,7 @@ const U = ({
|
|
|
121
124
|
zIndex: 10
|
|
122
125
|
},
|
|
123
126
|
onPointerEnter: () => {
|
|
124
|
-
h.current = !0, p(
|
|
127
|
+
h.current = !0, p(E), p(R);
|
|
125
128
|
},
|
|
126
129
|
onPointerLeave: () => {
|
|
127
130
|
h.current = !1, z();
|