@cosxai/ui 0.8.2 → 0.8.3
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/src/primitives/Tooltip.tsx +24 -3
package/package.json
CHANGED
|
@@ -37,6 +37,13 @@ export interface TooltipProps {
|
|
|
37
37
|
// Render even if `content` is falsy. Default false — callers can
|
|
38
38
|
// wrap unconditionally without branching JSX.
|
|
39
39
|
alwaysRender?: boolean;
|
|
40
|
+
// When true, force the tooltip to a single line and truncate
|
|
41
|
+
// overflow with an ellipsis. Default false — content wraps to
|
|
42
|
+
// multiple lines within `maxWidth`. Existing single-line labels
|
|
43
|
+
// (scan-status pill, date row) render identically because they
|
|
44
|
+
// fit within maxWidth without wrapping; longer hints (explanatory
|
|
45
|
+
// text under form fields, etc.) now display in full.
|
|
46
|
+
truncate?: boolean;
|
|
40
47
|
}
|
|
41
48
|
|
|
42
49
|
// AUTO_FLIP_THRESHOLD_PX = the vertical space "top" placement needs
|
|
@@ -51,6 +58,7 @@ export function Tooltip({
|
|
|
51
58
|
delay = 120,
|
|
52
59
|
placement = "auto",
|
|
53
60
|
alwaysRender = false,
|
|
61
|
+
truncate = false,
|
|
54
62
|
}: TooltipProps) {
|
|
55
63
|
const triggerRef = useRef<HTMLElement | null>(null);
|
|
56
64
|
const [open, setOpen] = useState(false);
|
|
@@ -174,9 +182,22 @@ export function Tooltip({
|
|
|
174
182
|
pointerEvents: "none",
|
|
175
183
|
zIndex: 9999,
|
|
176
184
|
maxWidth: 320,
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
185
|
+
// Default: wrap long hints. Opt-in `truncate` restores the old
|
|
186
|
+
// single-line-with-ellipsis behaviour for compact labels where
|
|
187
|
+
// horizontal overflow is preferable to a taller tooltip (e.g.
|
|
188
|
+
// dense toolbars). Single-line labels shorter than maxWidth
|
|
189
|
+
// render identically in both modes — the branch only matters
|
|
190
|
+
// when content would need multiple lines.
|
|
191
|
+
...(truncate
|
|
192
|
+
? {
|
|
193
|
+
whiteSpace: "nowrap" as const,
|
|
194
|
+
overflow: "hidden" as const,
|
|
195
|
+
textOverflow: "ellipsis" as const,
|
|
196
|
+
}
|
|
197
|
+
: {
|
|
198
|
+
whiteSpace: "normal" as const,
|
|
199
|
+
wordBreak: "break-word" as const,
|
|
200
|
+
}),
|
|
180
201
|
opacity: open && pos ? 1 : 0,
|
|
181
202
|
transition: "opacity 120ms ease",
|
|
182
203
|
};
|