"use client"; import { useState, useRef, useEffect } from "react"; interface ExpandableCodeProps { children: React.ReactNode; maxHeight?: number; } export function ExpandableCode({ children, maxHeight = 300, }: ExpandableCodeProps) { const [isExpanded, setIsExpanded] = useState(false); const [needsExpansion, setNeedsExpansion] = useState(false); const contentRef = useRef(null); useEffect(() => { if (contentRef.current) { setNeedsExpansion(contentRef.current.scrollHeight > maxHeight); } }, [maxHeight]); return (
{children}
{needsExpansion && !isExpanded && ( <>
)}
); }