Introducing shieldcn — README badges, shadcn style.

Check it out

Diff Viewer

Code diff viewer with line numbers and add/remove coloring. Supports unified and split layouts.

difflucide-react
Loading...

Installation

$ shadcn add @jalco/diff-viewer

Usage

import { DiffViewer } from "@/components/diff-viewer"
<DiffViewer oldCode={before} newCode={after} />

Layouts

Unified (default)

counter.tsxcounter.tsx
+8-4
1-import { useState } from "react"
1+import { useState, useCallback } from "react"
22  
3-function Counter() {
4- const [count, setCount] = useState(0)
3+function Counter({ initial = 0 }) {
4+ const [count, setCount] = useState(initial)
55  
6+ const increment = useCallback(() => {
7+ setCount((prev) => prev + 1)
8+ }, [])
9+ 
610 return (
7- <button onClick={() => setCount(count + 1)}>
11+ <button onClick={increment}>
812 Count: {count}
913 </button>
1014 )

Split

before.tsxafter.tsx
+8-4
1import { useState } from "react"
2 
3function Counter() {
4 const [count, setCount] = useState(0)
5 
 
 
 
 
6 return (
7 <button onClick={() => setCount(count + 1)}>
8 Count: {count}
9 </button>
10 )
1import { useState, useCallback } from "react"
2 
3function Counter({ initial = 0 }) {
4 const [count, setCount] = useState(initial)
5 
6 const increment = useCallback(() => {
7 setCount((prev) => prev + 1)
8 }, [])
9 
10 return (
11 <button onClick={increment}>
12 Count: {count}
13 </button>
14 )

API Reference

DiffViewer

PropType

Notes

  • Two input modes. Pass oldCode + newCode to compute the diff, or pass a patch string if you already have one.
  • Icon library. Uses Lucide icons by default. Since this is copy-paste code, you can swap the imports if your project uses a different icon library.