Componenteditors0.63 KB gzipZero dependencies
TextDiff
Word-level diff showing added/removed words with animation
Preview
Live Preview
Installation
Tokens guide →Add to your project via CLI (zero dependencies, code you own):
npx bigbullui add text-diffOr install the full npm package:
npm install bigbulluiUsage
tsx3 lines
import { TextDiff } from "@/components/ui/text-diff" <TextDiff before="Hello world" after="Hello universe" mode="inline" />Source code
text-diff.tsx + 1 helperZero third-party dependencies (2 local files shown in tabs below).
tsxtext-diff.tsx121 lines
import * as React from "react";import { cn } from "./lib/utils"; export type TextDiffMode = "inline" | "side"; export type TextDiffProps = { before: string; after: string; mode?: TextDiffMode;}; const TextDiff = ({ before = "", after = "", mode = "inline" }: TextDiffProps) => { const beforeWords = before.split(/\s+/); const afterWords = after.split(/\s+/); // Simple LCS to find added/removed/kept words const lcsMatrix: (string | null)[][] = []; for (let i = 0; i <= beforeWords.length; i++) {Props
Interactive Prop Playground
Tweak parsed AST props below to generate ready-to-paste JSX.
tsx3 lines
import { TextDiff } from "@/components/ui/text-diff"; <TextDiff />| Prop | Type | Description |
|---|---|---|
| before | string | The original text |
| after | string | The modified text |
| mode | TextDiffMode | Diff layout mode |