A syntax-highlighted code block with copy and download functionality, perfect for displaying code snippets in documentation and tutorials.
Search for a command to run...
A syntax-highlighted code block with copy and download functionality, perfect for displaying code snippets in documentation and tutorials.
function greet(name) {
console.log(`Hello, ${name}!`);
return `Welcome to GAIA UI`;
}
greet("Developer");Makes AI-generated code readable and usable. Auto-detects language and adds copy-paste utility.
npx shadcn@latest add https://ui.heygaia.io/r/code-block.jsonimport { CodeBlock } from "@/components/ui/code-block";
export default function Example() {
const code = `function hello() {
console.log("Hello, World!");
}`;
return (
<CodeBlock language="javascript" filename="hello.js">
{code}
</CodeBlock>
);
}def fibonacci(n):
if n <= 1:
return n
return fibonacci(n-1) + fibonacci(n-2)
print(fibonacci(10))interface User {
id: string;
name: string;
email: string;
}
const createUser = (data: User): User => {
return { ...data };
};#!/bin/bash
# Deploy script
echo "Building application..."
npm run build
echo "Deploying to production..."
npm run deploy123456789101112131415import React from "react";
import { cn } from "@/lib/utils";
export function Component({ className }) {
const [count, setCount] = React.useState(0);
return (
<div className={cn("container", className)}>
<h1>Count: {count}</h1>
<button onClick={() => setCount(count + 1)}>
Increment
</button>
</div>
);
}| Prop | Type | Default | Description |
|---|---|---|---|
| children | string | - | The code content to display |
| language | string | "plaintext" | Programming language for syntax highlighting |
| filename | string | - | Optional filename to display in header |
| showLineNumbers | boolean | false | Show line numbers on the left |
| className | string | - | Additional CSS classes |
The component automatically detects file extensions for the following languages:
This component works great with syntax highlighting libraries like react-syntax-highlighter or prism-react-renderer. Simply wrap the code content with your preferred highlighter:
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';
import { oneDark } from 'react-syntax-highlighter/dist/esm/styles/prism';
<CodeBlock language="javascript">
<SyntaxHighlighter language="javascript" style={oneDark}>
{code}
</SyntaxHighlighter>
</CodeBlock>Override the default styles using Tailwind classes:
<CodeBlock
className="border-blue-500 bg-blue-950"
language="python"
>
{code}
</CodeBlock>