|
|
|
@ -1,5 +1,5 @@
|
|
|
|
|
import clsx from 'clsx';
|
|
|
|
|
import { useEffect, useState } from 'react';
|
|
|
|
|
import { useLayoutEffect, useRef, useState } from 'react';
|
|
|
|
|
|
|
|
|
|
type ResumeExpandableTextProps = Readonly<{
|
|
|
|
|
text: string;
|
|
|
|
@ -8,17 +8,17 @@ type ResumeExpandableTextProps = Readonly<{
|
|
|
|
|
export default function ResumeExpandableText({
|
|
|
|
|
text,
|
|
|
|
|
}: ResumeExpandableTextProps) {
|
|
|
|
|
const ref = useRef<HTMLSpanElement>(null);
|
|
|
|
|
const [isExpanded, setIsExpanded] = useState(false);
|
|
|
|
|
const [descriptionOverflow, setDescriptionOverflow] = useState(false);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
const lines = text.split(/\r\n|\r|\n/);
|
|
|
|
|
if (lines.length > 3) {
|
|
|
|
|
useLayoutEffect(() => {
|
|
|
|
|
if (ref.current && ref.current.clientHeight < ref.current.scrollHeight) {
|
|
|
|
|
setDescriptionOverflow(true);
|
|
|
|
|
} else {
|
|
|
|
|
setDescriptionOverflow(false);
|
|
|
|
|
}
|
|
|
|
|
}, [text]);
|
|
|
|
|
}, [ref]);
|
|
|
|
|
|
|
|
|
|
const onSeeActionClicked = () => {
|
|
|
|
|
setIsExpanded((prevExpanded) => !prevExpanded);
|
|
|
|
@ -27,6 +27,7 @@ export default function ResumeExpandableText({
|
|
|
|
|
return (
|
|
|
|
|
<div>
|
|
|
|
|
<span
|
|
|
|
|
ref={ref}
|
|
|
|
|
className={clsx(
|
|
|
|
|
'line-clamp-3 whitespace-pre-wrap text-sm',
|
|
|
|
|
isExpanded ? 'line-clamp-none' : '',
|
|
|
|
|