@cronocode/react-box 3.0.14 → 3.0.15
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/tooltip.cjs +1 -1
- package/components/tooltip.mjs +28 -30
- package/package.json +1 -1
package/components/tooltip.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const
|
|
1
|
+
"use strict";const i=require("react/jsx-runtime"),C=require("react-dom"),d=require("../box.cjs"),s=require("react"),R=require("../core.cjs"),l=2;function m(f,w){const{onPositionChange:a}=f,c=s.useRef(null),[t,b]=s.useState(),h=R.usePortalContainer(),x=s.useCallback((r,e)=>{const n=p=>{p.target.contains(r)&&e(r)},o=new AbortController;return document.addEventListener("scroll",n,{signal:o.signal,capture:!0}),()=>o.abort()},[t]),g=s.useCallback((r,e)=>{const n=p=>{e(r)},o=new AbortController;return window.addEventListener("resize",n,{signal:o.signal,capture:!0}),()=>o.abort()},[t]),u=s.useCallback(r=>{const e=r.getBoundingClientRect(),n=Math.round((e.top+window.scrollY)*l)/l,o=Math.round((e.left+window.scrollX)*l)/l;((t==null?void 0:t.top)!==n||(t==null?void 0:t.left)!==o)&&(a==null||a({top:n,left:o}),b({top:n,left:o,width:e.width>0?e.width:void 0}))},[t]);return s.useLayoutEffect(()=>{if(c.current){u(c.current);const r=x(c.current,u),e=g(c.current,u);return()=>{r(),e()}}},[t]),i.jsxs(i.Fragment,{children:[i.jsx(d,{ref:c}),t&&C.createPortal(i.jsx(d,{ref:w,position:"absolute",top:0,left:0,transition:"none",style:{transform:`translate(${t.left}px,${t.top}px)`,width:t.width},children:i.jsx(d,{position:"absolute",width:"fit",...f})}),h)]})}const j=s.forwardRef(m);module.exports=j;
|
package/components/tooltip.mjs
CHANGED
|
@@ -1,63 +1,61 @@
|
|
|
1
1
|
import { jsxs as x, Fragment as C, jsx as a } from "react/jsx-runtime";
|
|
2
|
-
import { createPortal as
|
|
2
|
+
import { createPortal as v } from "react-dom";
|
|
3
3
|
import u from "../box.mjs";
|
|
4
|
-
import { forwardRef as
|
|
5
|
-
import { f as
|
|
4
|
+
import { forwardRef as R, useRef as z, useState as A, useCallback as f, useLayoutEffect as D } from "react";
|
|
5
|
+
import { f as E } from "../core.mjs";
|
|
6
6
|
const i = 2;
|
|
7
|
-
function H(
|
|
8
|
-
const { onPositionChange: l } =
|
|
9
|
-
(
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
},
|
|
13
|
-
return document.addEventListener("scroll", r,
|
|
7
|
+
function H(d, w) {
|
|
8
|
+
const { onPositionChange: l } = d, s = z(null), [t, m] = A(), b = E(), h = f(
|
|
9
|
+
(e, o) => {
|
|
10
|
+
const n = (p) => {
|
|
11
|
+
p.target.contains(e) && o(e);
|
|
12
|
+
}, r = new AbortController();
|
|
13
|
+
return document.addEventListener("scroll", n, { signal: r.signal, capture: !0 }), () => r.abort();
|
|
14
14
|
},
|
|
15
15
|
[t]
|
|
16
|
-
),
|
|
17
|
-
(
|
|
18
|
-
const
|
|
19
|
-
e
|
|
20
|
-
};
|
|
21
|
-
return window.addEventListener("resize",
|
|
22
|
-
window.removeEventListener("resize", r, { capture: !0 });
|
|
23
|
-
};
|
|
16
|
+
), g = f(
|
|
17
|
+
(e, o) => {
|
|
18
|
+
const n = (p) => {
|
|
19
|
+
o(e);
|
|
20
|
+
}, r = new AbortController();
|
|
21
|
+
return window.addEventListener("resize", n, { signal: r.signal, capture: !0 }), () => r.abort();
|
|
24
22
|
},
|
|
25
23
|
[t]
|
|
26
|
-
), c =
|
|
27
|
-
(
|
|
28
|
-
const
|
|
29
|
-
((t == null ? void 0 : t.top) !==
|
|
24
|
+
), c = f(
|
|
25
|
+
(e) => {
|
|
26
|
+
const o = e.getBoundingClientRect(), n = Math.round((o.top + window.scrollY) * i) / i, r = Math.round((o.left + window.scrollX) * i) / i;
|
|
27
|
+
((t == null ? void 0 : t.top) !== n || (t == null ? void 0 : t.left) !== r) && (l == null || l({ top: n, left: r }), m({ top: n, left: r, width: o.width > 0 ? o.width : void 0 }));
|
|
30
28
|
},
|
|
31
29
|
[t]
|
|
32
30
|
);
|
|
33
|
-
return
|
|
31
|
+
return D(() => {
|
|
34
32
|
if (s.current) {
|
|
35
33
|
c(s.current);
|
|
36
|
-
const
|
|
34
|
+
const e = h(s.current, c), o = g(s.current, c);
|
|
37
35
|
return () => {
|
|
38
|
-
|
|
36
|
+
e(), o();
|
|
39
37
|
};
|
|
40
38
|
}
|
|
41
39
|
}, [t]), /* @__PURE__ */ x(C, { children: [
|
|
42
40
|
/* @__PURE__ */ a(u, { ref: s }),
|
|
43
|
-
t &&
|
|
41
|
+
t && v(
|
|
44
42
|
/* @__PURE__ */ a(
|
|
45
43
|
u,
|
|
46
44
|
{
|
|
47
|
-
ref:
|
|
45
|
+
ref: w,
|
|
48
46
|
position: "absolute",
|
|
49
47
|
top: 0,
|
|
50
48
|
left: 0,
|
|
51
49
|
transition: "none",
|
|
52
50
|
style: { transform: `translate(${t.left}px,${t.top}px)`, width: t.width },
|
|
53
|
-
children: /* @__PURE__ */ a(u, { position: "absolute", width: "fit", ...
|
|
51
|
+
children: /* @__PURE__ */ a(u, { position: "absolute", width: "fit", ...d })
|
|
54
52
|
}
|
|
55
53
|
),
|
|
56
|
-
|
|
54
|
+
b
|
|
57
55
|
)
|
|
58
56
|
] });
|
|
59
57
|
}
|
|
60
|
-
const M =
|
|
58
|
+
const M = R(H);
|
|
61
59
|
export {
|
|
62
60
|
M as default
|
|
63
61
|
};
|