@ayseaistudio/ui-components 3.12.5 → 3.12.6
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/Label/Label.js +17 -4
- package/package.json +1 -1
package/dist/Label/Label.js
CHANGED
|
@@ -39,9 +39,16 @@ export const Label = ({ text, title, leftIcon, rightIcon, size, color, version,
|
|
|
39
39
|
const tooltipTimerRef = useRef(undefined);
|
|
40
40
|
const [isTooltipVisible, setIsTooltipVisible] = useState(false);
|
|
41
41
|
const labelRef = useRef(null);
|
|
42
|
+
const textRef = useRef(null);
|
|
42
43
|
const [anchorPos, setAnchorPos] = useState({ left: 0, top: 0 });
|
|
43
44
|
const hasLabelText = typeof text === "string" && text.trim().length > 0;
|
|
44
45
|
const tooltipText = hasLabelText ? (tooltip || text || "") : (tooltip || "");
|
|
46
|
+
const isTextTruncated = () => {
|
|
47
|
+
if (!textRef.current)
|
|
48
|
+
return false;
|
|
49
|
+
const el = textRef.current;
|
|
50
|
+
return el.scrollWidth > el.clientWidth || el.scrollHeight > el.clientHeight;
|
|
51
|
+
};
|
|
45
52
|
useEffect(() => {
|
|
46
53
|
return () => {
|
|
47
54
|
if (tooltipTimerRef.current) {
|
|
@@ -50,11 +57,16 @@ export const Label = ({ text, title, leftIcon, rightIcon, size, color, version,
|
|
|
50
57
|
};
|
|
51
58
|
}, []);
|
|
52
59
|
const handleMouseEnter = () => {
|
|
53
|
-
if (!tooltipText)
|
|
60
|
+
if (!useInfoTooltip || !tooltipText)
|
|
61
|
+
return;
|
|
62
|
+
if (!isTextTruncated())
|
|
54
63
|
return;
|
|
55
64
|
const rect = labelRef.current?.getBoundingClientRect();
|
|
56
65
|
if (rect) {
|
|
57
|
-
setAnchorPos({
|
|
66
|
+
setAnchorPos({
|
|
67
|
+
left: rect.left + rect.width / 2,
|
|
68
|
+
top: rect.bottom,
|
|
69
|
+
});
|
|
58
70
|
}
|
|
59
71
|
tooltipTimerRef.current = window.setTimeout(() => {
|
|
60
72
|
setIsTooltipVisible(true);
|
|
@@ -70,14 +82,15 @@ export const Label = ({ text, title, leftIcon, rightIcon, size, color, version,
|
|
|
70
82
|
return (_jsxs(_Fragment, { children: [_jsxs("div", { className: `label ${size} ${strokeClass} ${spacing} ${color} ${className} ${hover ? "hover-move" : ""}`, title: title, onClick: onClick, "data-testid": "label", onMouseEnter: handleMouseEnter, onMouseLeave: handleMouseLeave, style: { cursor: hover ? "pointer" : "default" }, ref: labelRef, children: [leftIcon && (React.cloneElement(leftIcon, {
|
|
71
83
|
className: getIconClassName(size),
|
|
72
84
|
color: getIconColor(version, color)
|
|
73
|
-
})), text && (_jsx("div", { className: `text-wrapper ${version} bold-${bold} size-${size} color-${color} ${divClassName || ""}`, children: text })), rightIcon && (React.cloneElement(rightIcon, {
|
|
85
|
+
})), text && (_jsx("div", { ref: textRef, className: `text-wrapper ${version} bold-${bold} size-${size} color-${color} ${divClassName || ""}`, children: text })), rightIcon && (React.cloneElement(rightIcon, {
|
|
74
86
|
className: getIconClassName(size),
|
|
75
87
|
color: getIconColor(version, color)
|
|
76
88
|
}))] }), isTooltipVisible && useInfoTooltip
|
|
77
89
|
? createPortal(_jsx("div", { style: {
|
|
78
90
|
position: "fixed",
|
|
79
91
|
top: Math.min(anchorPos.top + 6, (typeof window !== "undefined" ? window.innerHeight : 0) - 100),
|
|
80
|
-
left: Math.max(8, Math.min(anchorPos.left, (typeof window !== "undefined" ? window.innerWidth : 0) -
|
|
92
|
+
left: Math.max(8, Math.min(anchorPos.left, (typeof window !== "undefined" ? window.innerWidth : 0) - 8)),
|
|
93
|
+
transform: "translateX(-50%)",
|
|
81
94
|
zIndex: 9999,
|
|
82
95
|
pointerEvents: "none",
|
|
83
96
|
}, children: _jsx(InfoTooltip, { text: tooltipText, withIcon: tooltipWithIcon }) }), document.body)
|