Diff
A change shown as a diff and accepted or rejected piece by piece. Code diff marks the lines and the words inside them, Text diff the words in running prose, and both follow a change that is still being written.
Examples
import { db } from '@/lib/db'import { taxRateFor } from '@/lib/tax' (added)async function totalFor(invoiceId: string) {const invoice = await db.invoice.find(invoiceId)const lines = await db.line.list({ invoiceId })const subtotal = lines.reduce((sum, line) => sum + line.amount, 0)const tax = subtotal * 0.2 (removed)const tax = subtotal * taxRateFor(invoice.country) (added)return subtotal + tax}function formatTotal(total: number) { (removed)return '$' + total.toFixed(2) (removed)function formatTotal(total: number, currency = 'USD') { (added)return new Intl.NumberFormat('en-US', { style: 'currency', currency }).format(total) (added)}
Review an edit
Each change has Reject and Accept under it, and the page holds the decisions with resolved and onResolvedChange. Once they are made, resolveCode from @/lib/diff-math gives the file: pass it diffCode(before, after), resolved and 'rejected', which keeps before where a change is still open.
Reply to Maya Chen, suggested by Kino
Suggested reply
Text diff marks the words a suggestion changes in running prose: struck out where they leave, underlined where they arrive.
Reply to Sam Ortiz, suggested by Kino
While it arrives
Pass the suggestion as it is written with complete false: before past what has arrived stays as it is, and the change still being written waits to be decided. Press Rewrite reply to watch one arrive.
export const billing = {currency: 'USD',trialDays: 14, (removed)invoiceDueDays: 30, (removed)trialDays: 30, (added)invoiceDueDays: 14, (added)reminders: [7, 1], (added)}
Read only
Without onResolvedChange, the diff only shows what changed.
Installation
npx shadcn@latest add https://kinoui.com/r/diff.json- Files
lib/number-format.tslib/reduce-motion.tslib/refs.tslib/resize.tslib/roll.tsxlib/swap.tsxlib/run-progress.tscomponents/kino/animated-number.tsxcomponents/kino/spinner.tsxcomponents/kino/button.tsxlib/announce.tslib/syntax.tslib/scroll.tslib/fold.tslib/popup.tslib/glide.tsxlib/keys.tsxcomponents/kino/kbd.tsxcomponents/kino/tooltip.tsxlib/cut.tsxlib/code-lines.tsxlib/controllable.tslib/diff-math.tslib/diff-review.tslib/highlight.tslib/flow.tscomponents/kino/diff.tsx- Packages
@ui-sdk/core@ui-sdk/reactclass-variance-authorityshiki- Global CSS
- the feels, the density tokens, the shape tokens and the success and warning colours
New to Kino? Installation covers what your project needs first and the @kino namespace.
API reference
CodeDiff
Code with its changes in place: removed lines above added ones, each marked with a sign and a band, the words a line changed marked inside it, and Reject and Accept under each change. The header names the file, counts the lines added and removed, and holds Accept all and Reject all while more than one change is open.
TextDiff
Prose with its changes in place: the words that leave struck out and the words that arrive underlined, each on a tint, with Reject and Accept after each change and Accept all and Reject all at its foot.
Data attributes
Accessibility
- Each diff is a group named after its file or its
label, and every Accept and Reject is named after its change, such as “Accept change at line 12” or “Reject change 2 of 5”, so a screen reader and an agent tell them apart. Accept all and Reject all say how many changes they decide. - Each decision is announced, such as “Accepted change at line 12”, and focus moves on to the same button of the next open change, or to the diff once none follows.
- A screen reader hears each open change in prose as one deletion and one insertion, not a word at a time.
- Added and removed lines show a sign as well as a colour; changed words are underlined in forced colours, and struck-out and underlined words keep their lines there.
- An agent reads each diff’s changes by name in
snapshot()and accepts or rejects them withaccept,reject,acceptAllandrejectAll, throughonResolvedChangelike a press.
For agents
What an agent reads on this example with snapshot(), and the actions it can call with act().
The Agent bridge page sets up snapshot() and act() in your app.