/* istanbul ignore file */ /** * CodeBlock Component * Syntax-highlighted code block with copy functionality * This file is excluded from coverage as it's a documentation component */ 'use client'; import { useState } from 'react'; import { Check, Copy } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { cn } from '@/lib/utils'; interface CodeBlockProps { children: React.ReactNode; className?: string; title?: string; } export function CodeBlock({ children, className, title }: CodeBlockProps) { const [copied, setCopied] = useState(false); const handleCopy = async () => { const code = extractTextFromChildren(children); await navigator.clipboard.writeText(code); setCopied(true); setTimeout(() => setCopied(false), 2000); }; return (
{title && (
{title}
)}
          {children}
        
); } function extractTextFromChildren(children: React.ReactNode): string { if (typeof children === 'string') { return children; } if (Array.isArray(children)) { return children.map(extractTextFromChildren).join(''); } if (children && typeof children === 'object' && 'props' in children) { return extractTextFromChildren( (children as { props: { children: React.ReactNode } }).props.children ); } return ''; }