Skip to content
caliper ui pro docs

File diff

A line-by-line comparison of two versions of a file.

Pro
+7 −5
7 added, 5 removed in src/counter.tsx
import { useState } from "react";
Removed: function Counter({ start = 0 }: { start?: number }) {
Added: function Counter({ start = 0, step = 1 }: { start?: number; step?: number }) {
const [count, setCount] = useState(start);
Removed: const label = "Count: " + count;
Added: const label = `Count: ${count}`;
function increment() {
Removed: setCount(count + 1);
Added: setCount((current) => Math.min(current + step, maxCount));
}
return (
<div className="counter">
Removed: <p>{label}</p>
Removed: <button onClick={increment}>Add</button>
Added: <p aria-live="polite">{label}</p>
Added: <button onClick={increment} disabled={count >= maxCount}>
Added: Add
Added: </button>
</div>
);
}

When to use

  • Showing what an agent or a commit changed in a file.
  • Reviewing edits before they are applied.

When not to use

  • The comparison is of rich text or images.
  • Files are very large; page or collapse them first.

Installation

terminal
pnpm dlx shadcn@latest add @caliper/file-diff

Adds its 6 files to components/ui/, each with its own stylesheet, and installs their packages. Pro installs with your access token, set up once per project. See Pro access. The first part also adds Caliper UI’s tokens; import them once as in Installation.

API reference

FileDiff

9 props
PropTypeDefaultDescription
path *string—
before *string—
after *string—
languageCodeLanguage—
contextnumber3Unchanged lines kept around each change.
view"unified" | "split""unified"
actionsReactNode—Buttons for the header, such as Accept and Reject.
defaultOpenbooleantrue
classNamestring—

diffLines

0 props

No props of its own; it accepts the native props of its root element.

Keyboard

  • No custom key handling; Tab and the native activation keys do the work.

Accessibility

It exposes group and region semantics, with aria-label, aria-expanded, aria-controls, aria-hidden and aria-pressed kept in step with state.

Notes for AI

Give your coding assistant this page as Markdown instead of screenshots: the props, keyboard and examples in one file.

/docs/components/file-diff.md

The index of every part is at /llms.txt.

More in Agent output