What it does
The Code Diff component takes two strings of code and computes a line-by-line diff using the `diff` library.
It renders additions in green, deletions in red, and leaves unchanged lines unstyled. A sticky header shows the total additions and deletions at a glance.
Composition and API
The component accepts `oldCode` and `newCode` as required string props, and optional props for `viewType` (unified or split), `showLineNumbers`, `showGutterMarkers`, `oldTitle`, `newTitle`, `appearance`, and `size`.
Use the static entry from `@zentauri-ui/zentauri-components/ui/code-diff`. The component does not require framer-motion.
Accessibility
Diffs are rendered as HTML tables so screen readers navigate line by line with column headers. Added/removed lines use color and gutter markers (+/-) together — never rely on color alone.
The header announces the count of additions and deletions for quick scanning.
Next.js integration notes
Import from `@zentauri-ui/zentauri-components/ui/code-diff`. The component is a client component but can be imported in server components as long as the actual rendering happens on the client.
Set NEXT_PUBLIC_SITE_URL so canonical and Open Graph URLs resolve on deploy.
FAQ
Does the Code Diff component animate?
The base component is static (no framer-motion dependency). For animated transitions, wrap the component or use CSS transitions on the container.
Can I customize colors?
Yes. Every color is driven by CSS variables (--zui-code-diff-added-bg, --zui-code-diff-removed-bg, etc.) with sensible fallbacks. Override them in your Tailwind theme or global CSS.
What diff algorithm is used?
The component uses the battle-tested `diff` npm package under the hood. It provides word-level or line-level diffs — currently line-level with `diffLines`.
Does it work with large files?
Diff computation runs synchronously on render. For very large files, consider limiting the input size or computing the diff server-side.