import React, { useRef, useState } from 'react'; import { useIsRefOverflowingHorizontally } from 'wdk-client/Hooks/Overflow'; import { makeClassNameHelper } from 'wdk-client/Utils/ComponentUtils'; import 'wdk-client/Views/Strategy/OverflowingTextCell.scss'; const cx = makeClassNameHelper('OverflowingTextCell'); export function OverflowingTextCell(props: { value?: T }) { const ref = useRef(null); const isOverflowing = useIsRefOverflowingHorizontally(ref); const [ isExpanded, setExpanded ] = useState(false); const textContents = props.value || ''; const htmlContents = !isExpanded && isOverflowing ? textContents : textContents.split('\n').map((line, i) => {line}
); const contentsClassName = isOverflowing && isExpanded ? cx('--OverflowableContents', 'expanded') : cx('--OverflowableContents'); return (
{htmlContents} { isOverflowing &&
}
); }