cynx-lib 1.3.88 → 1.3.89
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/package.json +1 -1
- package/ui/components/HoverCard.jsx +85 -81
package/package.json
CHANGED
|
@@ -1,81 +1,85 @@
|
|
|
1
|
-
import { useState, useRef, useEffect } from 'react';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* HoverCard — reusable tooltip/popover on hover
|
|
5
|
-
*
|
|
6
|
-
* Props:
|
|
7
|
-
* trigger — React node as hover target
|
|
8
|
-
* children — popup content
|
|
9
|
-
* position — 'top' | 'bottom' (default: 'top')
|
|
10
|
-
* width — min-width (default: 180)
|
|
11
|
-
* style — extra popup styles
|
|
12
|
-
*
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
{
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
1
|
+
import { useState, useRef, useEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* HoverCard — reusable tooltip/popover on hover
|
|
5
|
+
*
|
|
6
|
+
* Props:
|
|
7
|
+
* trigger — React node as hover target
|
|
8
|
+
* children — popup content
|
|
9
|
+
* position — 'top' | 'bottom' (default: 'top')
|
|
10
|
+
* width — min-width (default: 180)
|
|
11
|
+
* style — extra popup styles
|
|
12
|
+
* arrow — show arrow indicator (default: false)
|
|
13
|
+
* style — extra popup styles
|
|
14
|
+
* triggerStyle — extra trigger wrapper styles
|
|
15
|
+
*/
|
|
16
|
+
export default function HoverCard({ trigger, children, position = 'top', width = 180, arrow = false, style, triggerStyle }) {
|
|
17
|
+
const [open, setOpen] = useState(false);
|
|
18
|
+
const [pos, setPos] = useState({ x: 0, y: 0 });
|
|
19
|
+
const wrapRef = useRef(null);
|
|
20
|
+
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
if (open && wrapRef.current) {
|
|
23
|
+
const r = wrapRef.current.getBoundingClientRect();
|
|
24
|
+
setPos({ x: r.left + r.width / 2, y: position === 'top' ? r.top : r.bottom });
|
|
25
|
+
}
|
|
26
|
+
}, [open, position]);
|
|
27
|
+
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
if (!open) return;
|
|
30
|
+
const close = (e) => {
|
|
31
|
+
if (wrapRef.current && !wrapRef.current.contains(e.target)) setOpen(false);
|
|
32
|
+
};
|
|
33
|
+
document.addEventListener('mousedown', close);
|
|
34
|
+
return () => document.removeEventListener('mousedown', close);
|
|
35
|
+
}, [open]);
|
|
36
|
+
|
|
37
|
+
return (
|
|
38
|
+
<div
|
|
39
|
+
ref={wrapRef}
|
|
40
|
+
onMouseEnter={() => setOpen(true)}
|
|
41
|
+
onMouseLeave={() => setOpen(false)}
|
|
42
|
+
style={{ display: 'inline-block', position: 'relative', ...triggerStyle }}
|
|
43
|
+
>
|
|
44
|
+
{trigger}
|
|
45
|
+
{open && (
|
|
46
|
+
<div style={{
|
|
47
|
+
position: 'fixed',
|
|
48
|
+
left: pos.x,
|
|
49
|
+
top: position === 'top' ? 'auto' : pos.y + 6,
|
|
50
|
+
bottom: position === 'top' ? window.innerHeight - pos.y + 6 : 'auto',
|
|
51
|
+
transform: 'translateX(-50%)',
|
|
52
|
+
zIndex: 9999,
|
|
53
|
+
minWidth: width,
|
|
54
|
+
background: 'var(--surface,#fff)',
|
|
55
|
+
border: '1px solid var(--border, #e2e8f0)',
|
|
56
|
+
borderRadius: 'var(--rads, 8px)',
|
|
57
|
+
padding: '10px 14px',
|
|
58
|
+
boxShadow: 'var(--smd, 0 4px 12px rgba(0,0,0,.12))',
|
|
59
|
+
pointerEvents: 'none',
|
|
60
|
+
animation: 'hoverCardIn .15s ease',
|
|
61
|
+
...style,
|
|
62
|
+
}}>
|
|
63
|
+
{children}
|
|
64
|
+
{arrow && (
|
|
65
|
+
<div style={{
|
|
66
|
+
position: 'absolute', left: '50%',
|
|
67
|
+
[position === 'top' ? 'bottom' : 'top']: -5,
|
|
68
|
+
transform: 'translateX(-50%) rotate(45deg)',
|
|
69
|
+
width: 8, height: 8, background: 'var(--surface,#fff)',
|
|
70
|
+
borderRight: '1px solid var(--border, #e2e8f0)',
|
|
71
|
+
borderBottom: position === 'top' ? 'none' : '1px solid var(--border, #e2e8f0)',
|
|
72
|
+
borderTop: position === 'top' ? '1px solid var(--border, #e2e8f0)' : 'none',
|
|
73
|
+
}} />
|
|
74
|
+
)}
|
|
75
|
+
</div>
|
|
76
|
+
)}
|
|
77
|
+
<style>{`
|
|
78
|
+
@keyframes hoverCardIn {
|
|
79
|
+
from { opacity: 0; transform: translateX(-50%) translateY(4px); }
|
|
80
|
+
to { opacity: 1; transform: translateX(-50%) translateY(0); }
|
|
81
|
+
}
|
|
82
|
+
`}</style>
|
|
83
|
+
</div>
|
|
84
|
+
);
|
|
85
|
+
}
|