import {useLinkifiedString} from '@common/utils/hooks/use-linkified-string'; import {Fragment, useRef, useState} from 'react'; import {Button} from '@common/ui/buttons/button'; import {Trans} from '@common/i18n/trans'; import clsx from 'clsx'; import {useLayoutEffect} from '@react-aria/utils'; interface TruncatedDescriptionProps { description?: string; className?: string; } export function TruncatedDescription({ description, className, }: TruncatedDescriptionProps) { const linkifiedDescription = useLinkifiedString(description); const wrapperRef = useRef(null); const contentRef = useRef(null); const [isOverflowing, setIsOverflowing] = useState(false); const [isShowingAll, setIsShowingAll] = useState(false); useLayoutEffect(() => { const wrapperHeight = wrapperRef.current?.getBoundingClientRect().height || 0; const contentHeight = wrapperRef.current?.scrollHeight || 0; if (contentHeight > wrapperHeight) { setIsOverflowing(true); } }, []); if (!linkifiedDescription) return null; return (
{isOverflowing && ( )} ); }