UI

Text diff

Review prose edits inline or inside a standalone card, with suggestion popovers, keyboard shortcuts, and undo.

import { TextDiff } from '@uthereal/ui/text-diff'

Text diff playground

Suggested changes

When a new request arrives, the agent will the project notes to . The summary stays visible while the evidence is checked, so you can follow the work without reading every internal step. Before the result is shared, the claims and their supporting sources. Any decisions you make here stay attached to these exact words.
3 changes to review
Loading interactive preview…

Overview

TextDiff presents suggested prose edits for word-level human review. Each pending change displays removed text (<del>) beside proposed text (<ins>) and opens an anchored suggestion popover to accept or reject the edit without mutating host data.

Use TextDiff for prose revisions, copyediting, and AI writing suggestions. Use Code (mode="diff") for line-based source code patches and Text editor for freeform authoring.

Mode / LayoutPrimary propsBehavior
layout="card"label, showToolbarStandalone bordered review surface with a caption, inline prose changes, and footer navigation, bulk, and Undo.
layout="inline"showToolbar={false}Unframed inline prose composed directly inside an existing paragraph or document surface.
Snapshot comparisonoriginal, suggestedDerives word-level change segments with bounded diffWords (up to 20,000 characters each).
Explicit segmentssegments, defaultDecisionsRenders host-prepared text and stable-ID change segments (with optional note) and exact-text initial state.

Usage

'use client'
import { TextDiff } from '@uthereal/ui/text-diff'

export function DraftReview() {
  return (
    <TextDiff
      label="Release note draft"
      segments={[
        { kind: 'text', text: 'We ' },
        {
          kind: 'change',
          id: 'verb',
          before: 'utilize',
          after: 'use',
          note: 'Prefer a shorter, direct verb.',
        },
        { kind: 'text', text: ' the updated summary.' },
      ]}
      onReview={({ text, complete }) => {
        if (complete) console.log('Reviewed text:', text)
      }}
    />
  )
}

Supply original and suggested together to compute word-level changes automatically, or pass explicit segments. Raw snapshots take precedence when provided; clear both before switching an existing configuration back to segments. Export diffWords(original, suggested) for server-side preparation and reviewText(segments, decisions) to compute the current prose string.

Examples

Use <SchemaPlayground /> above to test the default card layout, toolbar controls, and popover actions. The examples below cover inline composition and snapshot diffing.

Inline document review

Set layout="inline" and showToolbar={false} to embed reviewable changes inside surrounding copy. Focus or click any pending change to open its anchored popover or decide from the keyboard.

When a new request arrives, the agent will the project notes to . The summary stays visible while the evidence is checked, so you can follow the work without reading every internal step. Before the result is shared, the claims and their supporting sources. Any decisions you make here stay attached to these exact words.

Compare text snapshots

Pass original and suggested when the host holds two complete strings instead of precomputed change IDs.

Suggested changes

The summary is clear and ready.
2 changes to review

Decisions and undo

ConceptContract
defaultDecisionsSerializable array of unique-ID { id, decision, before, after } entries; converts via reviewDecisionsFromEntries.
decisionsReact-only controlled record keyed by change ID (Record<id, { decision, before, after }>).
Exact-text bindingreconcileReview drops any stored or undone decision whose before or after no longer matches the current segment.
Undo historyStores up to 200 snapshots in memory; Undo restores the previous decision map and re-validates against segments.
Host actionsacceptAction, rejectAction, and completeAction fire only after explicit user interaction, never on mount or edit.

API reference

Serializable arguments and defaults come directly from textDiffConfigSchema.

ArgumentType / defaultDescription
originalstring—Original prose snapshot, up to 20,000 characters. Supply with suggested to derive word-level change segments automatically.
suggestedstring—Proposed prose snapshot, up to 20,000 characters. Supply with original to derive word-level change segments automatically.
labelstringDefault: "Suggested changes"Accessible name of the prose review, shown as a caption above the text in card layout.
segmentsReviewSegment[]Default: []Explicit unchanged text and stable before/after change segments (with optional note). Ignored when original and suggested are supplied.
defaultDecisionsReviewDecisionEntry[]Default: []Initial accepted or rejected choices as unique-ID entries bound to exact before and after text; later edits do not overwrite existing user decisions.
acceptActionstring—Host-registered action name sent with the change ID after accepting a change.
rejectActionstring—Host-registered action name sent with the change ID after rejecting a change.
completeActionstring—Host-registered action name sent with "complete" once the final pending change is resolved.
layoutcard | inlineDefault: "card"card renders a bordered review surface with a label; inline renders unframed prose for document composition.
showToolbarbooleanDefault: trueShow the footer toolbar with pending count, previous/next change navigation, bulk Accept all / Reject all, and Undo.
recipestudio | softDefault: "studio"Visual treatment. Both recipes use the same interaction behavior.
themeTextDiffTheme—Color mode, accent, and semantic design token overrides forwarded to the review surface, popover, and controls.
motionnone | subtle | expressiveDefault: "subtle"Animation preset for change settling and suggestion popovers; system reduced motion takes precedence.
motionOptionsTextDiffMotionOptions—Disclosure transition override for review state and popover motion (durations in milliseconds).
dirltr | rtl—Reading direction; omit to inherit the page direction.

React integration

PropPurpose
decisions, onDecisionsChangeControlled decision record and change callback; entries carry decision, before, and after.
reviewRefImperative highlight(index), accept(index), reject(index), acceptAll(), rejectAll(), undo(), and reset() handle.
onReview(result)Reports { decisions, text, complete } after every user decision, bulk action, undo, or reset.
onAction(action, itemId)Receives acceptAction / rejectAction with the change ID, and completeAction with "complete".
presetApplication defaults overridden by explicit instance props.
tokens--ui-* CSS custom properties applied to the root element and portalled suggestion popovers.
ref, className, style, restForwarded to the root <div> element (style takes precedence over theme and motion variables).

Keyboard & accessibility

KeyInteraction
TabMoves focus across pending changes and toolbar controls.
Space / clickOpens the anchored review popover for the focused change.
Y, EnterAccepts the focused or active change and advances focus to the next pending change.
N, BackspaceRejects the focused or active change and advances focus to the next pending change.
EscapeCloses the active review popover without recording a decision.

The root element sets role="region" in card layout (role="group" in inline layout) with aria-label={label}. All prose renders as escaped text. A pre-mounted role="status" region announces pending counts and completion; resolving the final change moves focus to Undo when the toolbar is visible. Keyboard shortcuts ignore events originating inside editable inputs or IME composition. Navigation chevrons automatically mirror in right-to-left (dir="rtl") layouts. Under forced-colors: active, additions underline, focus rings use Highlight, and shortcut hints switch to Canvas / CanvasText.

Motion and theming

Resolved changes collapse discarded words smoothly while kept words settle into normal prose; the toolbar status glyph transitions through the shared activity glyph swap, and suggestion popovers open on the anchored surface transition. Under prefers-reduced-motion: reduce, width collapse and travel are removed in favor of a 120ms opacity crossfade. Under motion="none", transitions and scroll jumps are immediate (0ms).

Token group / keyRole
core (surface, border, text)Card frame, prose ink, muted deletion text, focus outline.
control, borderStrongToolbar button sizing, hover underline, and popover controls.
success, dangerSoft insertion and deletion tint bands (color-mix).
radius, popupRadius, radiusSmCard corner radius and portalled popover radius.
shadowResting, shadowRaisedPopover elevation in light and dark modes.

UtherealProvider supplies application-wide defaults. See Motion.

Composition

In agent compositions, TextDiff is a leaf component. User choices persist in host state at /components/instance-<id>/decisions and reconcile by stable change ID and exact before/after text. Register acceptAction, rejectAction, and completeAction on the host before referencing them.

{
  "type": "TextDiff",
  "props": {
    "label": "Summary review",
    "original": "The agent will utilize the notes to create a summary.",
    "suggested": "The agent will use the notes to write a summary."
  },
  "children": []
}

On this page