Table Extras
ProNewThree additions to the table: a handle that resizes a column by dragging or with the arrow keys, a heading row that folds a group of rows away, and row selection with Shift-click ranges.
Installation
pnpm dlx shadcn@latest add @viewport/table-extras
First time? Add the @viewport registry to components.json. Setup takes one minute.
Usage
The code behind the preview above comes with Truffle Pro.
Props
<ColumnResizer>
| Prop | Type | Default |
|---|---|---|
| width* | numberThe column's width now, in pixels. | — |
| onWidthChange* | (width: number) => void | — |
| min | number | 72 |
| max | number | 640 |
| label* | stringThe column's name, for the handle's accessible name. | — |
| onReset | () => voidRuns on a double click, e.g. to return the column to its default width. | — |
<TableGroupRow>
| Prop | Type | Default |
|---|---|---|
| label* | React.ReactNodeThe group's name, e.g. the value the rows share. | — |
| count | numberHow many rows are in the group. | — |
| colSpan* | numberHow many columns the table has, so the heading spans them all. | — |
| open* | boolean | — |
| onOpenChange* | (open: boolean) => void | — |
| summary | React.ReactNodeShown at the end of the heading, e.g. a total for the group. | — |
Accessibility
- The resize handle is a separator with a value, arrow-key steps, Home and End.
- Group headings are buttons that report whether the group is open.
- Range selection works from the keyboard with Shift and Space.
- Respects prefers-reduced-motion.