"use client";
import { useState, type ReactNode } from "react";
import { Check, Copy } from "lucide-react";
interface CodeBlockProps {
children: ReactNode;
className?: string;
inline?: boolean;
}
export function CodeBlock({ children, className, inline }: CodeBlockProps) {
const [copied, setCopied] = useState(false);
if (inline) {
return (
{children}
);
}
const codeString = String(children).replace(/\n$/, "");
const handleCopy = async () => {
await navigator.clipboard.writeText(codeString);
setCopied(true);
window.setTimeout(() => setCopied(false), 2000);
};
return (
{codeString}