import { useEffect, useRef, useState } from 'react' import { cn } from '@/lib/utils' import { Popover, PopoverContent, PopoverTrigger, } from '@/components/ui/popover' import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, } from '@/components/ui/tooltip' interface Props { children: React.ReactNode className?: string contentClassName?: string } export default function LongText({ children, className = '', contentClassName = '', }: Props) { const ref = useRef(null) const [isOverflown, setIsOverflown] = useState(false) useEffect(() => { if (checkOverflow(ref.current)) { setIsOverflown(true) return } setIsOverflown(false) }, []) if (!isOverflown) return (
{children}
) return ( <>
{children}

{children}

{children}

{children}

) } const checkOverflow = (textContainer: HTMLDivElement | null) => { if (textContainer) { return ( textContainer.offsetHeight < textContainer.scrollHeight || textContainer.offsetWidth < textContainer.scrollWidth ) } return false }