'use client'; import { CopyButton, SimpleTooltip } from "@/components/ui"; import { useThemeWatcher } from '@/lib/theme'; import { cn } from '@/lib/utils'; import { CodeIcon, TerminalWindowIcon } from "@phosphor-icons/react"; import type { ReactNode } from 'react'; import { PrismLight as SyntaxHighlighter } from 'react-syntax-highlighter'; import bash from 'react-syntax-highlighter/dist/esm/languages/prism/bash'; import python from 'react-syntax-highlighter/dist/esm/languages/prism/python'; import sql from 'react-syntax-highlighter/dist/esm/languages/prism/sql'; import tsx from 'react-syntax-highlighter/dist/esm/languages/prism/tsx'; import typescript from 'react-syntax-highlighter/dist/esm/languages/prism/typescript'; import { dark, prism } from 'react-syntax-highlighter/dist/esm/styles/prism'; Object.entries({ tsx, bash, typescript, python, sql }).forEach(([key, value]) => { SyntaxHighlighter.registerLanguage(key, value); }); type CodeBlockProps = { language: string, content: string, customRender?: ReactNode, title: string, icon: 'terminal' | 'code', maxHeight?: number, compact?: boolean, tooltip?: ReactNode, fullWidth?: boolean, neutralBackground?: boolean, noSeparator?: boolean, }; export function CodeBlock(props: CodeBlockProps) { const { theme, mounted } = useThemeWatcher(); let icon = null; switch (props.icon) { case 'terminal': { icon = ; break; } case 'code': { icon = ; break; } } return (
{icon} {props.title}
{props.tooltip && ( )}
{props.customRender ?? {props.content} }
); }