@wonderflow/react-components 14.5.0 → 15.0.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.
Files changed (35) hide show
  1. package/dist/components/table/table-cell/index.d.ts +1 -1
  2. package/dist/components/table/table-cell/index.d.ts.map +1 -1
  3. package/dist/components/table/table-cell/index.js +2 -2
  4. package/dist/components/table/table-cell/table-cell.d.ts +1 -0
  5. package/dist/components/table/table-cell/table-cell.d.ts.map +1 -1
  6. package/dist/components/table/table-cell/table-cell.js +3 -2
  7. package/dist/components/table/table-checkbox/table-checkbox.module.css +1 -1
  8. package/dist/components/table/table-controls/table-controls.test.js +10 -9
  9. package/dist/components/table/table-controls/toggle-columns.js +7 -7
  10. package/dist/components/table/table-row/index.d.ts +1 -1
  11. package/dist/components/table/table-row/index.d.ts.map +1 -1
  12. package/dist/components/table/table-row/index.js +2 -2
  13. package/dist/components/table/table-row/table-row.d.ts +14 -3
  14. package/dist/components/table/table-row/table-row.d.ts.map +1 -1
  15. package/dist/components/table/table-row/table-row.js +29 -22
  16. package/dist/components/table/table-row/table-row.test.js +1 -1
  17. package/dist/components/table/table.d.ts +25 -4
  18. package/dist/components/table/table.d.ts.map +1 -1
  19. package/dist/components/table/table.js +177 -92
  20. package/dist/components/table/table.stories.d.ts +17 -16
  21. package/dist/components/table/table.stories.d.ts.map +1 -1
  22. package/dist/components/table/table.stories.js +20 -0
  23. package/dist/components/table/table.test.d.ts +1 -1
  24. package/dist/components/table/table.test.d.ts.map +1 -1
  25. package/dist/components/table/table.test.js +197 -1
  26. package/dist/components/table/to-tanstack-columns.d.ts +4 -0
  27. package/dist/components/table/to-tanstack-columns.d.ts.map +1 -0
  28. package/dist/components/table/to-tanstack-columns.js +62 -0
  29. package/dist/components/table/to-tanstack-columns.test.d.ts +2 -0
  30. package/dist/components/table/to-tanstack-columns.test.d.ts.map +1 -0
  31. package/dist/components/table/to-tanstack-columns.test.js +93 -0
  32. package/dist/components/table/types.d.ts +55 -5
  33. package/dist/components/table/types.d.ts.map +1 -1
  34. package/dist/components/table/types.js +1 -1
  35. package/package.json +5 -6
@@ -1,5 +1,6 @@
1
1
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { render } from '@testing-library/react';
2
+ import '@testing-library/jest-dom';
3
+ import { fireEvent, render, screen } from '@testing-library/react';
3
4
  import { Table } from './table';
4
5
  const DATA = [
5
6
  {
@@ -44,4 +45,199 @@ describe('<Table>', () => {
44
45
  const { container } = render(_jsxs(_Fragment, { children: [_jsx(Table, { title: "Table", columns: COLUMNS, data: DATA, expandableRowComponent: subRow => (_jsx("div", { children: JSON.stringify(subRow, null, 2) })), showHeader: true, showPagination: true, isManualSorted: true }), _jsx(Table, { title: "Table", columns: COLUMNS, data: [] }), ","] }));
45
46
  expect(container).not.toBeNull();
46
47
  });
48
+ describe('row selection', () => {
49
+ test('checking a row and the "select all" checkbox notify onSelectedRowsChange', () => {
50
+ const onSelectedRowsChange = jest.fn();
51
+ render(_jsx(Table, { columns: COLUMNS, data: DATA, selectableRows: true, onSelectedRowsChange: onSelectedRowsChange }));
52
+ // index 0 is the header "select all" checkbox, followed by one per row
53
+ const checkboxes = screen.getAllByRole('checkbox');
54
+ expect(checkboxes).toHaveLength(DATA.length + 1);
55
+ fireEvent.click(checkboxes[1]);
56
+ expect(onSelectedRowsChange).toHaveBeenLastCalledWith(expect.arrayContaining([expect.any(String)]));
57
+ expect(onSelectedRowsChange.mock.calls.at(-1)?.[0]).toHaveLength(1);
58
+ fireEvent.click(checkboxes[0]);
59
+ expect(onSelectedRowsChange.mock.calls.at(-1)?.[0]).toHaveLength(DATA.length);
60
+ });
61
+ test('a data change clears the selection by default, but not with persistSelectionAcrossPages', () => {
62
+ const defaultRun = render(_jsx(Table, { columns: COLUMNS, data: DATA, selectableRows: true, selectedRowIds: ['1'] }));
63
+ expect(screen.getAllByRole('checkbox')[2]).toBeChecked();
64
+ defaultRun.rerender(_jsx(Table, { columns: COLUMNS, data: [...DATA], selectableRows: true, selectedRowIds: ['1'] }));
65
+ expect(screen.getAllByRole('checkbox')[2]).not.toBeChecked();
66
+ defaultRun.unmount();
67
+ const persistedRun = render(_jsx(Table, { columns: COLUMNS, data: DATA, selectableRows: true, persistSelectionAcrossPages: true, selectedRowIds: ['1'] }));
68
+ expect(screen.getAllByRole('checkbox')[2]).toBeChecked();
69
+ persistedRun.rerender(_jsx(Table, { columns: COLUMNS, data: [...DATA], selectableRows: true, persistSelectionAcrossPages: true, selectedRowIds: ['1'] }));
70
+ expect(screen.getAllByRole('checkbox')[2]).toBeChecked();
71
+ });
72
+ });
73
+ describe('sorting', () => {
74
+ test('clicking a sortable column header notifies onSortChange', () => {
75
+ const onSortChange = jest.fn();
76
+ render(_jsx(Table, { columns: COLUMNS, data: DATA, onSortChange: onSortChange }));
77
+ fireEvent.click(screen.getByText('Letter'));
78
+ expect(onSortChange).toHaveBeenCalledWith([{ id: 'letter', desc: false }]);
79
+ });
80
+ });
81
+ describe('column visibility', () => {
82
+ test('hiding a column removes its header and cells from the rendered rows, not just the header', () => {
83
+ const { rerender } = render(_jsx(Table, { title: "Table", columns: COLUMNS, data: DATA }));
84
+ expect(screen.getByText('Letter')).toBeInTheDocument();
85
+ expect(screen.getByText('A')).toBeInTheDocument();
86
+ rerender(_jsx(Table, { title: "Table", columns: COLUMNS, data: DATA, defaultHiddenColumns: ['letter'] }));
87
+ expect(screen.queryByText('Letter')).not.toBeInTheDocument();
88
+ expect(screen.queryByText('A')).not.toBeInTheDocument();
89
+ expect(screen.getByText('1')).toBeInTheDocument();
90
+ rerender(_jsx(Table, { title: "Table", columns: COLUMNS, data: DATA }));
91
+ expect(screen.getByText('Letter')).toBeInTheDocument();
92
+ expect(screen.getByText('A')).toBeInTheDocument();
93
+ });
94
+ });
95
+ describe('expandable rows', () => {
96
+ test('toggling an expandable row renders the custom expand content', () => {
97
+ const dataWithSubRows = [
98
+ { id: 1, letter: 'A', subRows: [{ id: '1.1', letter: 'A.1' }] },
99
+ ];
100
+ render(_jsx(Table, { columns: COLUMNS, data: dataWithSubRows, expandableRowComponent: subRow => _jsx("div", { children: subRow.letter }) }));
101
+ expect(screen.queryByText('A.1')).not.toBeInTheDocument();
102
+ fireEvent.click(screen.getByTestId('ToggleButton'));
103
+ expect(screen.getByText('A.1')).toBeInTheDocument();
104
+ });
105
+ });
106
+ describe('pagination', () => {
107
+ test('showPagination paginates client-side using itemsPerPage and initialPageIndex', () => {
108
+ render(_jsx(Table, { columns: COLUMNS, data: DATA, showPagination: true, itemsPerPage: 2, initialPageIndex: 1 }));
109
+ // page index 1 with 2 items per page shows rows 3 and 4 (C, D)
110
+ expect(screen.getByText('C')).toBeInTheDocument();
111
+ expect(screen.getByText('D')).toBeInTheDocument();
112
+ expect(screen.queryByText('A')).not.toBeInTheDocument();
113
+ expect(screen.queryByText('E')).not.toBeInTheDocument();
114
+ });
115
+ test('manual pagination defers to onPaginationChange instead of paginating client-side', () => {
116
+ const onPaginationChange = jest.fn();
117
+ render(_jsx(Table, { columns: COLUMNS, data: DATA.slice(0, 2), showPagination: true, itemsPerPage: 2, totalRows: DATA.length, onPaginationChange: onPaginationChange }));
118
+ // manual pagination: only the rows explicitly passed in `data` are rendered
119
+ expect(screen.getByText('A')).toBeInTheDocument();
120
+ expect(screen.getByText('B')).toBeInTheDocument();
121
+ expect(screen.queryByText('C')).not.toBeInTheDocument();
122
+ fireEvent.click(screen.getByTestId('RightChevron'));
123
+ expect(onPaginationChange).toHaveBeenLastCalledWith({ pageIndex: 1, pageSize: 2 });
124
+ });
125
+ });
126
+ describe('showTableHead', () => {
127
+ test('showTableHead={false} hides column headers but still renders cell data', () => {
128
+ render(_jsx(Table, { columns: COLUMNS, data: DATA, showTableHead: false }));
129
+ expect(screen.queryByText('Letter')).not.toBeInTheDocument();
130
+ expect(screen.getByText('A')).toBeInTheDocument();
131
+ });
132
+ });
133
+ describe('emptyComponent', () => {
134
+ test('renders the custom empty component when there is no data', () => {
135
+ render(_jsx(Table, { columns: COLUMNS, data: [], emptyComponent: _jsx("div", { children: "Nothing here" }) }));
136
+ expect(screen.getByText('Nothing here')).toBeInTheDocument();
137
+ });
138
+ test('falls back to the default "No data" message', () => {
139
+ render(_jsx(Table, { columns: COLUMNS, data: [] }));
140
+ expect(screen.getByText('No data')).toBeInTheDocument();
141
+ });
142
+ });
143
+ describe('manual sorting', () => {
144
+ test('isManualSorted still notifies onSortChange but leaves row order untouched', () => {
145
+ const onSortChange = jest.fn();
146
+ render(_jsx(Table, { columns: COLUMNS, data: DATA, isManualSorted: true, onSortChange: onSortChange }));
147
+ fireEvent.click(screen.getByText('Letter'));
148
+ expect(onSortChange).toHaveBeenCalledWith([{ id: 'letter', desc: false }]);
149
+ // row order in the DOM is unchanged since sorting is delegated to the consumer
150
+ const cells = screen.getAllByText(/^[A-F]$/);
151
+ expect(cells.map(cell => cell.textContent)).toEqual(['A', 'B', 'C', 'D', 'E', 'F']);
152
+ });
153
+ });
154
+ describe('initialSortBy', () => {
155
+ test('applies the initial sort order on mount', () => {
156
+ render(_jsx(Table, { columns: COLUMNS, data: DATA, initialSortBy: [{ id: 'letter', desc: true }] }));
157
+ const cells = screen.getAllByText(/^[A-F]$/);
158
+ expect(cells[0]).toHaveTextContent('F');
159
+ });
160
+ });
161
+ describe('selectSubRows', () => {
162
+ test('selecting a parent row selects its sub rows by default', () => {
163
+ const onSelectedRowsChange = jest.fn();
164
+ const dataWithSubRows = [
165
+ {
166
+ _id: '1', id: 1, letter: 'A', subRows: [{ _id: '1.1', id: '1.1', letter: 'A.1' }],
167
+ },
168
+ ];
169
+ render(_jsx(Table, { columns: COLUMNS, data: dataWithSubRows, selectableRows: true, onSelectedRowsChange: onSelectedRowsChange }));
170
+ fireEvent.click(screen.getByTestId('ToggleButton'));
171
+ const checkboxes = screen.getAllByRole('checkbox');
172
+ fireEvent.click(checkboxes[1]);
173
+ expect(onSelectedRowsChange.mock.calls.at(-1)?.[0]).toEqual(expect.arrayContaining(['1', '1.1']));
174
+ });
175
+ test('selectSubRows={false} keeps parent and sub row selection independent', () => {
176
+ const onSelectedRowsChange = jest.fn();
177
+ const dataWithSubRows = [
178
+ {
179
+ _id: '1', id: 1, letter: 'A', subRows: [{ _id: '1.1', id: '1.1', letter: 'A.1' }],
180
+ },
181
+ ];
182
+ render(_jsx(Table, { columns: COLUMNS, data: dataWithSubRows, selectableRows: true, selectSubRows: false, onSelectedRowsChange: onSelectedRowsChange }));
183
+ fireEvent.click(screen.getByTestId('ToggleButton'));
184
+ const checkboxes = screen.getAllByRole('checkbox');
185
+ fireEvent.click(checkboxes[1]);
186
+ expect(onSelectedRowsChange.mock.calls.at(-1)?.[0]).toEqual(['1']);
187
+ });
188
+ });
189
+ describe('stripes and showSeparators', () => {
190
+ test('reflect as data attributes on the table element', () => {
191
+ const { container, rerender } = render(_jsx(Table, { columns: COLUMNS, data: DATA, stripes: true, showSeparators: false }));
192
+ const tableEl = container.querySelector('table');
193
+ expect(tableEl).toHaveAttribute('data-table-stripes', 'true');
194
+ expect(tableEl).toHaveAttribute('data-table-separators', 'false');
195
+ rerender(_jsx(Table, { columns: COLUMNS, data: DATA, stripes: false, showSeparators: true }));
196
+ expect(tableEl).toHaveAttribute('data-table-stripes', 'false');
197
+ expect(tableEl).toHaveAttribute('data-table-separators', 'true');
198
+ });
199
+ });
200
+ describe('loading', () => {
201
+ test('shows skeleton rows instead of data while loading', () => {
202
+ const { container } = render(_jsx(Table, { columns: COLUMNS, data: DATA, loading: true }));
203
+ expect(screen.queryByText('A')).not.toBeInTheDocument();
204
+ expect(container.querySelector('[aria-busy="true"]')).toBeInTheDocument();
205
+ });
206
+ });
207
+ describe('header', () => {
208
+ test('title and actions render inside the header when showHeader is true', () => {
209
+ render(_jsx(Table, { columns: COLUMNS, data: DATA, showHeader: true, title: "My table", actions: _jsx("button", { type: "button", children: "Custom action" }) }));
210
+ expect(screen.getByText('My table')).toBeInTheDocument();
211
+ expect(screen.getByText('Custom action')).toBeInTheDocument();
212
+ });
213
+ test('title is not rendered when showHeader is false', () => {
214
+ render(_jsx(Table, { columns: COLUMNS, data: DATA, title: "Hidden title" }));
215
+ expect(screen.queryByText('Hidden title')).not.toBeInTheDocument();
216
+ });
217
+ });
218
+ describe('selection labels and actions', () => {
219
+ test('selectedLabel and selectedActions render once a row is selected', () => {
220
+ render(_jsx(Table, { columns: COLUMNS, data: DATA, selectableRows: true, selectedLabel: ids => `Picked: ${ids.length}`, selectedActions: () => _jsx("button", { type: "button", children: "Bulk delete" }) }));
221
+ const checkboxes = screen.getAllByRole('checkbox');
222
+ fireEvent.click(checkboxes[1]);
223
+ expect(screen.getByText('Picked: 1')).toBeInTheDocument();
224
+ expect(screen.getByText('Bulk delete')).toBeInTheDocument();
225
+ });
226
+ test('defaults to "Selected items: N" when selectedLabel is not provided', () => {
227
+ render(_jsx(Table, { columns: COLUMNS, data: DATA, selectableRows: true }));
228
+ fireEvent.click(screen.getAllByRole('checkbox')[1]);
229
+ expect(screen.getByText('Selected items: 1')).toBeInTheDocument();
230
+ });
231
+ });
232
+ describe('height and background', () => {
233
+ test('set the scrolling wrapper and CSS custom properties', () => {
234
+ const { container } = render(_jsx(Table, { columns: COLUMNS, data: DATA, height: "400px", background: "white" }));
235
+ const wrapper = container.querySelector('[data-table-scrolling]');
236
+ expect(wrapper).toHaveAttribute('data-table-scrolling', 'true');
237
+ expect(wrapper?.parentElement).toHaveStyle({
238
+ '--table-height': '400px',
239
+ '--table-background': 'white',
240
+ });
241
+ });
242
+ });
47
243
  });
@@ -0,0 +1,4 @@
1
+ import { ColumnDef } from '@tanstack/react-table';
2
+ import { CustomColumnsType } from './types';
3
+ export declare const toTanStackColumns: <T extends Record<string, unknown>>(columns: CustomColumnsType<T>) => ColumnDef<T, unknown>[];
4
+ //# sourceMappingURL=to-tanstack-columns.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"to-tanstack-columns.d.ts","sourceRoot":"","sources":["../../../src/components/table/to-tanstack-columns.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAGlD,OAAO,EACL,iBAAiB,EAClB,MAAM,SAAS,CAAC;AA+DjB,eAAO,MAAM,iBAAiB,+FAE2C,CAAC"}
@@ -0,0 +1,62 @@
1
+ /*
2
+ * Copyright 2022-2026 Wonderflow Design Team
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ /**
17
+ * Converts a single public, `react-table` v7-shaped column definition
18
+ * (`id`/`Header`/`accessor`/`Cell`/`disableSortBy` plus our own
19
+ * `OptionalColumnTypes`) into a v8 `ColumnDef`. This is what lets every
20
+ * existing consumer keep defining `columns` exactly as before while
21
+ * `Table` runs on `@tanstack/react-table` internally.
22
+ */
23
+ const toTanStackColumn = (column) => {
24
+ const { id, Header, accessor, Cell, disableSortBy, isCollapsed, align, isToggable, expander, minWidth, } = column;
25
+ const meta = {
26
+ isCollapsed, align, isToggable, expander, minWidth,
27
+ };
28
+ // `Header`/`Cell` are almost always a plain `ReactNode` (or unset) in
29
+ // practice; the function form is only kept for source compatibility with
30
+ // consumers that relied on `react-table` v7's row/column-based render props.
31
+ const header = (typeof Header === 'function'
32
+ ? (ctx) => Header({ column: ctx.column })
33
+ : Header);
34
+ const cell = Cell
35
+ ? ctx => Cell({ row: ctx.row, value: ctx.getValue() })
36
+ : ctx => ctx.getValue();
37
+ const shared = {
38
+ id,
39
+ header,
40
+ cell,
41
+ enableSorting: !disableSortBy,
42
+ meta,
43
+ };
44
+ // `shared` covers fields common to every `ColumnDef` variant; which
45
+ // concrete variant applies (accessor-fn/accessor-key/display-only) is
46
+ // only known at runtime, so TypeScript can't narrow the union for us here.
47
+ if (typeof accessor === 'function') {
48
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
49
+ return { ...shared, accessorFn: accessor };
50
+ }
51
+ if (typeof accessor === 'string') {
52
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
53
+ return {
54
+ ...shared,
55
+ id: id ?? accessor,
56
+ accessorKey: accessor,
57
+ };
58
+ }
59
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
60
+ return shared;
61
+ };
62
+ export const toTanStackColumns = (columns) => columns.map(column => toTanStackColumn(column));
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=to-tanstack-columns.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"to-tanstack-columns.test.d.ts","sourceRoot":"","sources":["../../../src/components/table/to-tanstack-columns.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,93 @@
1
+ import { toTanStackColumns } from './to-tanstack-columns';
2
+ describe('toTanStackColumns()', () => {
3
+ it('should map id, header and string accessor to accessorKey', () => {
4
+ const columns = [
5
+ { id: 'name', Header: 'Name', accessor: 'name' },
6
+ ];
7
+ const [result] = toTanStackColumns(columns);
8
+ expect(result.id).toBe('name');
9
+ expect(result.header).toBe('Name');
10
+ expect(result).toHaveProperty('accessorKey', 'name');
11
+ });
12
+ it('should fall back to accessor as id when id is not provided', () => {
13
+ const columns = [
14
+ { accessor: 'age' },
15
+ ];
16
+ const [result] = toTanStackColumns(columns);
17
+ expect(result.id).toBe('age');
18
+ });
19
+ it('should map function accessor to accessorFn', () => {
20
+ const accessor = (row) => row.age;
21
+ const columns = [
22
+ { id: 'ageDoubled', accessor },
23
+ ];
24
+ const [result] = toTanStackColumns(columns);
25
+ expect(result).toHaveProperty('accessorFn', accessor);
26
+ });
27
+ it('should support display-only columns without an accessor', () => {
28
+ const columns = [
29
+ { id: 'actions', Header: 'Actions' },
30
+ ];
31
+ const [result] = toTanStackColumns(columns);
32
+ expect(result.id).toBe('actions');
33
+ expect(result).not.toHaveProperty('accessorKey');
34
+ expect(result).not.toHaveProperty('accessorFn');
35
+ });
36
+ it('should enable sorting by default and disable it when disableSortBy is true', () => {
37
+ const columns = [
38
+ { id: 'name', accessor: 'name' },
39
+ { id: 'age', accessor: 'age', disableSortBy: true },
40
+ ];
41
+ const [sortable, notSortable] = toTanStackColumns(columns);
42
+ expect(sortable.enableSorting).toBe(true);
43
+ expect(notSortable.enableSorting).toBe(false);
44
+ });
45
+ it('should thread optional column fields through meta', () => {
46
+ const columns = [
47
+ {
48
+ id: 'name', accessor: 'name', align: 'center', isCollapsed: true, isToggable: true, minWidth: 120,
49
+ },
50
+ ];
51
+ const [result] = toTanStackColumns(columns);
52
+ expect(result.meta).toEqual({
53
+ isCollapsed: true,
54
+ align: 'center',
55
+ isToggable: true,
56
+ expander: undefined,
57
+ minWidth: 120,
58
+ });
59
+ });
60
+ it('should render function Header with the column instance', () => {
61
+ const Header = jest.fn(() => 'Rendered Header');
62
+ const columns = [
63
+ { id: 'name', accessor: 'name', Header },
64
+ ];
65
+ const [result] = toTanStackColumns(columns);
66
+ const header = result.header;
67
+ const fakeColumn = { id: 'name' };
68
+ const output = header({ column: fakeColumn });
69
+ expect(Header).toHaveBeenCalledWith({ column: fakeColumn });
70
+ expect(output).toBe('Rendered Header');
71
+ });
72
+ it('should render Cell with row and value from the resolved cell context', () => {
73
+ const Cell = jest.fn(({ value }) => `Age: ${value}`);
74
+ const columns = [
75
+ { id: 'age', accessor: 'age', Cell },
76
+ ];
77
+ const [result] = toTanStackColumns(columns);
78
+ const cell = result.cell;
79
+ const fakeRow = { id: '0' };
80
+ const fakeCtx = { row: fakeRow, getValue: () => 30 };
81
+ const output = cell(fakeCtx);
82
+ expect(Cell).toHaveBeenCalledWith({ row: fakeRow, value: 30 });
83
+ expect(output).toBe('Age: 30');
84
+ });
85
+ it('should default cell to the raw value when Cell is not provided', () => {
86
+ const columns = [
87
+ { id: 'name', accessor: 'name' },
88
+ ];
89
+ const [result] = toTanStackColumns(columns);
90
+ const cell = result.cell;
91
+ expect(cell({ getValue: () => 'John' })).toBe('John');
92
+ });
93
+ });
@@ -1,23 +1,73 @@
1
+ import { Cell, Column, Header } from '@tanstack/react-table';
1
2
  import { ReactNode } from 'react';
2
- import { Column, ColumnInstance, CustomCell, CustomHeaderGroup } from 'react-table';
3
+ /**
4
+ * Row/column ids are always plain strings (see `Table`'s `getRowId` prop,
5
+ * which defaults to `row._id`), the generic parameter is kept only for
6
+ * source-compatibility with the previous `react-table` v7-based `IdType<T>`.
7
+ */
8
+ export declare type IdType<T> = Extract<keyof T, string> | (string & Record<never, never>);
3
9
  export declare type PaginationPageType = {
4
10
  pageIndex: number;
5
11
  pageSize: number;
6
12
  };
13
+ /**
14
+ * Extra, design-system-only fields a column definition can carry, on top of
15
+ * the "core" fields (`id`/`Header`/`accessor`/`Cell`/`disableSortBy`) that
16
+ * map 1:1 to `@tanstack/react-table` primitives. These aren't part of
17
+ * TanStack's own `ColumnDef`, so `Table`'s column conversion shim
18
+ * (`to-tanstack-columns.ts`) threads them through `columnDef.meta` (see the
19
+ * `ColumnMeta` module augmentation in `types/tanstack-table.d.ts`) instead
20
+ * of setting them directly on the column/cell object.
21
+ */
7
22
  export declare type OptionalColumnTypes = {
8
23
  isCollapsed?: boolean;
9
24
  align?: 'start' | 'center' | 'end';
10
25
  isToggable?: boolean;
11
26
  expander?: boolean;
27
+ /**
28
+ * Pixel width used for the column's CSS `--width`. This is a plain
29
+ * design-system field (layout/CSS sizing), unrelated to TanStack's own
30
+ * `size`/`minSize` column-sizing feature, which is a different concept
31
+ * and only takes effect if the sizing feature/state is explicitly used
32
+ * (it isn't, here).
33
+ */
34
+ minWidth?: number;
12
35
  };
13
36
  export declare type OptionalDataTypes<T> = {
14
37
  subRows?: T[];
15
38
  actions?: ReactNode | ReactNode[];
16
39
  };
17
- export declare type HeaderGroupType<T extends Record<string, unknown>> = CustomHeaderGroup<T, OptionalColumnTypes>;
18
- export declare type CellType<T extends Record<string, unknown>> = CustomCell<T, OptionalColumnTypes>;
19
- export declare type CustomColumnsType<T extends Record<string, unknown>> = Array<Column<T> & OptionalColumnTypes>;
20
- export declare type CustomColumnInstanceType<T extends Record<string, unknown>> = ColumnInstance<T> & OptionalColumnTypes;
40
+ /**
41
+ * Render-prop signatures kept source-compatible with the previous
42
+ * `react-table` v7-based API: `Header`/`Cell` receive the row/column
43
+ * directly, rather than v8's context-object shape
44
+ * (`{ getValue(), row, column, table }`). `Table`'s column conversion shim
45
+ * (`to-tanstack-columns.ts`) adapts between the two.
46
+ */
47
+ export declare type HeaderRenderProps<T extends Record<string, unknown>> = {
48
+ column: CustomColumnInstanceType<T>;
49
+ };
50
+ export declare type CellRenderProps<T extends Record<string, unknown>> = {
51
+ row: import('@tanstack/react-table').Row<T>;
52
+ value: unknown;
53
+ };
54
+ export declare type CustomColumnType<T extends Record<string, unknown>> = OptionalColumnTypes & {
55
+ id?: string;
56
+ Header?: ReactNode | ((props: HeaderRenderProps<T>) => ReactNode);
57
+ accessor?: keyof T | ((row: T) => unknown);
58
+ Cell?: (props: CellRenderProps<T>) => ReactNode;
59
+ disableSortBy?: boolean;
60
+ };
61
+ export declare type CustomColumnsType<T extends Record<string, unknown>> = Array<CustomColumnType<T>>;
62
+ /**
63
+ * A resolved TanStack `Column`/`Header`/`Cell` instance. The
64
+ * `OptionalColumnTypes` fields set on the original column definition are
65
+ * available at runtime via `.columnDef.meta` (typed automatically through
66
+ * the `ColumnMeta` module augmentation in `types/tanstack-table.d.ts`).
67
+ */
68
+ export declare type CustomColumnInstanceType<T extends Record<string, unknown>> = Column<T>;
69
+ export declare type HeaderGroupType<T extends Record<string, unknown>> = Header<T, unknown>;
70
+ export declare type CellType<T extends Record<string, unknown>> = Cell<T, unknown>;
21
71
  export declare type CustomSortingRule<T> = {
22
72
  id: keyof T;
23
73
  desc?: boolean;
@@ -1 +1 @@
1
- {"version":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-2023 Wonderflow Design Team
2
+ * Copyright 2022-2026 Wonderflow Design Team
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wonderflow/react-components",
3
- "version": "14.5.0",
3
+ "version": "15.0.0",
4
4
  "description": "UI components from Wonderflow's Wanda design system",
5
5
  "author": "Wonderflow",
6
6
  "license": "Apache-2.0",
@@ -80,11 +80,10 @@
80
80
  "@storybook/theming": "6.5.16",
81
81
  "@types/react": "17.0.43",
82
82
  "@types/react-dom": "17.0.14",
83
- "@types/react-table": "7.7.20",
84
83
  "@types/react-test-renderer": "18.0.7",
85
- "@wonderflow/config": "14.5.0",
86
- "@wonderflow/tokens": "14.5.0",
87
- "@wonderflow/charts": "14.5.0",
84
+ "@wonderflow/config": "15.0.0",
85
+ "@wonderflow/tokens": "15.0.0",
86
+ "@wonderflow/charts": "15.0.0",
88
87
  "@types/uuid": "9.0.8",
89
88
  "babel-loader": "8.2.5",
90
89
  "cpy-cli": "3.1.1",
@@ -102,6 +101,7 @@
102
101
  },
103
102
  "dependencies": {
104
103
  "@radix-ui/react-tabs": "1.0.4",
104
+ "@tanstack/react-table": "8.21.3",
105
105
  "ahooks": "3.7.11",
106
106
  "clsx": "1.2.1",
107
107
  "constate": "3.3.2",
@@ -113,7 +113,6 @@
113
113
  "react-paginate": "8.2.0",
114
114
  "react-popper-tooltip": "4.4.2",
115
115
  "react-roving-tabindex": "3.2.0",
116
- "react-table": "7.8.0",
117
116
  "react-uid": "2.3.3",
118
117
  "slugify": "1.6.6",
119
118
  "type-fest": "3.0.0",