import React, { useState } from 'react'; import { classNames } from '~/utils/classNames'; import { motion } from 'framer-motion'; import { FileIcon } from './FileIcon'; import { Tooltip } from './Tooltip'; interface CodeBlockProps { code: string; language?: string; filename?: string; showLineNumbers?: boolean; highlightLines?: number[]; maxHeight?: string; className?: string; onCopy?: () => void; } export function CodeBlock({ code, language, filename, showLineNumbers = true, highlightLines = [], maxHeight = '400px', className, onCopy, }: CodeBlockProps) { const [copied, setCopied] = useState(false); const handleCopy = () => { navigator.clipboard.writeText(code); setCopied(true); setTimeout(() => setCopied(false), 2000); onCopy?.(); }; const lines = code.split('\n'); return (
{/* Header */}
{filename && ( <> {filename} )} {language && !filename && ( {language} )}
{copied ? : }
{/* Code content */}
{lines.map((line, index) => ( {showLineNumbers && ( )} ))}
{index + 1} {line || ' '}
); }