"use client"; import { useEffect, useState, useRef } from "react"; import mermaid from "mermaid"; import { motion, AnimatePresence } from "framer-motion"; import { Maximize2, Minimize2 } from "lucide-react"; export default function Mermaid({ chart }: { chart: string }) { const [isExpanded, setIsExpanded] = useState(false); const [needsExpansion, setNeedsExpansion] = useState(false); const contentRef = useRef(null); useEffect(() => { mermaid.initialize({ startOnLoad: true, theme: "dark", securityLevel: "loose", fontFamily: "monospace", }); mermaid.contentLoaded(); // Check if the rendered diagram is taller than 400px if (contentRef.current) { const height = contentRef.current.scrollHeight; setNeedsExpansion(height > 400); } }, [chart]); return (
needsExpansion && setIsExpanded(!isExpanded)} animate={{ height: isExpanded || !needsExpansion ? "auto" : "400px" }} className={`relative bg-neutral-900/20 rounded-3xl border border-neutral-800/50 p-4 md:p-12 overflow-hidden transition-colors duration-500 ${needsExpansion && !isExpanded ? "cursor-pointer hover:border-neutral-700" : "cursor-default"}`} > {/* Legend */}
Traffic Flow
Service Node
{chart}
{/* The "Fade to Darkness" Overlay - only show if needs expansion */} {needsExpansion && !isExpanded && ( )} {/* Expand/Collapse Button - only show if needs expansion */} {needsExpansion && ( )}
); }