/* istanbul ignore file */ /** * CodeSnippet Component * Displays syntax-highlighted code with copy-to-clipboard functionality * This file is excluded from coverage as it's a demo/showcase 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 CodeSnippetProps { code: string; language?: 'tsx' | 'typescript' | 'javascript' | 'css' | 'bash' | 'json'; title?: string; showLineNumbers?: boolean; highlightLines?: number[]; className?: string; } /** * CodeSnippet - Syntax-highlighted code block with copy button * * @example * Click me`} * showLineNumbers * /> */ export function CodeSnippet({ code, language = 'tsx', title, showLineNumbers = false, highlightLines = [], className, }: CodeSnippetProps) { const [copied, setCopied] = useState(false); const handleCopy = async () => { try { await navigator.clipboard.writeText(code); setCopied(true); setTimeout(() => setCopied(false), 2000); } catch (err) { console.error('Failed to copy code:', err); } }; const lines = code.split('\n'); return (
{/* Header */} {(title || language) && (
{title && {title}} {language && ({language})}
)} {/* Code Block */}
{/* Copy button (when no header) */} {!title && !language && ( )}
          
            {showLineNumbers ? (
              
{/* Line numbers */}
{lines.map((_, idx) => (
{idx + 1}
))}
{/* Code lines */}
{lines.map((line, idx) => (
{line || ' '}
))}
) : ( code )}
); } /** * CodeGroup - Group multiple related code snippets * * @example * * * * */ export function CodeGroup({ children, className, }: { children: React.ReactNode; className?: string; }) { return
{children}
; }