diff --git a/apps/client/src/components/ui/auto-tooltip-text.tsx b/apps/client/src/components/ui/auto-tooltip-text.tsx new file mode 100644 index 00000000..419ec3d9 --- /dev/null +++ b/apps/client/src/components/ui/auto-tooltip-text.tsx @@ -0,0 +1,49 @@ +import { useRef, useState, ReactNode } from "react"; +import { Text, TextProps, Tooltip } from "@mantine/core"; + +type AutoTooltipTextProps = TextProps & { + children: ReactNode; + tooltipLabel?: string; + tooltipProps?: Omit< + React.ComponentProps, + "children" | "label" + >; +}; + +export function AutoTooltipText({ + children, + tooltipLabel, + tooltipProps, + ...textProps +}: AutoTooltipTextProps) { + const textRef = useRef(null); + const [isTruncated, setIsTruncated] = useState(false); + + const handleMouseEnter = () => { + const element = textRef.current; + if (element) { + setIsTruncated(element.scrollWidth > element.clientWidth); + } + }; + + const label = tooltipLabel ?? (typeof children === "string" ? children : ""); + + return ( + + + {children} + + + ); +}