Installation
Usage
"use client"
import { DiffReview } from "@/components/diff-review"
const before = `export function price(n: number) {
return n * 1.2
}`
const after = `export function price(n: number, yearly = false) {
return (yearly ? n * 10 : n) * 1.2
}`
export function ReviewChanges() {
return (
<DiffReview
title="Add yearly pricing"
author="Atlas"
files={[{ path: "src/lib/price.ts", old: before, new: after, note: "Yearly plans cost ten months." }]}
onRevise={(request) => console.log("send to your model", request)}
onApply={(result) => console.log(result.files[0].content)}
/>
)
}Props
| Prop | Type | Default | Description |
|---|---|---|---|
| files | DiffFile[] | — | Each has path, old (leave out for a new file), new ("" for a deleted one), an optional language and a note: the agent's explanation shown above its changes. |
| title / author | string | — / "Agent" | A heading for the change set and who made it. |
| decisions / defaultDecisions | Record<string, "accept" | "reject"> | {} | Decisions by change id, kept by you or by the component; onDecisionsChange tells you about each one. Ids come from a change's content, so a revision keeps the decisions on changes it didn't touch. |
| comments / defaultComments | DiffComment[] | [] | Comments on lines (path, side, line, author, body, agent); onCommentsChange gets the new list. me is the name on new comments. |
| onRevise | (request) => void | — | Shows "Ask … to revise" in the comment box, with the path, line and text to send to your model. Mark files as busy while it works. |
| onApply | (result) => void | — | Called with each file's content holding only the accepted changes, plus what was accepted and rejected. |
| view / defaultView | "unified" | "split" | "unified" | One column or side by side; onViewChange tells you when it changes. Narrow screens stay unified. |
| context | number | 3 | Unchanged lines kept around each change; the rest fold away. |
| label | string | "Review changes" | Accessible name. |
Accessibility
- Each change is a labelled group with Accept and Reject as toggle buttons; J and K move between changes, A accepts, R rejects and C opens a comment on the change.
- Removed and added lines say "removed" and "added" to screen readers, not only in colour.
- Every decision, comment and request is announced through a polite live region, and the progress bar reports accepted, rejected and left.
- The comment box is labelled with its line; Escape closes it and Ctrl or Cmd Enter sends it.
- Under prefers-reduced-motion threads and the applied card appear without moving.
Changelog
- v1.0.1Latest
A rejected change now strikes through its added lines, as intended (the old selector never matched and broke Tailwind's dev CSS).
- v1.0.0
First release.