Editable document lines: totals roll down the column, a total traces the lines it counts, rows paste from a spreadsheet, a removed line is thrown into Undo.
Change the valueChange the value
Northbeam Joinery · Delivery 14 Nov · EUR
| Item | Qty | Unit price | Disc. | Total | Remove |
|---|---|---|---|---|---|
% | €516.00 | ||||
% | €51.60 | ||||
% | €0.00 | ||||
% | €49.68 |
1 line needs a price
| 3 of 4 lines in Subtotal, 1 left out until valid | €617.28 |
|---|---|
| 3 of 4 lines in Tax 22%, 1 left out until valid | €135.80 |
| 3 of 4 lines in Total, 1 left out until valid | €753.08 |
line-items, lively
Use it for the editable lines of a document: purchase and sales orders, invoices and quotes, timesheets, bills of materials. Each line is an item, figures (quantity, unit price, discount) and a computed total; the foot carries the summary (subtotal, tax, total). Change a quantity and the line total rolls, then the summary values roll one stagger step apart, top to bottom, so the eye follows the money down the column. A total explains itself: point at, focus or press a summary label (dotted underline) and the column it adds lights line by line, while lines it leaves out (still invalid) are hatched and the line under the grid reads "3 of 4 lines in Total, 1 left out". An invalid line says what it needs, and "Fix line 3" takes focus to the cell. "+ Add line" morphs into the new row, Ctrl+D (⌘D) copies a line below itself, and rows copied from a spreadsheet paste straight into the cells; the × on a line throws it as a ball into the Undo pill, and Undo throws it back. Below 576 px of width each line becomes a tile. For a read-only list of records use a data table; for a single figure use a number input.
pnpm dlx shadcn@latest add @motionkit-pro/line-itemsnpx shadcn@latest add @motionkit-pro/line-itemsyarn dlx shadcn@latest add @motionkit-pro/line-itemsbunx --bun shadcn@latest add @motionkit-pro/line-itemsRequires a Pro license and the @motionkit-pro registry with your token. See Installation.
import { useState } from "react"
import { type LineItem, LineItems } from "@/components/ui/line-items"
const lines: LineItem[] = [
{ id: "1", item: "Oak panel 120 × 60", qty: 8, unitPrice: 64.5, discount: 0 },
{ id: "2", item: "Hinge set", qty: 4, unitPrice: 12.9, discount: 0 },
]
export function OrderLines() {
const [value, setValue] = useState(lines)
return <LineItems value={value} onValueChange={setValue} taxRate={0.22} currency="EUR" />
}preset picks the columns and the summary: invoice (item, qty, unit price, discount %, total;
subtotal, tax and total), timesheet (date, project, hours, rate, amount; hours and amount) and
bom (component, qty, unit, stock on hand tinted when short, unit cost, cost; parts and cost).
Pass columns (text, number, currency, percent, computed with compute(line)) and
summary (compute(lines)) to define your own. Totals come from the value only (one source of
truth) and leave out lines a column's validate rejects. onAdd returns the new line,
onRemove(id) fires on removal, undoWindow (ms, 0 to remove at once) sets how long Undo stays,
max caps the lines. showErrors flags every invalid line at once (a saved draft reopened)
instead of waiting for a cell to lose focus. A summary row traces the column named by its
source (default: the computed column for money rows; the timesheet hours trace hours, the
bom parts trace component). renderCell(line, column, api) drops your own control into a cell (a
combobox for the item). actionsRef exposes add, remove, undo and duplicate with the whole motion and no
focus change. temperament only changes how much it moves. totalOf(lines, columns) sums the
computed column.
<LineItems
columns={columns}
renderCell={(line, column, api) =>
column.id === "item" ? (
<ProductCombobox value={api.value} onValueChange={api.setValue} aria-label={api.label} />
) : undefined
}
/>Prop
Type
Also accepts all props of Omit<ComponentProps<"div">, "defaultValue" | "onChange">.
A week of entries: hours step by a quarter (step: 0.25), the amount is hours times rate, and the
summary adds hours and amount.
Change the valueChange the value
| Date | Project | Hours | Rate | Amount | Remove |
|---|---|---|---|---|---|
h | €552.50 | ||||
h | €616.25 | ||||
h | €475.00 | ||||
h | €760.00 | ||||
h | €315.00 |
| 5 of 5 lines in Hours | 31.25 |
|---|---|
| 5 of 5 lines in Amount | €2,718.75 |
line-items, lively
A chair's parts with stock on hand: a part with less stock than the quantity is tinted warning
with a dot, and the summary counts parts and cost.
Change the valueChange the value
| Component | Qty | Unit | In stock | Unit cost | Cost | Remove |
|---|---|---|---|---|---|---|
36 | €24.80 | |||||
Low stock:0 | €14.80 | |||||
Low stock:3 | €12.40 | |||||
420 | €0.80 | |||||
6 | €2.20 |
| 5 of 5 lines in Parts | 5 |
|---|---|
| 5 of 5 lines in Cost | €55.00 |
line-items, lively
LineItems (data-slot="line-items"): the 16 px tile, the live region.<table role="grid"> with real <th> column headers; each line is a row
(data-slot="line-items-row") of cells (line-items-cell): text inputs and Number Inputs
(compact preset) that read as text until pointed at or focused, and computed figures that roll.
Below 576 px the same rows are laid out as tiles by CSS only: the item on the first line, the
figures side by side under their labels, the line total on the last line.line-items-remove), 24 px, visible on hover and focus, always on touch.line-items-fix); while a total is traced, its count (line-items-trace) takes the same line.line-items-add), then the Undo pill
(line-items-undo) after a removal, the limit after a refused Add, or, while the grid has focus
and there is room, the shortcuts (line-items-keys); and the summary (line-items-summary, a
<tfoot> with <th scope="row"> labels and reserved width for the widest value). A summary row
with a source column has a toggle label (line-items-trace-toggle, aria-pressed).The lines are a grid named by label with aria-rowcount; every cell input is named
"Qty, line 2". Totals are read once through the rolling figure's sr-only text, its digits are
aria-hidden. A polite live region announces "Line 6 added", "Line 3 removed, Undo available" and
"Line restored". When the removed line held focus, focus moves to Undo ("Undo remove"); after Undo,
to the restored line. Add and Undo move focus only when the person pressed them, never from
actionsRef; the focus lands once the new row is fully open, so its ring is never clipped. Invalid
cells take aria-invalid and the destructive rim; the error line counts the touched lines it marks
(a line is touched once one of its cells loses focus; a new line stays a draft, never flagged, until
one of its cells is edited, or every line at once with showErrors) and names every need among
them ("2 lines need a quantity or a price"); "Fix line N" moves focus to the first failing cell.
A traced total's label is a toggle button (aria-pressed) described by "4 of 5 lines in Total, 1
left out until valid"; the lit and hatched cells are visual only. "Line 2 duplicated as line 3"
and "3 lines pasted" are announced. A pending total is aria-busy. Short stock is announced as "Low stock". The
ball, the ghost and the dots are aria-hidden. Hit areas: × 24 px, Add 32 px. Disabled keeps full
text contrast (cells become read-only), with no × and no Add.
| Keys | Action |
|---|---|
| Tab / Shift+Tab | Moves cell by cell along a line, then to the next |
| ArrowUp / ArrowDown | Moves to the same cell of the line above or below |
| Alt+ArrowUp / Alt+ArrowDown | Steps a number cell up or down |
| Enter (last cell of the last line) | Adds a line and focuses its first cell |
| Ctrl+D / Cmd+D | Duplicates the line below itself, same cell focused |
| Ctrl+V / Cmd+V (spreadsheet rows) | Fills cells rightward and downward, adds lines |
| Enter / Space (summary label) | Pins or unpins the total's trace (focus previews) |
| Delete / Backspace (remove button) | Removes the line into Undo |
| Ctrl+Z / Cmd+Z | Restores the removed line while Undo is shown |
A mouse drag across a number cell's digits scrubs it (one step per 8 px); touch never scrubs.
Pasting tab-separated text (rows copied from a sheet) fills the cells from the one pasted into,
rightward and downward, opens new lines past the last one up to max, and reads figures with
currency signs and thousands separators ("€1,250.00"); a single value pastes into the cell as usual.
Digits crossfade instead of rolling, the Add pill stays and the new row fades in, a removed line fades out and closes in the fade time while the Undo pill fades in with its dot already there, and no ball flies. Undo fades the line back, a copied or pasted line fades in, and a traced column lights all at once instead of line by line. Every state is still drawn: rims, tints, dots, the error.
Nothing runs at rest. A change renders the cells it touches; totals are one useMemo over the
value, so a controlled round trip never rolls twice. Each figure keeps one mounted roll. The add
morph is one ghost element (the pill's rim and dot; its label fades) flying from the pill's box to
the row's, measured once, on the same spring the new row opens with; the ball is one element thrown
on a spring in the foot's frame, so it lands in the dot while the rows close. Each row owns its
opening: measured once, one tween to that height, then auto, so quick adds never leave a row half
open. A pending total is one still muted tile: a state, not a loop. The trace is a data attribute and a CSS
transition per cell (its stagger is a transition delay), no animation loop. Our code is about
18.6 kB gzip including the Number Input item it uses (10.8 kB); npm
dependency: motion.
Main spring of each temperament. Set it with the temperament prop or MotionKitProvider; the default is lively.
Not measured yet · budget 18.6 kB gzip
Component and MotionKit helpers; excludes react, react-dom, motion.
a value change, press, typing
Digits crossfade, the Add pill crossfades into the new row, a removed line fades out while the Undo pill fades in, no ball flies, and a traced column lights all at once instead of down the column.
Last 2 versions of Chrome, Edge, Firefox and Safari (iOS 16.4+)