"use client"; import { useEffect, useRef, useState } from "react"; import { cn } from "@/lib/utils"; interface ExpandableTextProps { text: string; /** Tailwind line-clamp class applied when collapsed (default: "line-clamp-3") */ clampClass?: string; className?: string; textClassName?: string; } export function ExpandableText({ text, clampClass = "line-clamp-3", className, textClassName, }: ExpandableTextProps) { const [expanded, setExpanded] = useState(false); const [clamped, setClamped] = useState(false); const ref = useRef(null); useEffect(() => { const el = ref.current; if (!el) return; const check = () => setClamped(el.scrollHeight > el.clientHeight + 1); check(); const observer = new ResizeObserver(check); observer.observe(el); return () => observer.disconnect(); }, []); return (

{text}

{(clamped || expanded) && ( )}
); }