Code Block

A syntax-highlighted code surface with stable streaming updates, line numbers, focused lines, smooth following, and copy feedback.

Preview

summarize.tstypescriptWriting
1import { generateText } from "ai";

Install

Add it with the shadcn CLI, or copy the source manually.

$ bunx --bun shadcn add @beui/code-block

API Reference

code
string
language?
"text" | "bash" | "diff" | "json" | "tsx" | "typescript"
typescript
filename?
ReactNode
status?
"complete" | "streaming"
complete
showLineNumbers?
boolean
true
highlightLines?
number[]
[]
maxHeight?
number
280
wrap?
boolean
false
copyable?
boolean
true
onCopy?
(() => void | Promise<void>)
className?
string

Composition

Nest generated source inside the response that owns its streaming lifecycle.

StreamingResponse
└── CodeBlock

Note: File Diff explains additions and removals around highlighted code. Tool Result wraps generated code in an execution outcome. Streaming Response embeds highlighted code inside a rich answer.

How it works

Generated code changes faster than a conventional static snippet. The surface must remain readable while lines arrive, preserve syntax structure, and make copying the final result predictable.

Updated