Code Block

A syntax-highlighted code block for AI-generated code, with copy support - streaming Writing status, line numbers, and highlights. Content stays dir="ltr".

Streaming

status="streaming" shows Writing and auto-scrolls as tokens arrive. Replay remounts the stream.

Loading…

Installation

CLI
npx @sonojs/ui@latest add agent-code-block
Also needs
npx @sonojs/ui@latest add agent-code
npm i lucide-react motion shiki

Usage

agent-code-block.tsx
import { AgentCodeBlock } from "@/components/sonojs/agent-code-block"

export function Example() {
  return (
    <AgentCodeBlock
      filename="app.ts"
      language="typescript"
      code={`export const answer = 42`}
    />
  )
}

Props

PropTypeDefaultDescription
codestring-Source text to highlight.
languageAgentCodeLanguage"typescript"Highlighter language.
filenameReactNode-Optional filename in the header.
status"streaming" · "complete""complete"Shows Writing vs Ready in the header.
showLineNumbersbooleantrueRenders a gutter with line numbers.
highlightLinesnumber[][]1-based line numbers to tint.
maxHeightnumber280Scroll viewport max height in pixels.
wrapbooleanfalseWrap long lines instead of horizontal scroll.
copyablebooleantrueShows the copy control in the header.
onCopy() => void-Optional override for the copy action.
classNamestring-Optional class names on the root.