diff --git a/client/src/components/ExpandableText.tsx b/client/src/components/ExpandableText.tsx new file mode 100644 index 0000000..381b06f --- /dev/null +++ b/client/src/components/ExpandableText.tsx @@ -0,0 +1,25 @@ +import { useMemo, useState } from 'react'; + +interface Props { + text: string; + maxLines?: number; +} + +export default function ExpandableText({ text, maxLines = 1 }: Props) { + const [expanded, setExpanded] = useState(false); + const lines = useMemo(() => text.split('\n'), [text]); + const shouldClamp = lines.length > maxLines || text.length > 140; + + if (!shouldClamp) { + return

{text}

; + } + + return ( +
+
{text}
+ +
+ ); +}