Skip to content
caliper ui docs

Pro

File diff

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

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

Add a step to the counter

The assistant proposed 1 change for Dev Patel · branch feat/counter-step

+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>
);
}
Installs components/ui/file-diff.tsxDepends on @radix-ui/react-slot, lucide-reactMotion none in component source

When to use

Use it for

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

Skip it when

  • 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.

Usage

Import it from your copy of the source. The example behind the preview comes with the source. It is built from FileDiff and diffLines.

example.tsx
import { FileDiff, diffLines } from "@/components/ui/file-diff"

The worked example comes with Pro

The 89-line example behind the preview opens here, ready to copy.

  • 626 Pro parts, blocks and page templates, all with source
  • $149 once, with lifetime updates. No renewal
  • A full refund within 14 days if it is not for you
Checking your licence…

API reference

FileDiff

component
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

component

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

Accessibility

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

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

Motion

It declares no animation in its component source. Any transition comes from its stylesheet, which uses the duration tokens that collapse to instant under prefers-reduced-motion.

All Agent output examples