Skip to content
Browse docs and components

File Diff

file-diff

A change to one file as an agent applies it: path, counts and a proportion bar in the header, highlighted added and removed lines below, following the newest line while it streams and folding away when done.

Responsive

Install

$npxshadcnadd@forme/file-diff

Adds the component, its registry dependencies, and the token stylesheet you import once.

Usage

import { FileDiff } from "@/components/forme/file-diff/file-diff";

<FileDiff
  file="billing/invoices.ts"
  language="ts"
  lines={[
    { type: "removed", oldLine: 13, content: "  return plan.price;" },
    { type: "added", newLine: 13, content: "  return prorate(plan, days);" },
  ]}
/>

When to use

Reach for it

  • A change an agent made, or is making, to one file.

Use something else

  • New files with no previous version; a CodeBlock says the same thing with less chrome.

Examples

3 more ways to put it to work. Install one by name and it lands beside the component, or copy it from the Code tab into your app.

Changeset to review

An agent's change across several files with the totals up top, the first file open, and keep or discard for the lot.

$npxshadcnadd@forme/file-diff-changeset
Responsive

New file

A file written from nothing: every line added as it streams in, then folded to its header once it is done.

$npxshadcnadd@forme/file-diff-new-file
Responsive

Deleted file

A file removed outright, every line on the old side, with a sentence above saying why.

$npxshadcnadd@forme/file-diff-deleted-file
Responsive

API reference

Read from the source, so it is the API of the file you install. A prop marked * is required.

FileDiff

A change to one file, the way an agent applies it: a header that summarises it, over the lines it touched.

PropTypeDefaultDescription
file*ReactNode—The path, shown in the header.
lines*readonly FileDiffLine[]—
language'html' | 'text' | 'ts' | 'tsx' | 'js' | 'jsx' | 'json' | 'css' | 'bash'"text"
streamingbooleanfalseWhile true the diff is still being written: it stays open and follows the newest line.
defaultOpenbooleantrue
collapseOnCompletebooleantrueFolds the diff away when streaming finishes, leaving the header as a summary.
maxHeightnumber280The tallest the lines get before they scroll, in pixels.
copyTextstring—Text for the copy button. No button without it.
classNamestring—

Accessibility

  • Added and removed lines carry a real + or − character, so the change survives without colour.

Motion

  • While streaming it opens, follows the newest line and fades new lines in.
  • When it finishes it folds itself away (collapseOnComplete), because a finished diff in a transcript is a receipt.

Responsive behaviour

  • The five-square size bar in the header is hidden below sm; the counts stay.