@aircall/ds 0.34.0 → 0.35.0

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.
@@ -47,8 +47,9 @@ Controlled by the `data-theme` attribute on a root element:
47
47
  ## Peer dependencies
48
48
 
49
49
  Required: `react`, `react-dom`, `@aircall/react-icons`, `@aircall/numbers`.
50
- Install only if you use the component: `react-day-picker` + `date-fns` (Calendar),
51
- `@tanstack/react-table` (DataTable).
50
+ Install only if you use the component: `react-day-picker` + `date-fns` (Calendar).
51
+ `@tanstack/react-table` (DataTable) is a regular dependency — it installs automatically,
52
+ nothing to add yourself.
52
53
 
53
54
  ## When unsure about an API
54
55
 
package/README.md CHANGED
@@ -85,17 +85,13 @@ pnpm add react react-dom @aircall/react-icons @aircall/numbers
85
85
  | Component | Packages to install |
86
86
  |-----------|-------------------|
87
87
  | `Calendar` | `react-day-picker`, `date-fns` |
88
- | `DataTable` | `@tanstack/react-table` |
89
88
 
90
89
  ```bash
91
90
  # If using Calendar
92
91
  pnpm add react-day-picker date-fns
93
-
94
- # If using DataTable
95
- pnpm add @tanstack/react-table
96
92
  ```
97
93
 
98
- > The package is published with its module graph preserved (`tsdown` `unbundle`) and is marked `sideEffects: ["**/*.css"]`, so these peers are only pulled into a consumer's bundle when `Calendar` / `DataTable` are actually imported. Importing other components (e.g. `Button`) tree-shakes them away — no install required.
94
+ > The package is published with its module graph preserved (`tsdown` `unbundle`) and is marked `sideEffects: ["**/*.css"]`, so `Calendar`'s peers are only pulled into a consumer's bundle when `Calendar` is actually imported. Importing other components (e.g. `Button`) tree-shakes them away — no install required. `DataTable`'s `@tanstack/react-table` runtime is a regular `@aircall/ds` dependency instead — it installs automatically, nothing to add yourself.
99
95
 
100
96
  ## Usage
101
97
 
@@ -0,0 +1,179 @@
1
+ import * as React from "react";
2
+ import { ColumnDef, OnChangeFn, RowData, SortingState } from "@tanstack/react-table";
3
+ //#region src/components/data-table.d.ts
4
+ declare module '@tanstack/react-table' {
5
+ interface ColumnMeta<TData extends RowData, TValue> {
6
+ /**
7
+ * Stick this column to the left or right edge while the table scrolls
8
+ * horizontally. Implies fixed column widths (`table-layout: fixed`); set an
9
+ * explicit `size` on pinned columns. When any column is pinned and selection
10
+ * is enabled, the built-in selection column is also auto-pinned to the left.
11
+ */
12
+ pin?: 'left' | 'right';
13
+ }
14
+ }
15
+ /**
16
+ * Column definition for `DataTable`. A bound alias of TanStack Table's own
17
+ * `ColumnDef`, owned by `@aircall/ds` — author against this type (not
18
+ * `@tanstack/react-table` directly), since `@tanstack/react-table` is a
19
+ * regular `@aircall/ds` dependency and not part of your own install.
20
+ */
21
+ type ColumnDef$1<TData extends RowData, TValue = unknown> = ColumnDef<TData, TValue>;
22
+ /** Sorting state for `DataTable`'s `sorting` / `onSortingChange` props. Bound alias of TanStack Table's `SortingState`. */
23
+ type SortingState$1 = SortingState;
24
+ /** Change handler used by `DataTable`'s controlled props (e.g. `onSortingChange`). Bound alias of TanStack Table's `OnChangeFn`. */
25
+ type OnChangeFn$1<TState> = OnChangeFn<TState>;
26
+ /** Async states a `DataTable` can be in (mirrors React Spectrum's `loadingState`). */
27
+ type DataTableLoadingState = 'idle' | 'loading' | 'sorting' | 'filtering' | 'loadingMore';
28
+ interface DataTableProps<TData> {
29
+ /**
30
+ * Column definitions for the table. Define a column's `footer` to render a
31
+ * summary row — the table auto-shows a `<tfoot>` when any column has one, with
32
+ * footer cells aligned under their columns.
33
+ *
34
+ * Pin a column while scrolling horizontally with `meta: { pin: 'left' | 'right' }`.
35
+ * Pinned columns imply fixed widths — set an explicit `size` on each.
36
+ */
37
+ columns: ColumnDef$1<TData, unknown>[];
38
+ /** Data array to render. With server-side sorting/pagination, this is the already-prepared page. */
39
+ data: TData[];
40
+ /** Stable row id resolver. Required for selection to persist across data changes. */
41
+ getRowId?: (row: TData, index: number) => string;
42
+ /**
43
+ * The table's async state (mirrors React Spectrum's single `loadingState`):
44
+ * - `'loading'` — initial load with no data yet; the body shows skeleton rows.
45
+ * - `'sorting'` / `'filtering'` — re-querying an already-loaded table; the
46
+ * current rows stay in place under a dimmed overlay with a spinner.
47
+ * - `'loadingMore'` — fetching the next page for infinite scroll; a spinner
48
+ * row renders at the bottom.
49
+ * Omit (or `'idle'`) when not loading.
50
+ */
51
+ loadingState?: DataTableLoadingState;
52
+ /** Number of skeleton rows when `loadingState` is `'loading'`. */
53
+ skeletonCount?: number;
54
+ /**
55
+ * Rendered when there are no rows and not loading. Provide an `<Empty>`
56
+ * component (icon, copy, actions) — render different content based on context
57
+ * (no data vs. no search results). Nothing is shown when omitted.
58
+ */
59
+ emptyState?: React.ReactNode;
60
+ /** Controlled sorting state. Pass alongside `onSortingChange` to enable sortable headers. */
61
+ sorting?: SortingState$1;
62
+ /** Called when the user toggles a sortable header. */
63
+ onSortingChange?: OnChangeFn$1<SortingState$1>;
64
+ /**
65
+ * Enables interactive column resizing. Each resizable header gets a drag
66
+ * handle on its right edge; column widths come from each column's `size`
67
+ * (and are bounded by `minSize`/`maxSize`). Set `enableResizing: false` on a
68
+ * column def to pin it (e.g. an actions column).
69
+ */
70
+ enableColumnResizing?: boolean;
71
+ /**
72
+ * The type of selection allowed (mirrors React Spectrum's `selectionMode`):
73
+ * - `'none'` — selection off; no checkbox column (default).
74
+ * - `'single'` — one row at a time; a checkbox column is prepended with no
75
+ * select-all header, and selecting a row clears any other.
76
+ * - `'multiple'` — many rows; the checkbox column gets a select-all header.
77
+ *
78
+ * Selection keys are the values returned by `getRowId` (its index when
79
+ * `getRowId` is omitted), matching React Spectrum's key-based model.
80
+ */
81
+ selectionMode?: 'none' | 'single' | 'multiple';
82
+ /**
83
+ * Controlled set of selected row ids. Pass alongside `onSelectionChange`. For
84
+ * uncontrolled selection, use `defaultSelectedKeys` instead (or neither).
85
+ */
86
+ selectedKeys?: Set<string>;
87
+ /**
88
+ * Initial selected row ids for uncontrolled selection (mirrors React
89
+ * Spectrum's `defaultSelectedKeys`). Ignored when `selectedKeys` is provided.
90
+ */
91
+ defaultSelectedKeys?: Set<string>;
92
+ /** Called with the new set of selected row ids whenever selection changes. */
93
+ onSelectionChange?: (keys: Set<string>) => void;
94
+ /** Row ids that cannot be selected (mirrors React Spectrum's `disabledKeys`). */
95
+ disabledKeys?: Set<string>;
96
+ /**
97
+ * How `disabledKeys` rows behave (mirrors React Spectrum's `disabledBehavior`):
98
+ * - `'all'` — fully disabled: no checkbox, the row is dimmed and does not
99
+ * respond to clicks/`onRowClick` (default).
100
+ * - `'selection'` — disabled for selection only: no checkbox, but the row is
101
+ * not dimmed and still fires `onRowClick`.
102
+ */
103
+ disabledBehavior?: 'selection' | 'all';
104
+ /** Bar rendered floating at the bottom while there is at least one selected row. */
105
+ actionBar?: React.ReactNode;
106
+ /** Called when the user scrolls near the bottom; use to fetch the next page. */
107
+ onFetchMore?: () => void;
108
+ /** Whether more pages are available. */
109
+ hasMore?: boolean;
110
+ /**
111
+ * Called when a data row is activated by click. With row selection enabled,
112
+ * this fires only while nothing is selected — once there is a selection, a row
113
+ * click toggles that row instead (the "click anywhere to select" pattern, as in
114
+ * React Spectrum). Clicks on the selection checkbox never fire this.
115
+ */
116
+ onRowClick?: (row: TData) => void;
117
+ /**
118
+ * Fills the parent's height and scrolls the table body internally, keeping
119
+ * the header pinned (sticky). The parent must provide a bounded height — e.g.
120
+ * a flex column (`flex flex-col` + `min-h-0`). Common for full-page lists.
121
+ *
122
+ * Required when using `virtualizeRows` — the virtualizer tracks `scrollTop` on
123
+ * this container; without it the page scrolls and virtualization has no effect.
124
+ */
125
+ fillHeight?: boolean;
126
+ /**
127
+ * Enables row virtualization via `@tanstack/react-virtual` — only visible rows
128
+ * are rendered, keeping DOM size constant for large datasets (1 000+ rows).
129
+ * Works independently of `onFetchMore`: use it for infinite-scroll tables that
130
+ * accumulate many pages, or for any static dataset with 1 000+ rows.
131
+ *
132
+ * Requires `fillHeight={true}` — the container must scroll internally so the
133
+ * virtualizer can track scroll position. Without it, `scrollTop` stays 0 and
134
+ * virtualization has no effect.
135
+ *
136
+ * Implies `fixedLayout` (`table-layout: fixed`): the virtualizer needs stable
137
+ * column widths, so every column takes its `size` instead of sizing to
138
+ * content. Columns with no `size` fall back to TanStack's 150px default — so
139
+ * a content-sized table (e.g. a narrow icon column) will visibly snap to
140
+ * 150px when you enable this. Set an explicit `size` on each column def to
141
+ * preserve the intended widths.
142
+ */
143
+ virtualizeRows?: boolean;
144
+ /**
145
+ * Uses a fixed table layout (`table-layout: fixed`): column widths come from
146
+ * each column's `size` (defaulting to 150) instead of the widest cell, so the
147
+ * layout stays stable as different-length content loads. Long cell content
148
+ * should be truncated by the cell (e.g. a `truncate` wrapper).
149
+ *
150
+ * This is width-pinning WITHOUT interactivity — unlike `enableColumnResizing`
151
+ * it adds no drag handles, and unlike `virtualizeRows` it needs no
152
+ * `fillHeight`. Use it for content-stable lists where columns shouldn't
153
+ * reflow. (`enableColumnResizing`, `virtualizeRows`, and column pinning via
154
+ * `meta.pin` imply this too.)
155
+ */
156
+ fixedLayout?: boolean;
157
+ className?: string;
158
+ }
159
+ /**
160
+ * Data grid built on TanStack Table. Renders a `<div>` wrapper around a DS
161
+ * `<Table>` (`<table>`), driven by `columns` + `data`, with opt-in sorting,
162
+ * row selection, column resizing, column pinning (`meta.pin`), virtualization,
163
+ * infinite scroll, a floating action bar, and loading/empty states.
164
+ *
165
+ * @example
166
+ * ```tsx
167
+ * <DataTable
168
+ * columns={columns}
169
+ * data={rows}
170
+ * getRowId={row => row.id}
171
+ * />
172
+ * ```
173
+ */
174
+ declare function DataTable<TData>(componentProps: DataTable.Props<TData>): React.JSX.Element;
175
+ declare namespace DataTable {
176
+ type Props<TData> = DataTableProps<TData>;
177
+ }
178
+ //#endregion
179
+ export { SortingState$1 as a, OnChangeFn$1 as i, DataTable as n, DataTableLoadingState as r, ColumnDef$1 as t };