Keyframery

Table

Rows cascade in, a sortable header's arrow turns over on a spring and reports the sort to screen readers, and selected rows fade in. On a phone it scrolls sideways with a soft edge.

See it as an AI agent does.

Resize preview. Focus the handle and use the left or right arrow keys. Hold Shift for larger steps.— px
Customize1 controls
Animation speed1×

Installation

npx shadcn@latest add @keyframery/table

This adds components/keyframery/table.tsx and its primitive to your project, and installs UI SDK, along with agent-content, which it builds on. The motion tokens are added to your global CSS the first time you install a component.

Usage

import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/keyframery/table"

export default function Usage() {
  return (
    <Table>
      <TableHeader>
        <TableRow>
          <TableHead>Invoice</TableHead>
          <TableHead>Amount</TableHead>
        </TableRow>
      </TableHeader>
      <TableBody>
        <TableRow>
          <TableCell>INV-001</TableCell>
          <TableCell>€250.00</TableCell>
        </TableRow>
      </TableBody>
    </Table>
  )
}

Anatomy

How the parts fit together:

Table
├── TableHeader
│   └── TableRow
│       └── TableHead
└── TableBody
    └── TableRow
        └── TableCell

Examples

Basic

A header, a body, a footer for totals and a caption. Rows cascade in when the table first shows.

Sortable columns

Give a header sort and onSort and it becomes a button with an arrow that turns over on a spring. It sets aria-sort for screen readers.

Selecting rows

Put a Checkbox in the first column and pass selected to the row. The header's checkbox shows a dash when only some are ticked.

With pages

Give each row a stable key. When the page changes, the new rows cascade in; after a sort, rows that only moved stay still.

Wide tables on a phone

When the columns don't fit, the table scrolls sideways inside its container and the edge you can scroll toward fades. Narrow this window to see it.

Motion

MoveWhat you see
CascadeRows arrive one after another, and new rows do the same when the page or filter changes. Rows that only move, like after a sort, stay put.
SpringA sortable header's arrow turns over when the direction flips.
FadeHover and selected rows fade their colour in and out.
DirectionToo wide for the screen, it scrolls sideways and the edge you can scroll toward softens.

Timing and springiness follow the motion style you set. To change how fast this table moves, pass speed:

<Table speed="fast">
  …
</Table>

"fast" is 0.6×, "slow" 1.4×, and a number sets the multiplier. With reduced motion turned on, nothing moves: changes happen at once or with a short fade.

Theming

Set these CSS variables on the component or a parent. Leave them unset to follow the light and dark theme. The open Customize panel below the preview lets you try these settings.

VariableWhat it changesDefault
--table-inkTable text--foreground
--table-mutedHeaders and caption text--muted-foreground
--table-borderRow and footer rules--border; 70% on rows
--table-accentHover and selection tint--foreground at 3% on hover and 6% when selected
--table-footerFooter fill--muted at 40%
--table-heightBody cell height2.75rem
--table-paddingCell horizontal padding0.75rem
--table-radiusSort button corners7px

API reference

Every part takes className and children, along with the props of the element it renders. The parts are rendered by UI SDK, so they also take render, to draw your own element, and a function of their state for className and style.

Table

Renders a <table>, and takes its props too.

Prop

Type

TableRow

Renders a <tr>, and takes its props too.

Prop

Type

TableHead

Renders a <tableheadercell>, and takes its props too.

Prop

Type

Other parts

These take the props of the element they render, and nothing else:

  • TableHeader: a <tbody>
  • TableBody: a <tbody>
  • TableCell: a <tabledatacell>
  • TableCaption
  • TableFooter: a <tbody>

Keyboard

KeyWhat it does
TabMoves between the sort buttons, checkboxes and links in the table.
EnterSorts by the focused column, or turns its sort over.
SpaceSorts by the focused column, or ticks the focused row's checkbox.
Shift + scrollScrolls a wide table sideways.

Accessibility

Roles, keyboard and focus are declared on the component's UI SDK primitive, and state is announced through the matching ARIA attributes. More in Accessibility.

Built on UI SDK's core

UI SDK doesn't ship a table, so this one is defined with its core: one definePrimitive in components/keyframery/core/table-core.ts, with no React in it. UI SDK's adapters can render that same definition in Vue, Svelte, Solid and web components. To keep your own styling and take only the motion, import from @/components/keyframery/primitives/table.

Questions

How does the animated Table for UI SDK move?

Cascade: Rows arrive one after another, and new rows do the same when the page or filter changes. Rows that only move, like after a sort, stay put. Spring: A sortable header's arrow turns over when the direction flips. Fade: Hover and selected rows fade their colour in and out. Direction: Too wide for the screen, it scrolls sideways and the edge you can scroll toward softens.

Do I need Motion or Framer Motion for the animated Table?

No. Every move is plain CSS, so there is nothing to install besides the component and UI SDK.

UI SDK has no table. How is this one built on UI SDK?

Its behaviour is one definition written with UI SDK's core (definePrimitive), in components/keyframery/core/table-core.ts. Its parts are rendered by UI SDK's adapter, so they take render, state-based class names and data-slot, like every UI SDK component.

What happens to the Table when someone turns on reduced motion?

Nothing moves. State changes happen at once, or with a short fade.

All components

On this page