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