@tanstack/react-table 0.0.1-alpha.0 → 0.0.1-alpha.12

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 (97) hide show
  1. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js +112 -0
  2. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +1 -0
  3. package/build/cjs/aggregationTypes.js +130 -0
  4. package/build/cjs/aggregationTypes.js.map +1 -0
  5. package/build/cjs/core.js +493 -0
  6. package/build/cjs/core.js.map +1 -0
  7. package/build/cjs/createTable.js +103 -0
  8. package/build/cjs/createTable.js.map +1 -0
  9. package/build/cjs/features/Expanding.js +234 -0
  10. package/build/cjs/features/Expanding.js.map +1 -0
  11. package/build/cjs/features/Filters.js +396 -0
  12. package/build/cjs/features/Filters.js.map +1 -0
  13. package/build/cjs/features/Grouping.js +228 -0
  14. package/build/cjs/features/Grouping.js.map +1 -0
  15. package/build/cjs/features/Headers.js +483 -0
  16. package/build/cjs/features/Headers.js.map +1 -0
  17. package/build/cjs/features/Ordering.js +83 -0
  18. package/build/cjs/features/Ordering.js.map +1 -0
  19. package/build/cjs/features/Pinning.js +163 -0
  20. package/build/cjs/features/Pinning.js.map +1 -0
  21. package/build/cjs/features/Sorting.js +269 -0
  22. package/build/cjs/features/Sorting.js.map +1 -0
  23. package/build/cjs/features/Visibility.js +160 -0
  24. package/build/cjs/features/Visibility.js.map +1 -0
  25. package/build/cjs/filterTypes.js +172 -0
  26. package/build/cjs/filterTypes.js.map +1 -0
  27. package/build/cjs/index.js +30 -0
  28. package/build/cjs/index.js.map +1 -0
  29. package/build/cjs/sortTypes.js +121 -0
  30. package/build/cjs/sortTypes.js.map +1 -0
  31. package/build/cjs/utils/columnFilterRowsFn.js +130 -0
  32. package/build/cjs/utils/columnFilterRowsFn.js.map +1 -0
  33. package/build/cjs/utils/expandRowsFn.js +38 -0
  34. package/build/cjs/utils/expandRowsFn.js.map +1 -0
  35. package/build/cjs/utils/globalFilterRowsFn.js +100 -0
  36. package/build/cjs/utils/globalFilterRowsFn.js.map +1 -0
  37. package/build/cjs/utils/groupRowsFn.js +154 -0
  38. package/build/cjs/utils/groupRowsFn.js.map +1 -0
  39. package/build/cjs/utils/sortRowsFn.js +93 -0
  40. package/build/cjs/utils/sortRowsFn.js.map +1 -0
  41. package/build/cjs/utils.js +143 -0
  42. package/build/cjs/utils.js.map +1 -0
  43. package/build/esm/index.js +3389 -0
  44. package/build/esm/index.js.map +1 -0
  45. package/build/stats-html.html +2689 -0
  46. package/build/stats-react.json +703 -0
  47. package/build/types/aggregationTypes.d.ts +22 -0
  48. package/build/types/core.d.ts +122 -0
  49. package/build/types/createTable.d.ts +35 -0
  50. package/build/types/features/Expanding.d.ts +52 -0
  51. package/build/types/features/Filters.d.ts +93 -0
  52. package/build/types/features/Grouping.d.ts +82 -0
  53. package/build/types/features/Headers.d.ts +41 -0
  54. package/build/types/features/Ordering.d.ts +19 -0
  55. package/build/types/features/Pinning.d.ts +39 -0
  56. package/build/types/features/Sorting.d.ts +75 -0
  57. package/build/types/features/Visibility.d.ts +47 -0
  58. package/build/types/filterTypes.d.ts +50 -0
  59. package/build/types/index.d.ts +7 -0
  60. package/build/types/sortTypes.d.ts +17 -0
  61. package/build/types/types.d.ts +122 -0
  62. package/build/types/utils/columnFilterRowsFn.d.ts +2 -0
  63. package/build/types/utils/expandRowsFn.d.ts +2 -0
  64. package/build/types/utils/globalFilterRowsFn.d.ts +2 -0
  65. package/build/types/utils/groupRowsFn.d.ts +2 -0
  66. package/build/types/utils/sortRowsFn.d.ts +2 -0
  67. package/build/types/utils.d.ts +24 -0
  68. package/{dist/react-table.development.js → build/umd/index.development.js} +11 -1
  69. package/build/umd/index.development.js.map +1 -0
  70. package/{dist/react-table.production.min.js → build/umd/index.production.js} +11 -1
  71. package/build/umd/index.production.js.map +1 -0
  72. package/package.json +10 -92
  73. package/src/features/{withColumnResizing.ts → withColumnResizing.oldts} +0 -0
  74. package/src/features/{withPagination.ts → withPagination.oldts} +0 -0
  75. package/src/features/{withRowSelection.ts → withRowSelection.oldts} +0 -0
  76. package/dist/react-table.development.js.map +0 -1
  77. package/dist/react-table.production.min.js.map +0 -1
  78. package/lib/index.js +0 -65
  79. package/src/.DS_Store +0 -0
  80. package/src/features/notest/useAbsoluteLayout.test.js +0 -152
  81. package/src/features/notest/useBlockLayout.test.js +0 -158
  82. package/src/features/notest/useColumnOrder.test.js +0 -186
  83. package/src/features/notest/useExpanded.test.js +0 -125
  84. package/src/features/notest/useFilters.test.js +0 -393
  85. package/src/features/notest/useFiltersAndRowSelect.test.js +0 -256
  86. package/src/features/notest/useFlexLayout.test.js +0 -152
  87. package/src/features/notest/useGroupBy.test.js +0 -259
  88. package/src/features/notest/usePagination.test.js +0 -231
  89. package/src/features/notest/useResizeColumns.test.js +0 -229
  90. package/src/features/notest/useRowSelect.test.js +0 -250
  91. package/src/features/notest/useRowState.test.js +0 -178
  92. package/src/features/tests/Visibility.test.tsx +0 -225
  93. package/src/features/tests/__snapshots__/Visibility.test.tsx.snap +0 -390
  94. package/src/features/tests/withSorting.notest.tsx +0 -341
  95. package/src/test-utils/makeTestData.ts +0 -41
  96. package/src/tests/__snapshots__/core.test.tsx.snap +0 -148
  97. package/src/tests/core.test.tsx +0 -241
@@ -1,241 +0,0 @@
1
- import * as React from 'react'
2
-
3
- // import { renderHook } from '@testing-library/react-hooks'
4
- import * as RTL from '@testing-library/react'
5
- import { createTable } from 'react-table'
6
- import { act, renderHook } from '@testing-library/react-hooks'
7
-
8
- type Row = {
9
- firstName: string
10
- lastName: string
11
- age: number
12
- visits: number
13
- status: string
14
- progress: number
15
- }
16
-
17
- const table = createTable().RowType<Row>()
18
-
19
- const defaultData: Row[] = [
20
- {
21
- firstName: 'tanner',
22
- lastName: 'linsley',
23
- age: 29,
24
- visits: 100,
25
- status: 'In Relationship',
26
- progress: 50,
27
- },
28
- {
29
- firstName: 'derek',
30
- lastName: 'perkins',
31
- age: 40,
32
- visits: 40,
33
- status: 'Single',
34
- progress: 80,
35
- },
36
- {
37
- firstName: 'joe',
38
- lastName: 'bergevin',
39
- age: 45,
40
- visits: 20,
41
- status: 'Complicated',
42
- progress: 10,
43
- },
44
- ]
45
-
46
- const defaultColumns = table.createColumns([
47
- table.createGroup({
48
- header: 'Name',
49
- footer: props => props.column.id,
50
- columns: [
51
- table.createColumn('firstName', {
52
- cell: info => info.value,
53
- footer: props => props.column.id,
54
- }),
55
- table.createColumn(row => row.lastName, {
56
- id: 'lastName',
57
- cell: info => info.value,
58
- header: <span>Last Name</span>,
59
- footer: props => props.column.id,
60
- }),
61
- ],
62
- }),
63
- table.createGroup({
64
- header: 'Info',
65
- footer: props => props.column.id,
66
- columns: [
67
- table.createColumn('age', {
68
- header: () => 'Age',
69
- footer: props => props.column.id,
70
- }),
71
- table.createGroup({
72
- header: 'More Info',
73
- columns: [
74
- table.createColumn('visits', {
75
- header: () => <span>Visits</span>,
76
- footer: props => props.column.id,
77
- }),
78
- table.createColumn('status', {
79
- header: 'Status',
80
- footer: props => props.column.id,
81
- }),
82
- table.createColumn('progress', {
83
- header: 'Profile Progress',
84
- footer: props => props.column.id,
85
- }),
86
- ],
87
- }),
88
- ],
89
- }),
90
- ])
91
-
92
- describe('core', () => {
93
- it('renders a table with markup', () => {
94
- const Table = () => {
95
- const [data] = React.useState<Row[]>(() => [...defaultData])
96
- const [columns] = React.useState<typeof defaultColumns>(() => [
97
- ...defaultColumns,
98
- ])
99
- const [columnVisibility, setColumnVisibility] = React.useState({})
100
-
101
- const rerender = React.useReducer(() => ({}), {})[1]
102
-
103
- const instance = table.useTable({
104
- data,
105
- columns,
106
- onColumnVisibilityChange: setColumnVisibility,
107
- state: {
108
- columnVisibility,
109
- },
110
- // debug: true,
111
- })
112
-
113
- return (
114
- <div className="p-2">
115
- <table {...instance.getTableProps()}>
116
- <thead>
117
- {instance.getHeaderGroups().map(headerGroup => (
118
- <tr {...headerGroup.getHeaderGroupProps()}>
119
- {headerGroup.headers.map(header => (
120
- <th {...header.getHeaderProps()}>
121
- {header.isPlaceholder ? null : header.renderHeader()}
122
- </th>
123
- ))}
124
- </tr>
125
- ))}
126
- </thead>
127
- <tbody {...instance.getTableBodyProps()}>
128
- {instance.getRows().map(row => (
129
- <tr {...row.getRowProps()}>
130
- {row.getVisibleCells().map(cell => (
131
- <td {...cell.getCellProps()}>{cell.renderCell()}</td>
132
- ))}
133
- </tr>
134
- ))}
135
- </tbody>
136
- <tfoot>
137
- {instance.getFooterGroups().map(footerGroup => (
138
- <tr {...footerGroup.getFooterGroupProps()}>
139
- {footerGroup.headers.map(header => (
140
- <th {...header.getFooterProps()}>
141
- {header.isPlaceholder ? null : header.renderFooter()}
142
- </th>
143
- ))}
144
- </tr>
145
- ))}
146
- </tfoot>
147
- </table>
148
- <div className="h-4" />
149
- <button onClick={() => rerender()} className="border p-2">
150
- Rerender
151
- </button>
152
- </div>
153
- )
154
- }
155
-
156
- // let api: any;
157
-
158
- const rendered = RTL.render(<Table />)
159
-
160
- // RTL.screen.logTestingPlaygroundURL();
161
-
162
- RTL.screen.getByRole('table')
163
- expect(RTL.screen.getAllByRole('rowgroup').length).toEqual(3)
164
- expect(RTL.screen.getAllByRole('row').length).toEqual(9)
165
- expect(RTL.screen.getAllByRole('columnheader').length).toEqual(12)
166
- expect(RTL.screen.getAllByRole('columnfooter').length).toEqual(12)
167
- expect(RTL.screen.getAllByRole('gridcell').length).toEqual(18)
168
-
169
- expect(
170
- Array.from(rendered.container.querySelectorAll('thead > tr')).map(d =>
171
- Array.from(d.querySelectorAll('th')).map(d => [
172
- d.innerHTML,
173
- d.getAttribute('colspan'),
174
- ])
175
- )
176
- ).toMatchSnapshot()
177
-
178
- expect(
179
- Array.from(rendered.container.querySelectorAll('tbody > tr')).map(d =>
180
- Array.from(d.querySelectorAll('td')).map(d => d.innerHTML)
181
- )
182
- ).toMatchSnapshot()
183
-
184
- expect(
185
- Array.from(rendered.container.querySelectorAll('tfoot > tr')).map(d =>
186
- Array.from(d.querySelectorAll('th')).map(d => [
187
- d.innerHTML,
188
- d.getAttribute('colspan'),
189
- ])
190
- )
191
- ).toMatchSnapshot()
192
- })
193
-
194
- it('has a stable api', () => {
195
- const { result } = renderHook(() => {
196
- const rerender = React.useReducer(() => ({}), {})[1]
197
-
198
- const instance = table.useTable({
199
- data: defaultData,
200
- columns: defaultColumns,
201
- })
202
-
203
- return {
204
- instance,
205
- rerender,
206
- }
207
- })
208
-
209
- const prev = result.current
210
-
211
- act(() => {
212
- result.current.rerender()
213
- })
214
-
215
- const next = result.current
216
-
217
- expect(prev).toStrictEqual(next)
218
- })
219
-
220
- it('can return the rowModel', () => {
221
- const { result } = renderHook(() => {
222
- const rerender = React.useReducer(() => ({}), {})[1]
223
-
224
- const instance = table.useTable({
225
- data: defaultData,
226
- columns: defaultColumns,
227
- })
228
-
229
- return {
230
- instance,
231
- rerender,
232
- }
233
- })
234
-
235
- const rowModel = result.current.instance.getRowModel()
236
-
237
- expect(rowModel.rows.length).toEqual(3)
238
- expect(rowModel.flatRows.length).toEqual(3)
239
- expect(rowModel.rowsById['2']?.original).toEqual(defaultData[2])
240
- })
241
- })