Diff View

React code diff viewer that tints added lines green and removed lines red with plus and minus gutters, context lines and an optional filename header.

src/registry/ui/diff-view.tsx/r/diff-view.json
button.tsx
function Button() {
return <button />
return <button data-slot="button" />
}

Sample

Installation#

bash
npx shadcn@latest add @minidev/diff-view

MiniDev UI is in the shadcn registry directory, so the short form works with no setup. Older CLI versions can use the full URL: npx shadcn@latest add https://ui.minidev.pro/r/diff-view.json

Usage#

tsx
import { DiffView } from "@/components/ui/diff-view"

export function Example() {
  return (
    <DiffView filename="button.tsx" lines={[{ type: "ctx", text: "function Button() {" }, { type: "del", text: "  return <button />" }, { type: "add", text: "  return <button data-slot=\"button\" />" }, { type: "ctx", text: "}" }]} />
  )
}

API reference#

DiffView props
PropTypeDefault
lines*Line[]-
classNamestring-
filenamestring-

* required

All Developer tool UI components for React