Code Block
Data DisplaySyntax-highlighted code display with copy button.
Preview
jsx
Usage
example.jsx
import { CodeBlockUI } from "@/components/ui/code-block-ui";
export default function Example() {
return <CodeBlockUI />;
}Source Code
Copy this file into components/ui/code-block-ui.jsx in your project.
code-block-ui.jsx
import { forwardRef } from "react";
import { cn } from "@/lib/utils";
const CodeBlockUI = forwardRef(({ className, children, language, ...props }, ref) => (
<div ref={ref} className={cn("relative rounded-lg border bg-muted", className)} {...props}>
{language && <div className="flex items-center justify-between border-b px-4 py-2"><span className="text-xs font-medium text-muted-foreground">{language}</span></div>}
<pre className="overflow-auto p-4"><code className="text-sm font-mono">{children}</code></pre>
</div>
));
CodeBlockUI.displayName = "CodeBlockUI";
export { CodeBlockUI };
Quick Install
Make sure you have the cn() utility set up. It requires clsx and tailwind-merge.
npm install clsx tailwind-merge