Skip to content
Haze UI

Diff viewer

Unified and side-by-side code diff viewer with addition/deletion counts and monospace line numbers.

pnpm dlx shadcn@latest add @haze/diff-viewer
Open preview in a new tab
Livesmall script

When to use

  • Reviewing config updates, release diffs, or AI-proposed file changes
  • Inspecting before-and-after code patches inside drawers or PR views

When not to use

  • Read-only static snippets need no diff markers; use code-block
  • Visual before/after image comparison belongs in compare-slider

Installation

Add the Haze registry to components.json once, then install Diff viewer with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.

pnpm dlx shadcn@latest add @haze/diff-viewer
First time? Registry and theme setup

1. Add to components.json:

{
  "registries": {
    "@haze": "http://localhost:4329/r/{name}.json"
  }
}

2. Install the theme once: npx shadcn@latest add @haze/theme, then import it after Tailwind in your global CSS:@import "./haze.css";

API reference

PropTypeDefaultDescription
id*string–Unique DOM id for the diff viewer.
filenamestring"haze.config.ts"File path shown in the header bar.
linesDiffLine[]–Diff hunks with type (context, add, del), line numbers, and content.
view"unified" | "split""unified"Initial unified or side-by-side layout.

Accessibility

  • Explicit '+' and '-' markers accompany color fills so additions and deletions never depend on hue alone.
  • Decorative line numbers carry select-none so copying code text skips line gutters.

Notes for AI

Copy into Claude Code, Cursor, Codex or any coding agent. Agents can also read the Markdown version of this page.

  • Install and use

    Install the Haze UI component "Diff viewer" with `npx shadcn@latest add @haze/diff-viewer`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "http://localhost:4329/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import DiffViewer from "@/components/haze/ui/diff-viewer.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: http://localhost:4329/ui/diff-viewer.md

  • Customize with real content

    Adapt the Haze diff-viewer ui for our product. Replace the demo values of these props with our real content: id, filename, lines, view. Keep the layout, the heading level rules and these accessibility details: Explicit '+' and '-' markers accompany color fills so additions and deletions never depend on hue alone. Decorative line numbers carry select-none so copying code text skips line gutters. Do not add raw color classes; use the Haze tokens.

  • Choose the right block

    Before using diff-viewer, check it fits: use it when reviewing config updates, release diffs, or ai-proposed file changes; inspecting before-and-after code patches inside drawers or pr views. Avoid it when read-only static snippets need no diff markers; use code-block; visual before/after image comparison belongs in compare-slider. Alternatives: @haze/code-block, @haze/compare-slider, @haze/json-viewer.

Dependencies

  • npm: @lucide/astro
  • @haze/utils
  • @haze/theme (one-time setup)

Source · Original Haze UI work.

Catalog

↑↓ moveEnter openEsc close

Keyboard shortcuts

CtrlK
Command palette
/
Focus search
←↑→↓
Move between cards
jk
Next / previous card
ci
Copy code / install command (detail page)
[]
Previous / next entry
?
This help
Esc
Close dialog