All files / src/components/pages/chat/chat-long-text index.tsx

36.84% Statements 14/38
100% Branches 0/0
0% Functions 0/1
36.84% Lines 14/38

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 391x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x                                                  
'use client';
 
import { Icon } from '@/components/icon';
import { useModal } from '@/components/ui';
import { useLongText } from '@/hooks/use-chat/use-chat-longText';
 
import { LongTextModal } from '../chat-modal';
 
interface Props {
  text: string;
  className?: string;
}
 
export const ExpandableText = ({ text, className }: Props) => {
  const { open } = useModal();
  const { textRef, isLongText } = useLongText(text);

  return (
    <>
      <span
        ref={textRef}
        className={`line-clamp-20 block whitespace-pre-line text-gray-800 ${className}`}
      >
        {text}
      </span>

      {isLongText && (
        <button
          className='text-text-xs-medium mt-2 flex items-center'
          onClick={() => open(<LongTextModal text={text} />)}
        >
          <span className='text-text-xs-regular text-gray-500'>전체보기 </span>
          <Icon id='chevron-right-1' className='w-4 text-gray-600' />
        </button>
      )}
    </>
  );
};