Code Block
Display source code with syntax tokens, highlighted lines, diffs and useful file actions.
app/api/chat/route.ts
import { streamText } from "ai"
export async function POST(request: Request) {
const { messages } = await request.json()
const result = streamText({
model: "anthropic/claude-sonnet-4.5",
system: "You are a helpful assistant. Answer in one short paragraph.",
messages,
})
return result.toUIMessageStreamResponse()
}
Diff
greeting.ts
export function greeting(name: string) {
return 'Hello, ' + name
return `Hello, ${name}!`
}
Installation
Install the shared package once in your Exact app. This version is a beta.
bun add --exact @rightui/ui@0.4.0-beta.4
The Exact compiler requires Bun 1.4.2, regardless of which package manager installs the package.
Complete the font, app metadata and root provider setup (required for both installation methods).
Import
use CodeBlock, CodeBlockAdvanced, CodeToken, CodeLine from "@rightui/ui"
Usage
CodeBlock keeps its existing props and adds a line-wrap toggle with clearer diff styling. Use CodeBlockAdvanced for tokenized content, highlighted or added/removed lines, a custom starting line, maximum height and optional file export. CodeToken contains text and tone; CodeLine contains tokens and variant. Supported tones are plain, keyword, string, function, number, comment, type and property. Line variants are default, highlighted, added and removed. Supply tokenized lines from your data or build tooling; language labels the code and does not run a parser. The example uses Shiki-generated tokens with light and dark theme colors. Copy and Download always use the original code string. Keep that string and the tokenized lines in sync. An empty lines array falls back to the code string. The export uses the platform save flow.
Keyboard
Tab focuses Wrap lines, Download code when enabled, Copy code and the scrollable code region. Enter or Space activates the focused action. Wrap lines exposes its pressed state.
API Reference
Properties from the component source. State lives in your component; actions receive the updated value.
CodeBlock.id
string
CodeBlock.title
string
CodeBlock.language
string
CodeBlock.code
string
CodeBlock.numbers
bool
CodeBlock.diff
bool
CodeBlockAdvanced.id
string
CodeBlockAdvanced.title
string
CodeBlockAdvanced.language
string
CodeBlockAdvanced.code
string
CodeBlockAdvanced.lines
CodeLine[]
CodeBlockAdvanced.numbers
bool
CodeBlockAdvanced.startLine
number
CodeBlockAdvanced.showDownload
bool
CodeBlockAdvanced.maxHeight
number
CodeBlockAdvanced.compact
bool
CodeBlockAdvanced.variant
string