File Diff

A collapsible code diff that shows added and removed lines — streaming apply state, syntax tokens via agent-code, and optional copy.

Streaming

Lines stream in while status="streaming", then settle to complete. Replay remounts the cycle.

Loading…

Installation

CLI
npx @sonojs/ui@latest add file-diff
Also needsnpx @sonojs/ui@latest add agent-code agent-disclosure && npm i lucide-react motion shiki

Usage

file-diff.tsx
import { FileDiff } from "@/components/sonojs/file-diff"

export function Example() {
  return (
    <FileDiff
      file="src/app.ts"
      status="complete"
      lines={[
        { id: "1", type: "removed", oldLine: 1, content: "const x = 1" },
        { id: "2", type: "added", newLine: 1, content: "const x = 2" },
      ]}
      copyText="- const x = 1\n+ const x = 2"
    />
  )
}

Props

PropTypeDefaultDescription
fileReactNode—Filename shown in the disclosure trigger.
linesFileDiffLine[]—Diff rows with type, line numbers, and content.
status"streaming" · "complete""streaming"Spinner while applying; check when complete.
open / defaultOpenbooleantrueControlled or uncontrolled open state.
collapseOnCompletebooleantrueAuto-collapses when streaming finishes.
languageAgentCodeLanguage"typescript"Highlighter language for line tokens.
copyText / onCopystring / () => void—Enables the copy control in the panel footer.
maxHeightnumber220Scroll viewport max height in pixels.
classNamestring—Optional class names on the root.