Table with motion: when its rows change, they move instead of jumping. A sort glides each row to its new place, a row that goes fades out while the rest close up, and a new one fades in, tinted for a moment.
$ pnpm dlx shadcn@latest add @dashral/motion-tableInstallation
$ pnpm dlx shadcn@latest add @dashral/motion-tableAdds components/dashral/motion/table.tsx, the Table it builds on (in components/dashral/), motion and the motion files every motion component shares. Or by its full URL: https://dashral.com/r/motion-table.json
Usage
The same as Table, imported from components/dashral/motion/ (with the npm package: @dashral/motion/components/table): swap the import and it moves.
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/dashral/motion/table"
<Table>
<TableHeader>
<TableRow>
<TableHead>Customer</TableHead>
<TableHead className="text-right">Total</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{orders.map((order) => (
<TableRow key={order.id}>
<TableCell>{order.customer}</TableCell>
<TableCell className="text-right">{order.total}</TableCell>
</TableRow>
))}
</TableBody>
</Table>Examples
Compared with Default
Rows appear, move and disappear at once when the data changes.
Motion
Rows glide to a new place when the order changes, fade out while the rest close up, and new ones fade in, tinted for a moment.
How the two editions differ in general, and which to use where: Motion.
API reference
Every prop of Table, and every attribute of the element it renders. What the Motion edition adds is marked Motion.
Table, TableHeader, TableBody, TableFooter, TableRow, TableHead, TableCell, TableCaption
Styled table elements; the table scrolls sideways when it doesn't fit.
Also takes every prop of <table>(opens in a new tab).
TableBodyMotion
| Prop | Type | Default |
|---|---|---|
highlightNew | booleanRows that arrive after the table first drew are tinted in the primary color for a moment, so the eye finds them. | true |
Table, TableHeader, TableFooter, TableHead, TableCell and TableCaption are the default edition's, re-exported. Give each TableRow a stable key (the record's id), or React can't tell which row moved.
Motion
- When the order changes (a sort, a row moved to the top), each row glides to its new place in 0.35s on a smooth curve, no spring.
- A row that goes fades out in 0.18s, then the rows under it glide up to close the gap.
- A row that arrives fades in from 6px above, and a tint of the primary color over it fades away over 1.4s; hover and selected still show under the tint. highlightNew turns the tint off.
- The first draw stays still, and rows in the header and footer never move. With reduced motion, rows only fade in and out.