Code Block

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
Default—
language?
"text" | "bash" | "diff" | "json" | "tsx" | "typescript"
Defaulttypescript
filename?
ReactNode
Default—
status?
"complete" | "streaming"
Defaultcomplete
showLineNumbers?
boolean
Defaulttrue
highlightLines?
number[]
Default[]
maxHeight?
number
Default280
wrap?
boolean
Defaultfalse
copyable?
boolean
Defaulttrue
onCopy?
(() => void | Promise<void>)
Default—
className?
string
Default—

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.

Also on React Native. Streaming code with fixed line numbers and wrap.

Updated