@aircall/ds 0.49.0 → 0.50.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{data-table-B3ahtFLP.js → data-table-AX0Mgu6K.js} +5 -0
- package/dist/{data-table-BgeS8KWP.d.ts → data-table-B5VqWPmw.d.ts} +3 -4
- package/dist/data-table.d.ts +1 -1
- package/dist/data-table.js +1 -1
- package/dist/globals.css +1 -1
- package/dist/index.d.ts +53 -16
- package/dist/index.js +113 -20
- package/package.json +2 -2
- package/skills/aircall-ds/migrate-audio-player/SKILL.md +14 -3
- package/skills/aircall-ds/migrate-icons/SKILL.md +45 -16
- package/skills/aircall-ds/migrate-tractor/SKILL.md +34 -31
- package/skills/aircall-ds/migrate-tractor/accordion/SKILL.md +25 -15
- package/skills/aircall-ds/migrate-tractor/alert/SKILL.md +107 -20
- package/skills/aircall-ds/migrate-tractor/avatar/SKILL.md +57 -26
- package/skills/aircall-ds/migrate-tractor/badge/SKILL.md +71 -25
- package/skills/aircall-ds/migrate-tractor/button/SKILL.md +68 -32
- package/skills/aircall-ds/migrate-tractor/card/SKILL.md +62 -42
- package/skills/aircall-ds/migrate-tractor/combobox/SKILL.md +233 -149
- package/skills/aircall-ds/migrate-tractor/data-table/SKILL.md +102 -108
- package/skills/aircall-ds/migrate-tractor/data-table/references/column-widths-and-pinning.md +50 -0
- package/skills/aircall-ds/migrate-tractor/data-table/references/infinite-scroll.md +51 -0
- package/skills/aircall-ds/migrate-tractor/data-table/references/row-actions.md +34 -0
- package/skills/aircall-ds/migrate-tractor/date-picker/SKILL.md +100 -47
- package/skills/aircall-ds/migrate-tractor/dialog/SKILL.md +115 -20
- package/skills/aircall-ds/migrate-tractor/dropdown-menu/SKILL.md +135 -57
- package/skills/aircall-ds/migrate-tractor/dropzone/SKILL.md +2 -0
- package/skills/aircall-ds/migrate-tractor/form-and-field/SKILL.md +111 -49
- package/skills/aircall-ds/migrate-tractor/gauge/SKILL.md +6 -4
- package/skills/aircall-ds/migrate-tractor/input/SKILL.md +165 -59
- package/skills/aircall-ds/migrate-tractor/item/SKILL.md +85 -63
- package/skills/aircall-ds/migrate-tractor/link/SKILL.md +85 -68
- package/skills/aircall-ds/migrate-tractor/popover/SKILL.md +115 -74
- package/skills/aircall-ds/migrate-tractor/select/SKILL.md +117 -64
- package/skills/aircall-ds/migrate-tractor/sheet-vs-drawer/SKILL.md +55 -32
- package/skills/aircall-ds/migrate-tractor/skeleton/SKILL.md +40 -11
- package/skills/aircall-ds/migrate-tractor/styling/SKILL.md +11 -7
- package/skills/aircall-ds/migrate-tractor/tabs/SKILL.md +62 -55
- package/skills/aircall-ds/migrate-tractor/toast/SKILL.md +58 -12
- package/skills/aircall-ds/migrate-tractor/tooltip/SKILL.md +65 -40
- package/skills/aircall-ds/migrate-tractor/tree/SKILL.md +23 -6
- package/skills/aircall-ds/setup/SKILL.md +53 -8
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
name: aircall-ds/migrate-tractor/data-table
|
|
3
3
|
description: >
|
|
4
4
|
Migrate Tractor Table and TableColumn to the @aircall/ds DataTable (TanStack
|
|
5
|
-
Table-backed). Load when a file imports Table or
|
|
6
|
-
Covers column definitions, sorting, row selection
|
|
7
|
-
`
|
|
5
|
+
Table-backed). Load when a file imports Table, TableColumn or ActionBar from
|
|
6
|
+
@aircall/tractor. Covers column definitions and widths, sorting, row selection with the
|
|
7
|
+
floating ActionBar, column pinning (`stickTo` -> `columnPinning`), row actions, loading
|
|
8
|
+
states, empty states, infinite scroll and row virtualization.
|
|
8
9
|
type: sub-skill
|
|
9
10
|
library: aircall-ds
|
|
10
11
|
requires:
|
|
@@ -12,6 +13,9 @@ requires:
|
|
|
12
13
|
- aircall-ds/migrate-tractor
|
|
13
14
|
sources:
|
|
14
15
|
- "aircall/hydra:packages/ds/src/components/data-table.tsx"
|
|
16
|
+
- "aircall/hydra:packages/ds/src/components/action-bar.tsx"
|
|
17
|
+
- "aircall/hydra:packages/ds/src/stories/DataTable.stories.tsx"
|
|
18
|
+
- "aircall/hydra:packages/ds/src/stories/DataTableColumnSizing.stories.tsx"
|
|
15
19
|
---
|
|
16
20
|
|
|
17
21
|
This skill builds on aircall-ds/migrate-tractor. Apply all cross-cutting rules from that skill (prop renames, `render` prop, data attributes) before the data-table-specific steps below.
|
|
@@ -24,6 +28,8 @@ DS `DataTable` is built on **TanStack Table v8**. Columns are defined as `Column
|
|
|
24
28
|
|
|
25
29
|
There is no sub-component API (no `<TableColumn>`) — everything is declared in `columns`.
|
|
26
30
|
|
|
31
|
+
`DataTable` **never sorts or paginates rows itself**: it renders `data` as given. Turning sorting on (`onSortingChange`) only makes the headers clickable and reports the new `SortingState`; you sort `data` (client side) or re-query (server side) in response. For a static table with no state use the `Table` primitives (`Table`, `TableHeader`, `TableBody`, `TableRow`, `TableHead`, `TableCell`) instead.
|
|
32
|
+
|
|
27
33
|
## 2. Component mapping
|
|
28
34
|
|
|
29
35
|
| Tractor | @aircall/ds |
|
|
@@ -34,24 +40,36 @@ There is no sub-component API (no `<TableColumn>`) — everything is declared in
|
|
|
34
40
|
| `columns[n].label` | `ColumnDef.header` |
|
|
35
41
|
| `columns[n].renderer` | `ColumnDef.cell` (receives `{ row }`) |
|
|
36
42
|
| `columns[n].sortable` | `ColumnDef.enableSorting` |
|
|
37
|
-
| `loading={true}` | `loadingState="loading"` |
|
|
43
|
+
| `loading={true}` | `loadingState="loading"` (skeleton rows) |
|
|
44
|
+
| `pageSize` (number of skeleton rows while loading) | `skeletonCount` (default 5) |
|
|
38
45
|
| `noDataMessage` | `emptyState` (accepts any `ReactNode`) |
|
|
39
|
-
| `onRowClick(record, event)` | `onRowClick(row)` (no `event` argument
|
|
46
|
+
| `onRowClick(record, event)` | `onRowClick(row)` — receives the data record (`TData`), no `event` argument. Once a row is selected, a row click toggles selection instead |
|
|
40
47
|
| `bulkActions` + `verticalScrollingParent` | `selectionMode` + `actionBar` |
|
|
48
|
+
| `hideActionBar` | omit `actionBar` |
|
|
49
|
+
| `onSelectionChange(rows, count)` | `onSelectionChange(keys: Set<string>)` |
|
|
50
|
+
| `recordAttributeIdentifier` (default `'id'`) | `getRowId` (default: the row index) |
|
|
51
|
+
| `disableRow` / `unselectableRowCondition` | `disabledKeys: Set<string>` + `disabledBehavior` (`'all'` default: dimmed and inert; `'selection'`: only unselectable, still clickable) |
|
|
52
|
+
| `rowActions` + `rowActionsType` | a trailing `ColumnDef` whose `cell` renders a `DropdownMenu` (see §6d) |
|
|
41
53
|
| `onOrderChange(columnId)` | `onSortingChange` (receives `SortingState`) + `sorting` |
|
|
42
54
|
| `order` (`OrderInput`) | `sorting` (`SortingState`) |
|
|
43
|
-
| `footer` | column-level `ColumnDef.footer` (auto-renders `<tfoot>`) |
|
|
44
|
-
| `stickTo: 'left' \| 'right'` (Tractor column pinning) | `
|
|
45
|
-
|
|
|
55
|
+
| `footer` (any node under the table) | column-level `ColumnDef.footer` (column-aligned summary cells, auto-renders `<tfoot>`); render other footer content (e.g. a count) outside `DataTable` |
|
|
56
|
+
| `stickTo: 'left' \| 'right'` (Tractor column pinning) | `columnPinning={{ left: [ids], right: [ids] }}` prop on `DataTable` |
|
|
57
|
+
| `w` / `h` / sizing props | `className`; `fillHeight` inside a bounded flex parent |
|
|
58
|
+
| _(no equivalent)_ | `loadingState="sorting"` / `"filtering"` (overlay spinner over the current rows) |
|
|
46
59
|
| _(no equivalent)_ | `loadingState="loadingMore"` (infinite scroll spinner row) |
|
|
47
60
|
| _(no equivalent)_ | `onFetchMore` + `hasMore` (IntersectionObserver sentinel for infinite scroll) |
|
|
48
61
|
| _(no equivalent)_ | `fillHeight` (sticky header, internal scroll) |
|
|
49
62
|
| _(no equivalent)_ | `virtualizeRows` (explicit row virtualization — requires `fillHeight`) |
|
|
63
|
+
| _(no equivalent)_ | `enableColumnResizing`, `columnVisibility` (controlled `VisibilityState`) |
|
|
50
64
|
|
|
51
65
|
## 3. Verified DS exports (`packages/ds/src/index.ts`)
|
|
52
66
|
|
|
53
67
|
```
|
|
54
|
-
DataTable, type ColumnDef, type
|
|
68
|
+
DataTable, type ColumnDef, type ColumnPinningState, type DataTableLoadingState,
|
|
69
|
+
type OnChangeFn, type SortingState, type VisibilityState
|
|
70
|
+
Table, TableHeader, TableBody, TableFooter, TableHead, TableRow, TableCell // static primitives
|
|
71
|
+
ActionBar, ActionBarButton, ActionBarContext, ActionBarHeight
|
|
72
|
+
Empty, EmptyHeader, EmptyMedia, EmptyTitle, EmptyDescription, EmptyContent
|
|
55
73
|
```
|
|
56
74
|
|
|
57
75
|
`@aircall/ds` **exposes** the TanStack Table types you author — `ColumnDef`, `SortingState`, `OnChangeFn` — as bound aliases, so **import them from `@aircall/ds`**, not `@tanstack/react-table`. The react-table runtime ships as a regular `@aircall/ds` dependency (auto-installed; `DataTable` owns the table instance internally), so there is nothing to install and no version to keep in sync.
|
|
@@ -60,7 +78,7 @@ DataTable, type ColumnDef, type DataTableLoadingState, type OnChangeFn, type Sor
|
|
|
60
78
|
|
|
61
79
|
```tsx
|
|
62
80
|
import { DataTable, type DataTableLoadingState } from '@aircall/ds';
|
|
63
|
-
import type { ColumnDef, SortingState, OnChangeFn } from '@aircall/ds';
|
|
81
|
+
import type { ColumnDef, ColumnPinningState, SortingState, OnChangeFn, VisibilityState } from '@aircall/ds';
|
|
64
82
|
```
|
|
65
83
|
|
|
66
84
|
## 5. Column definitions
|
|
@@ -72,41 +90,21 @@ Tractor used a descriptor array (`TableColumn[]`) with a `renderer` function. DS
|
|
|
72
90
|
| `id` | `accessorKey` (auto-creates accessor) or `id` + `accessorFn` |
|
|
73
91
|
| `label` | `header` (`ReactNode` or render function) |
|
|
74
92
|
| `renderer(rowData, value, rowIndex)` | `cell: ({ row }) => row.original.<field>` |
|
|
75
|
-
| `sortable: false` | `enableSorting: false` |
|
|
76
|
-
| `
|
|
93
|
+
| `sortable: false` | `enableSorting: false` (a column with an accessor is sortable once `onSortingChange` is passed; display columns are not) |
|
|
94
|
+
| `textAlign` | Tailwind on the cell content, e.g. `cell: … => <div className="text-right">…</div>` |
|
|
95
|
+
| `stickTo` / `StickTo.Left` / `StickTo.Right` | the table-level `columnPinning` prop (ids of the pinned columns) — not a field on the column def |
|
|
77
96
|
| _(no equivalent)_ | `footer` (triggers `<tfoot>` rendering) |
|
|
78
|
-
| _(no equivalent)_ | `size`, `minSize`, `maxSize
|
|
97
|
+
| _(no equivalent)_ | `size`, `minSize`, `maxSize`, `flex` — see "Column widths" below |
|
|
79
98
|
|
|
80
|
-
### Column
|
|
99
|
+
### Column widths
|
|
81
100
|
|
|
82
|
-
|
|
101
|
+
A numeric `size` is static (exact px); a column without one is flexible and shares the leftover space equally (`flex` weights the share, `minSize` is the floor, default 75, `maxSize` caps). Keep at least one column flexible. `fixedLayout` is a deprecated no-op: delete it.
|
|
83
102
|
|
|
84
|
-
|
|
85
|
-
const columns: ColumnDef<Person>[] = [
|
|
86
|
-
{
|
|
87
|
-
accessorKey: 'name',
|
|
88
|
-
header: 'Name',
|
|
89
|
-
size: 220,
|
|
90
|
-
meta: { pin: 'left' }
|
|
91
|
-
},
|
|
92
|
-
{ accessorKey: 'email', header: 'Email', size: 280 },
|
|
93
|
-
{
|
|
94
|
-
id: 'actions',
|
|
95
|
-
header: '',
|
|
96
|
-
size: 40,
|
|
97
|
-
enableResizing: false,
|
|
98
|
-
meta: { pin: 'right' },
|
|
99
|
-
cell: ({ row }) => <RowActionsMenu person={row.original} />
|
|
100
|
-
}
|
|
101
|
-
];
|
|
102
|
-
```
|
|
103
|
+
### Column pinning (`stickTo` → `columnPinning`)
|
|
103
104
|
|
|
104
|
-
|
|
105
|
+
Pin with the controlled table-level `columnPinning={{ left: [ids], right: [ids] }}` prop, never a per-column field. Ids resolve as `id` → string `accessorKey` → string `header`; display columns need an explicit `id`. With `selectionMode` on, the checkbox column auto-pins left when anything is pinned. There is no `onColumnPinningChange`.
|
|
105
106
|
|
|
106
|
-
|
|
107
|
-
- **Resolvable id required.** Pinning derives TanStack `columnPinning` from column ids. Resolution matches TanStack: `id` → string `accessorKey` → string `header`. Display-only columns (`cell` + non-string `header`, no `id`/`accessorKey`) need an explicit `id` or pinning is skipped (dev warning).
|
|
108
|
-
- **Selection auto-pin is gated.** When `selectionMode` is on *and* at least one consumer column has `meta.pin`, the built-in checkbox column is also auto-pinned left. Selection-only tables without `meta.pin` stay on fluid layout.
|
|
109
|
-
- Tractor's left-pinned select + right-pinned actions map to: pin your identity/name column(s) left, pin the actions column right, enable `selectionMode` — the checkbox column joins the left pin group automatically.
|
|
107
|
+
See `references/column-widths-and-pinning.md` for the full width model, pinning rules and a worked example.
|
|
110
108
|
|
|
111
109
|
Source: `packages/ds/src/components/data-table.tsx`
|
|
112
110
|
|
|
@@ -191,7 +189,7 @@ const columns: TableColumn<Person>[] = [
|
|
|
191
189
|
```tsx
|
|
192
190
|
// After
|
|
193
191
|
import { DataTable } from '@aircall/ds';
|
|
194
|
-
import type { ColumnDef, SortingState
|
|
192
|
+
import type { ColumnDef, SortingState } from '@aircall/ds';
|
|
195
193
|
|
|
196
194
|
const [sorting, setSorting] = React.useState<SortingState>([{ id: 'firstName', desc: false }]);
|
|
197
195
|
|
|
@@ -212,7 +210,8 @@ const columns: ColumnDef<Person>[] = [
|
|
|
212
210
|
|
|
213
211
|
Key changes:
|
|
214
212
|
- `order: OrderInput` → `sorting: SortingState` (array of `{ id, desc }` objects)
|
|
215
|
-
- `onOrderChange(columnId)` → `onSortingChange: OnChangeFn<SortingState>` (receives the new full state)
|
|
213
|
+
- `onOrderChange(columnId)` → `onSortingChange: OnChangeFn<SortingState>` (receives the new full state, so there is no direction toggling to write)
|
|
214
|
+
- `DataTable` does not reorder `data`: refetch with the new `sorting` (server side), or sort the array yourself (client side, see the `Full` story)
|
|
216
215
|
- A `loadingState="sorting"` dims the existing rows with an overlay spinner while the server re-queries — no skeleton flash
|
|
217
216
|
|
|
218
217
|
### 6c. Selectable table with bulk action bar
|
|
@@ -240,6 +239,8 @@ const parentRef = React.useRef<HTMLDivElement | null>(null);
|
|
|
240
239
|
import { DataTable } from '@aircall/ds';
|
|
241
240
|
import { ActionBar, ActionBarButton } from '@aircall/ds';
|
|
242
241
|
|
|
242
|
+
import { Trash } from '@aircall/react-icons';
|
|
243
|
+
|
|
243
244
|
const [selectedKeys, setSelectedKeys] = React.useState<Set<string>>(new Set());
|
|
244
245
|
|
|
245
246
|
<DataTable
|
|
@@ -249,10 +250,11 @@ const [selectedKeys, setSelectedKeys] = React.useState<Set<string>>(new Set());
|
|
|
249
250
|
selectionMode="multiple"
|
|
250
251
|
selectedKeys={selectedKeys}
|
|
251
252
|
onSelectionChange={setSelectedKeys}
|
|
253
|
+
// Inside a DataTable, ActionBar reads `count` and the Clear handler from context: no props needed.
|
|
252
254
|
actionBar={
|
|
253
255
|
<ActionBar>
|
|
254
|
-
<ActionBarButton
|
|
255
|
-
Delete
|
|
256
|
+
<ActionBarButton onClick={deleteSelected}>
|
|
257
|
+
<Trash /> Delete
|
|
256
258
|
</ActionBarButton>
|
|
257
259
|
</ActionBar>
|
|
258
260
|
}
|
|
@@ -260,10 +262,19 @@ const [selectedKeys, setSelectedKeys] = React.useState<Set<string>>(new Set());
|
|
|
260
262
|
```
|
|
261
263
|
|
|
262
264
|
Key changes:
|
|
263
|
-
- `verticalScrollingParent` is not needed —
|
|
264
|
-
- `bulkActions` array → pass an `<ActionBar>` node to the `actionBar` prop
|
|
265
|
-
- `
|
|
266
|
-
- `
|
|
265
|
+
- `verticalScrollingParent` is not needed — the bar floats at the bottom of the table and the scroll area reserves space for it
|
|
266
|
+
- `bulkActions` array → pass an `<ActionBar>` node to the `actionBar` prop. The bar shows only while at least one selected row is **in the current `data`**, with an "N items selected." label and a clear (X) button. Its count comes from the loaded rows (`getSelectedRowModel()`), not from `selectedKeys`
|
|
267
|
+
- `ActionBarButton` is always `ghost`; it only takes `size="default" | "icon"`. There is no `variant` prop, so a destructive action is not styled red: say so in the label/icon. Put the icon inside as a child
|
|
268
|
+
- `ActionBar` outside a `DataTable` needs its own `count` and `onClear` props (or an `ActionBarContext` provider)
|
|
269
|
+
- `onSelectionChange(selectedRows, count)` is replaced by controlled `selectedKeys` — a React-Spectrum-style `Set<string>` of row ids. For the current page, derive selected records from `data.filter(p => selectedKeys.has(p.id))`
|
|
270
|
+
- `selectionMode="single"` shows a checkbox column with no select-all header; picking a row replaces the selection
|
|
271
|
+
- `getRowId` is required when selection must survive data refreshes (server pagination); without it the keys are row indexes
|
|
272
|
+
- **Selection across pages:** with server pagination, keys survive a page change but the built-in bar only counts rows on the loaded page, so it hides when the user moves to a page with none selected, and `data.filter` can't see off-page records. For cross-page bulk actions, keep the selected records yourself (a `Map` updated in `onSelectionChange`), render your own `ActionBar` outside the table with `count` / `onClear` from that state, and leave the `actionBar` prop unset
|
|
273
|
+
- Once anything is selected, clicking a row toggles it instead of calling `onRowClick`. Interactive cells (menus, links) must stop propagation themselves; the built-in checkbox already does
|
|
274
|
+
|
|
275
|
+
### 6d. Row actions column
|
|
276
|
+
|
|
277
|
+
Tractor's `rowActions` / `rowActionsType` become an ordinary trailing column (`id: 'actions'`, `header: ''`, static `size: 40`, `enableResizing: false`) whose `cell` renders a `DropdownMenu`; wrap it in a div that stops click propagation so it does not fire `onRowClick`. See `references/row-actions.md` for the full example.
|
|
267
278
|
|
|
268
279
|
## 7. Common mistakes
|
|
269
280
|
|
|
@@ -289,7 +300,7 @@ const columns: ColumnDef<Person>[] = [
|
|
|
289
300
|
];
|
|
290
301
|
```
|
|
291
302
|
|
|
292
|
-
`ColumnDef` has no `renderer` field —
|
|
303
|
+
`ColumnDef` has no `renderer` field — it is dead code and is never called, so the cell renders the raw accessor value. Use `cell: ({ row }) => …` and access typed row data via `row.original`.
|
|
293
304
|
|
|
294
305
|
Source: `packages/ds/src/components/data-table.tsx`
|
|
295
306
|
|
|
@@ -349,93 +360,76 @@ Source: `packages/ds/src/components/data-table.tsx`
|
|
|
349
360
|
<DataTable data={[]} columns={columns} noDataMessage="No records found." />
|
|
350
361
|
|
|
351
362
|
// Correct — emptyState accepts any ReactNode; render an Empty component for rich states
|
|
352
|
-
import { Empty,
|
|
363
|
+
import { Empty, EmptyDescription, EmptyHeader, EmptyMedia, EmptyTitle } from '@aircall/ds';
|
|
364
|
+
import { Search } from '@aircall/react-icons';
|
|
353
365
|
|
|
354
366
|
<DataTable
|
|
355
367
|
data={[]}
|
|
356
368
|
columns={columns}
|
|
357
369
|
emptyState={
|
|
358
370
|
<Empty>
|
|
359
|
-
<
|
|
371
|
+
<EmptyHeader>
|
|
372
|
+
<EmptyMedia variant="icon">
|
|
373
|
+
<Search />
|
|
374
|
+
</EmptyMedia>
|
|
360
375
|
<EmptyTitle>No records found</EmptyTitle>
|
|
361
376
|
<EmptyDescription>Try adjusting your filters.</EmptyDescription>
|
|
362
|
-
</
|
|
377
|
+
</EmptyHeader>
|
|
363
378
|
</Empty>
|
|
364
379
|
}
|
|
365
380
|
/>
|
|
366
381
|
```
|
|
367
382
|
|
|
368
|
-
Tractor `noDataMessage` accepted a `ReactNode` but was declared as a simple prop. DS requires an `emptyState` prop; `noDataMessage` is silently ignored. For plain text, wrap it in a `<p>` with `text-sm text-muted-foreground`. For a full empty state
|
|
383
|
+
Tractor `noDataMessage` accepted a `ReactNode` but was declared as a simple prop. DS requires an `emptyState` prop; `noDataMessage` is silently ignored. For plain text, wrap it in a `<p>` with `text-sm text-muted-foreground`. For a full empty state use the `Empty` compound from `@aircall/ds`: `EmptyHeader` holds the media, title and description, and `EmptyContent` is the region below for actions (buttons). In an `@aircall/blocks` app prefer `NoDataEmptyState` (search/filter with no results) or the other `*EmptyState` presets. `emptyState` shows only when there are no rows and `loadingState` is not `'loading'`; nothing renders if you omit it.
|
|
369
384
|
|
|
370
385
|
Source: `packages/ds/src/components/data-table.tsx`
|
|
371
386
|
|
|
372
|
-
### Mistake 5 — `meta.pin`
|
|
387
|
+
### Mistake 5 — Pinning with `stickTo` or `meta.pin` instead of the `columnPinning` prop
|
|
373
388
|
|
|
374
389
|
```tsx
|
|
375
|
-
// Wrong —
|
|
376
|
-
|
|
377
|
-
header:
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
// Correct —
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
meta: { pin: 'left' }
|
|
389
|
-
}
|
|
390
|
+
// Wrong — stickTo is Tractor's; meta.pin was removed from DataTable and is ignored
|
|
391
|
+
const columns: ColumnDef<Person>[] = [
|
|
392
|
+
{ accessorKey: 'name', header: 'Name', size: 220, stickTo: 'left' },
|
|
393
|
+
{ id: 'actions', header: '', size: 40, meta: { pin: 'right' } }
|
|
394
|
+
];
|
|
395
|
+
<DataTable columns={columns} data={people} />
|
|
396
|
+
|
|
397
|
+
// Correct — pin by column id on the table
|
|
398
|
+
<DataTable
|
|
399
|
+
columns={columns}
|
|
400
|
+
data={people}
|
|
401
|
+
columnPinning={{ left: ['name'], right: ['actions'] }}
|
|
402
|
+
/>
|
|
390
403
|
```
|
|
391
404
|
|
|
392
|
-
|
|
405
|
+
Pinning is a controlled table-level prop (`ColumnPinningState`, arrays of column ids), like `sorting` and `columnVisibility`. The ids are the ones TanStack resolves: `id`, else the `accessorKey` (dots become `_`), else a string `header`. A column with none of those, such as a display column with a render-function `header`, needs an explicit `id` or the id in `columnPinning` matches nothing.
|
|
393
406
|
|
|
394
407
|
Source: `packages/ds/src/components/data-table.tsx`
|
|
395
408
|
|
|
396
|
-
|
|
409
|
+
### Mistake 6 — Declaring a `size` on every column
|
|
397
410
|
|
|
398
|
-
|
|
411
|
+
```tsx
|
|
412
|
+
// Wrong — every column is static, so nothing absorbs the container width and the table ends short
|
|
413
|
+
const columns: ColumnDef<Person>[] = [
|
|
414
|
+
{ accessorKey: 'name', header: 'Name', size: 260 },
|
|
415
|
+
{ accessorKey: 'email', header: 'Email', size: 280 },
|
|
416
|
+
{ id: 'actions', header: '', size: 40 }
|
|
417
|
+
];
|
|
399
418
|
|
|
400
|
-
|
|
419
|
+
// Correct — static for columns with a known width, flexible (with a floor) for the rest
|
|
420
|
+
const columns: ColumnDef<Person>[] = [
|
|
421
|
+
{ accessorKey: 'name', header: 'Name', minSize: 260 },
|
|
422
|
+
{ accessorKey: 'email', header: 'Email', minSize: 200 },
|
|
423
|
+
{ id: 'actions', header: '', size: 40 }
|
|
424
|
+
];
|
|
425
|
+
```
|
|
401
426
|
|
|
402
|
-
|
|
427
|
+
A numeric `size` is exact and never grows; a column without one takes an equal share of the free space. The selection checkbox column is always 40px static, so with `selectionMode` on, at least one more column must stay flexible.
|
|
403
428
|
|
|
404
|
-
|
|
429
|
+
Source: `packages/ds/src/components/data-table.tsx`
|
|
405
430
|
|
|
406
|
-
|
|
407
|
-
// Infinite scroll with virtualization
|
|
408
|
-
function CallsTable() {
|
|
409
|
-
const [items, setItems] = React.useState<Call[]>(() => fetchPage(0));
|
|
410
|
-
const [isFetchingMore, setIsFetchingMore] = React.useState(false);
|
|
411
|
-
const hasMore = items.length < totalCount;
|
|
412
|
-
|
|
413
|
-
const onFetchMore = React.useCallback(() => {
|
|
414
|
-
if (isFetchingMore || !hasMore) return;
|
|
415
|
-
setIsFetchingMore(true);
|
|
416
|
-
fetchPage(items.length).then(page => {
|
|
417
|
-
setItems(prev => [...prev, ...page]);
|
|
418
|
-
setIsFetchingMore(false);
|
|
419
|
-
});
|
|
420
|
-
}, [isFetchingMore, hasMore, items.length]);
|
|
421
|
-
|
|
422
|
-
return (
|
|
423
|
-
<div className="flex h-dvh flex-col p-4">
|
|
424
|
-
<DataTable
|
|
425
|
-
columns={columns} // each column must have a size when virtualizing
|
|
426
|
-
data={items}
|
|
427
|
-
getRowId={row => row.id}
|
|
428
|
-
fillHeight
|
|
429
|
-
virtualizeRows
|
|
430
|
-
onFetchMore={onFetchMore}
|
|
431
|
-
hasMore={hasMore}
|
|
432
|
-
loadingState={isFetchingMore ? 'loadingMore' : 'idle'}
|
|
433
|
-
/>
|
|
434
|
-
</div>
|
|
435
|
-
);
|
|
436
|
-
}
|
|
437
|
-
```
|
|
431
|
+
## 8. Infinite scroll and row virtualization
|
|
438
432
|
|
|
439
|
-
|
|
433
|
+
`onFetchMore` + `hasMore` give infinite scroll; `virtualizeRows` is a separate opt-in that **requires `fillHeight`** inside a bounded-height parent. Pagination needs neither. See `references/infinite-scroll.md` for the rules and a full example.
|
|
440
434
|
|
|
441
|
-
Source: `packages/ds/src/components/data-table.tsx`
|
|
435
|
+
Source: `packages/ds/src/components/data-table.tsx`, `packages/ds/src/stories/DataTable.stories.tsx` (`VirtualizedInfiniteScroll`, `InfiniteScroll`)
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
## Column widths
|
|
2
|
+
|
|
3
|
+
Tractor sized columns from content. DS resolves every column width from the defs, in every mode (this is what React Spectrum's `TableView` does too):
|
|
4
|
+
|
|
5
|
+
- **`size: 40`** — static: exactly 40px at every container width. Use it for columns with a known width (checkbox, icon, row actions, status badge).
|
|
6
|
+
- **no `size`** — flexible: an equal share of whatever the static columns leave. This is the default, so leave identity columns (name, email) without a `size`.
|
|
7
|
+
- **`flex: 2`** — flexible with twice the share. **`minSize`** is the floor (defaults to **75** on a flexible column; when floors exceed the container the table scrolls horizontally instead of crushing columns). **`maxSize`** caps it.
|
|
8
|
+
- If **every** column declares a `size`, nothing absorbs the container width and the table ends short of its right edge. Keep at least one column flexible (give it a `minSize` rather than a `size`).
|
|
9
|
+
- Cells clip at the column edge. Wrap long text in a `truncate` div for an ellipsis.
|
|
10
|
+
- `fixedLayout` is deprecated and does nothing (still accepted); delete it.
|
|
11
|
+
|
|
12
|
+
## Column pinning (`stickTo` → `columnPinning`)
|
|
13
|
+
|
|
14
|
+
Tractor pinned columns with `stickTo: StickTo.Left | StickTo.Right` (selection stuck left, row actions stuck right). DS has a controlled `columnPinning` prop (TanStack `ColumnPinningState`) that lists column ids; there is no per-column field and no `meta.pin`:
|
|
15
|
+
|
|
16
|
+
```tsx
|
|
17
|
+
const columns: ColumnDef<Person>[] = [
|
|
18
|
+
{ accessorKey: 'name', header: 'Name', size: 220 },
|
|
19
|
+
{ accessorKey: 'email', header: 'Email', minSize: 280 }, // flexible: absorbs the spare width
|
|
20
|
+
{ accessorKey: 'phone', header: 'Phone', size: 200 },
|
|
21
|
+
{
|
|
22
|
+
id: 'actions',
|
|
23
|
+
header: '',
|
|
24
|
+
size: 40,
|
|
25
|
+
enableResizing: false,
|
|
26
|
+
cell: ({ row }) => <RowActionsMenu person={row.original} />
|
|
27
|
+
}
|
|
28
|
+
];
|
|
29
|
+
|
|
30
|
+
<DataTable
|
|
31
|
+
columns={columns}
|
|
32
|
+
data={people}
|
|
33
|
+
getRowId={row => row.id}
|
|
34
|
+
columnPinning={{ left: ['name'], right: ['actions'] }}
|
|
35
|
+
selectionMode="multiple"
|
|
36
|
+
selectedKeys={selectedKeys}
|
|
37
|
+
onSelectionChange={setSelectedKeys}
|
|
38
|
+
fillHeight
|
|
39
|
+
/>
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Rules:
|
|
43
|
+
|
|
44
|
+
- **Use ids that the table resolves.** The ids in `columnPinning` are the column ids: `id` → string `accessorKey` (dots replaced by `_`) → string `header`. A display-only column (`cell` with a non-string `header`, no `id`/`accessorKey`) needs an explicit `id` to be pinnable.
|
|
45
|
+
- Pin offsets come from the resolved widths, so pinned columns need no special sizing. Give pinned columns a `size` when their width is known (a name column, the actions column) and keep at least one unpinned column flexible.
|
|
46
|
+
- **Selection auto-pin.** When `columnPinning` pins anything and `selectionMode` is on, the built-in checkbox column is auto-pinned left so it cannot scroll away from its rows. A selection-only table with no `columnPinning` stays unpinned.
|
|
47
|
+
- `columnPinning` is a controlled prop with no `onColumnPinningChange` callback: the user can't re-pin columns from the UI. You can still change pinning at runtime by passing a new value from your own state (a toggle, a screen-size hook), and the table re-resolves it.
|
|
48
|
+
- Tractor's left-pinned select + right-pinned actions map to: list your identity column(s) in `columnPinning.left`, the actions column in `columnPinning.right`, and enable `selectionMode`.
|
|
49
|
+
|
|
50
|
+
Source: `packages/ds/src/components/data-table.tsx`
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
## Infinite scroll and row virtualization
|
|
2
|
+
|
|
3
|
+
`DataTable` supports infinite scroll via `onFetchMore` + `hasMore` (IntersectionObserver sentinel row at the bottom, with a 200px look-ahead). Row virtualization is a **separate, explicit opt-in** via the `virtualizeRows` prop. Unlike `DataCombobox`, `DataTable` has no `'auto'` mode: `virtualizeRows` is a plain boolean and is off unless you pass it.
|
|
4
|
+
|
|
5
|
+
`fillHeight` makes the table fill its parent and scroll its body inside, with a sticky header. The parent must supply a bounded height (a `flex flex-col` parent with `min-h-0`/fixed height). Without a bounded parent it has no effect. `onFetchMore` works with or without `fillHeight`, but inside a page that scrolls the sentinel is measured against the viewport, so for a list page use `fillHeight`.
|
|
6
|
+
|
|
7
|
+
`virtualizeRows` **requires `fillHeight`** — the container must scroll internally so the virtualizer can track `scrollTop`. Without `fillHeight` it is ignored (the page scrolls instead and the virtual window never updates).
|
|
8
|
+
|
|
9
|
+
Use `virtualizeRows` on any table with 1 000+ rows: infinite-scroll tables that accumulate pages, or static datasets loaded all at once.
|
|
10
|
+
|
|
11
|
+
**Virtualization needs no sizing setup.** Column widths are resolved from the column defs in every mode, so turning it on does not change the widths (the old "implies `fixedLayout`, columns fall back to 150px" behaviour is gone, and `fixedLayout` is a deprecated no-op). Follow the usual width rule instead: `size` for columns with a known width, none (or `minSize`/`flex`) for the rest.
|
|
12
|
+
|
|
13
|
+
```tsx
|
|
14
|
+
// Infinite scroll with virtualization
|
|
15
|
+
function CallsTable() {
|
|
16
|
+
const [items, setItems] = React.useState<Call[]>(() => fetchPage(0));
|
|
17
|
+
const [isFetchingMore, setIsFetchingMore] = React.useState(false);
|
|
18
|
+
const hasMore = items.length < totalCount;
|
|
19
|
+
|
|
20
|
+
const onFetchMore = React.useCallback(() => {
|
|
21
|
+
if (isFetchingMore || !hasMore) return;
|
|
22
|
+
setIsFetchingMore(true);
|
|
23
|
+
fetchPage(items.length).then(page => {
|
|
24
|
+
setItems(prev => [...prev, ...page]);
|
|
25
|
+
setIsFetchingMore(false);
|
|
26
|
+
});
|
|
27
|
+
}, [isFetchingMore, hasMore, items.length]);
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
<div className="flex h-dvh flex-col p-4">
|
|
31
|
+
<DataTable
|
|
32
|
+
columns={columns}
|
|
33
|
+
data={items}
|
|
34
|
+
getRowId={row => row.id}
|
|
35
|
+
fillHeight
|
|
36
|
+
virtualizeRows
|
|
37
|
+
onFetchMore={onFetchMore}
|
|
38
|
+
hasMore={hasMore}
|
|
39
|
+
loadingState={isFetchingMore ? 'loadingMore' : 'idle'}
|
|
40
|
+
/>
|
|
41
|
+
</div>
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
- `onFetchMore` fires once per intersection and re-arms when `data` changes length. Guard against double fetches with your own `isFetchingMore` flag, as above; while `loadingState` is `'loadingMore'` the sentinel is replaced by a spinner row.
|
|
47
|
+
- Selection keys persist across pages as long as `getRowId` returns stable ids.
|
|
48
|
+
|
|
49
|
+
**Pagination does not need virtualization.** With pagination you replace `data` on each page change — the row count stays constant. Do not pass `onFetchMore`; use an external `<Pagination>` component instead.
|
|
50
|
+
|
|
51
|
+
Source: `packages/ds/src/components/data-table.tsx`, `packages/ds/src/stories/DataTable.stories.tsx` (`VirtualizedInfiniteScroll`, `InfiniteScroll`)
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
## Row actions column
|
|
2
|
+
|
|
3
|
+
Tractor's `rowActions` / `rowActionsType` become an ordinary trailing column. Use a static `size` and keep it unresizable:
|
|
4
|
+
|
|
5
|
+
```tsx
|
|
6
|
+
import { Button, DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger } from '@aircall/ds';
|
|
7
|
+
import { EllipsisVertical } from '@aircall/react-icons';
|
|
8
|
+
|
|
9
|
+
const actionsColumn: ColumnDef<Person> = {
|
|
10
|
+
id: 'actions',
|
|
11
|
+
header: '',
|
|
12
|
+
size: 40,
|
|
13
|
+
enableResizing: false,
|
|
14
|
+
cell: ({ row }) => (
|
|
15
|
+
// DataTable only guards its own checkbox: stop the click so opening the menu does not fire onRowClick
|
|
16
|
+
<div onClick={e => e.stopPropagation()}>
|
|
17
|
+
<DropdownMenu>
|
|
18
|
+
<DropdownMenuTrigger
|
|
19
|
+
render={<Button variant="ghost" size="icon-sm" aria-label={`Actions for ${row.original.firstName}`} />}
|
|
20
|
+
>
|
|
21
|
+
<EllipsisVertical />
|
|
22
|
+
</DropdownMenuTrigger>
|
|
23
|
+
<DropdownMenuContent align="end">
|
|
24
|
+
<DropdownMenuItem>Edit</DropdownMenuItem>
|
|
25
|
+
<DropdownMenuSeparator />
|
|
26
|
+
<DropdownMenuItem variant="destructive">Delete</DropdownMenuItem>
|
|
27
|
+
</DropdownMenuContent>
|
|
28
|
+
</DropdownMenu>
|
|
29
|
+
</div>
|
|
30
|
+
)
|
|
31
|
+
};
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Every body row has a named hover group (`group/row`), so a cell that reveals itself on hover or focus can use `group-hover/row:` and `group-focus-within/row:`. See `aircall-ds/migrate-tractor/dropdown-menu` for the menu parts.
|