Componenteditors0.63 KB gzipZero dependencies

TextDiff

Word-level diff showing added/removed words with animation

Preview

Live Preview
Open ↗

Installation

Tokens guide →

Add to your project via CLI (zero dependencies, code you own):

npx bigbullui add text-diff

Or install the full npm package:

npm install bigbullui

Usage

tsx3 lines
import { TextDiff } from "@/components/ui/text-diff" <TextDiff before="Hello world" after="Hello universe" mode="inline" />

Source code

text-diff.tsx + 1 helper

Zero 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 />
PropTypeDescription
beforestringThe original text
afterstringThe modified text
modeTextDiffModeDiff layout mode