import { useEffect, useRef, useState } from 'react' import classNames from 'classnames' import CaretDownIcon from '~/icons/compiled/CaretDown' const DEFAULT_CELL_HEIGHT = 220 const EXPANDED_CELL_HEIGHT = 600 export default function Truncate({ children }: { children: React.ReactNode }) { const scrollingEl = useRef(null) const contentsEl = useRef(null) const [isExpanded, setIsExpanded] = useState(false) const [isTruncated, setIsTruncated] = useState(false) useEffect(() => { if (!isExpanded) { scrollingEl.current?.scrollTo(0, 0) } }, [isExpanded]) useEffect(() => { if (!contentsEl.current || !scrollingEl.current) return const contentsHeight = contentsEl.current.getBoundingClientRect().height const scrollingHeight = scrollingEl.current.getBoundingClientRect().height setIsTruncated(contentsHeight > scrollingHeight) }, [children]) return (
{children}
) }