"use client"; import React, { useEffect, useState } from "react"; import { Copy, Terminal, Check } from "lucide-react"; import { cn } from "../../lib/utils"; import { motion } from "framer-motion"; import { Prism as SyntaxHighlighter } from "react-syntax-highlighter"; import { oneDark } from "react-syntax-highlighter/dist/cjs/styles/prism"; type TerminalCardProps = { command: string; language?: string; className?: string; }; const TerminalCard: React.FC = ({ command, language = "tsx", className }) => { const [copied, setCopied] = useState(false); const [displayedText, setDisplayedText] = useState(""); const [index, setIndex] = useState(0); const [isComplete, setIsComplete] = useState(false); // Typing animation logic useEffect(() => { let timeout: NodeJS.Timeout; if (index < command.length) { timeout = setTimeout(() => { setDisplayedText((prev) => prev + command.charAt(index)); setIndex((prev) => prev + 1); }, 40); // typing speed } else { setIsComplete(true); timeout = setTimeout(() => { setDisplayedText(""); setIndex(0); setIsComplete(false); }, 2000); // restart delay } return () => clearTimeout(timeout); }, [index, command]); // Copy handler const handleCopy = () => { navigator.clipboard.writeText(command); setCopied(true); setTimeout(() => setCopied(false), 1500); }; return (
{/* Header */}
Terminal
{/* Content with Syntax Highlighting */}
{isComplete ? ( {command} ) : ( {displayedText} )}
); }; export default TerminalCard;