Code Block
Syntax-highlighted code blocks with language labels and copy actions for AI markdown.
Usage
typescript
function greet(name: string) {
return `Hello, ${name}!`;
}
console.log(greet("Namespace UIKit"));"use client";
import { CodeBlock } from "@thenamespace/uikit";
const code = `function greet(name: string) {Use CodeBlock for fenced code output, tool snippets, and AI-generated examples.
Anatomy
import { CodeBlock } from "@thenamespace/uikit";
<CodeBlock>
<CodeBlock.Header>
<span>typescript</span>
<CodeBlock.CopyButton code={code} />
</CodeBlock.Header>
<CodeBlock.Code code={code} language="typescript" />
</CodeBlock>;CSS Classes
.code-block- Root code block surface.code-block__header- Header row.code-block__code- Code scroll region.code-block__copy-button- Copy/check icon button
API Reference
CodeBlock
Root container. Also supports native div props.
CodeBlock.Header
Header slot for language labels and actions. Also supports native div props.
CodeBlock.Code
| Prop | Type | Default | Description |
|---|---|---|---|
code | string | - | Code to render |
language | string | 'plaintext' | Shiki language id |
theme | string | 'github-light' | Shiki theme |
Also supports native div props.
CodeBlock.CopyButton
| Prop | Type | Default | Description |
|---|---|---|---|
code | string | - | Code copied to clipboard |
aria-label | string | 'Copy code' | Accessible label |
className | string | - | Additional class |