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