@tanstack/react-table 0.0.1-alpha.8 → 8.0.0-alpha.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/build/cjs/_virtual/_rollupPluginBabelHelpers.js +112 -0
- package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +1 -0
- package/build/cjs/aggregationTypes.js +130 -0
- package/build/cjs/aggregationTypes.js.map +1 -0
- package/build/cjs/core.js +519 -0
- package/build/cjs/core.js.map +1 -0
- package/build/cjs/createTable.js +103 -0
- package/build/cjs/createTable.js.map +1 -0
- package/build/cjs/features/ColumnSizing.js +331 -0
- package/build/cjs/features/ColumnSizing.js.map +1 -0
- package/build/cjs/features/Expanding.js +234 -0
- package/build/cjs/features/Expanding.js.map +1 -0
- package/build/cjs/features/Filters.js +396 -0
- package/build/cjs/features/Filters.js.map +1 -0
- package/build/cjs/features/Grouping.js +228 -0
- package/build/cjs/features/Grouping.js.map +1 -0
- package/build/cjs/features/Headers.js +486 -0
- package/build/cjs/features/Headers.js.map +1 -0
- package/build/cjs/features/Ordering.js +83 -0
- package/build/cjs/features/Ordering.js.map +1 -0
- package/build/cjs/features/Pinning.js +163 -0
- package/build/cjs/features/Pinning.js.map +1 -0
- package/build/cjs/features/Sorting.js +269 -0
- package/build/cjs/features/Sorting.js.map +1 -0
- package/build/cjs/features/Visibility.js +160 -0
- package/build/cjs/features/Visibility.js.map +1 -0
- package/build/cjs/filterTypes.js +172 -0
- package/build/cjs/filterTypes.js.map +1 -0
- package/build/cjs/index.js +30 -0
- package/build/cjs/index.js.map +1 -0
- package/build/cjs/sortTypes.js +121 -0
- package/build/cjs/sortTypes.js.map +1 -0
- package/build/cjs/utils/columnFilterRowsFn.js +130 -0
- package/build/cjs/utils/columnFilterRowsFn.js.map +1 -0
- package/build/cjs/utils/expandRowsFn.js +38 -0
- package/build/cjs/utils/expandRowsFn.js.map +1 -0
- package/build/cjs/utils/globalFilterRowsFn.js +100 -0
- package/build/cjs/utils/globalFilterRowsFn.js.map +1 -0
- package/build/cjs/utils/groupRowsFn.js +154 -0
- package/build/cjs/utils/groupRowsFn.js.map +1 -0
- package/build/cjs/utils/sortRowsFn.js +93 -0
- package/build/cjs/utils/sortRowsFn.js.map +1 -0
- package/build/cjs/utils.js +143 -0
- package/build/cjs/utils.js.map +1 -0
- package/build/esm/index.js +3722 -0
- package/build/esm/index.js.map +1 -0
- package/build/stats-html.html +2689 -0
- package/build/stats-react.json +747 -0
- package/build/types/aggregationTypes.d.ts +22 -0
- package/build/types/core.d.ts +126 -0
- package/build/types/createTable.d.ts +35 -0
- package/build/types/features/ColumnSizing.d.ts +73 -0
- package/build/types/features/Expanding.d.ts +52 -0
- package/build/types/features/Filters.d.ts +93 -0
- package/build/types/features/Grouping.d.ts +82 -0
- package/build/types/features/Headers.d.ts +41 -0
- package/build/types/features/Ordering.d.ts +19 -0
- package/build/types/features/Pinning.d.ts +39 -0
- package/build/types/features/Sorting.d.ts +75 -0
- package/build/types/features/Visibility.d.ts +47 -0
- package/build/types/filterTypes.d.ts +50 -0
- package/build/types/index.d.ts +7 -0
- package/build/types/sortTypes.d.ts +17 -0
- package/build/types/types.d.ts +124 -0
- package/build/types/utils/columnFilterRowsFn.d.ts +2 -0
- package/build/types/utils/expandRowsFn.d.ts +2 -0
- package/build/types/utils/globalFilterRowsFn.d.ts +2 -0
- package/build/types/utils/groupRowsFn.d.ts +2 -0
- package/build/types/utils/sortRowsFn.d.ts +2 -0
- package/build/types/utils.d.ts +24 -0
- package/{dist/react-table.development.js → build/umd/index.development.js} +372 -29
- package/build/umd/index.development.js.map +1 -0
- package/build/umd/index.production.js +12 -0
- package/build/umd/index.production.js.map +1 -0
- package/package.json +9 -94
- package/src/core.tsx +43 -5
- package/src/createTable.tsx +1 -1
- package/src/features/ColumnSizing.ts +482 -0
- package/src/features/Filters.ts +1 -1
- package/src/features/Headers.ts +43 -6
- package/src/features/{withPagination.ts → withPagination.oldts} +0 -0
- package/src/features/{withRowSelection.ts → withRowSelection.oldts} +0 -0
- package/src/types.ts +35 -6
- package/src/utils.tsx +8 -2
- package/dist/react-table.development.js.map +0 -1
- package/dist/react-table.production.min.js +0 -2
- package/dist/react-table.production.min.js.map +0 -1
- package/lib/index.js +0 -65
- package/src/features/notest/useAbsoluteLayout.test.js +0 -152
- package/src/features/notest/useBlockLayout.test.js +0 -158
- package/src/features/notest/useColumnOrder.test.js +0 -186
- package/src/features/notest/useExpanded.test.js +0 -125
- package/src/features/notest/useFilters.test.js +0 -393
- package/src/features/notest/useFiltersAndRowSelect.test.js +0 -256
- package/src/features/notest/useFlexLayout.test.js +0 -152
- package/src/features/notest/useGroupBy.test.js +0 -259
- package/src/features/notest/usePagination.test.js +0 -231
- package/src/features/notest/useResizeColumns.test.js +0 -229
- package/src/features/notest/useRowSelect.test.js +0 -250
- package/src/features/notest/useRowState.test.js +0 -178
- package/src/features/tests/Visibility.test.tsx +0 -225
- package/src/features/tests/__snapshots__/Visibility.test.tsx.snap +0 -390
- package/src/features/tests/withSorting.notest.tsx +0 -341
- package/src/features/withColumnResizing.ts +0 -281
- package/src/test-utils/makeTestData.ts +0 -41
- package/src/tests/__snapshots__/core.test.tsx.snap +0 -148
- package/src/tests/core.test.tsx +0 -241
|
@@ -1,229 +0,0 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
import { render, fireEvent } from '@testing-library/react'
|
|
3
|
-
import { useTable } from '../../hooks/useTable'
|
|
4
|
-
import { useBlockLayout } from '../useBlockLayout'
|
|
5
|
-
import { useResizeColumns } from '../useResizeColumns'
|
|
6
|
-
|
|
7
|
-
const data = [
|
|
8
|
-
{
|
|
9
|
-
firstName: 'tanner',
|
|
10
|
-
lastName: 'linsley',
|
|
11
|
-
age: 29,
|
|
12
|
-
visits: 100,
|
|
13
|
-
status: 'In Relationship',
|
|
14
|
-
progress: 50,
|
|
15
|
-
},
|
|
16
|
-
{
|
|
17
|
-
firstName: 'derek',
|
|
18
|
-
lastName: 'perkins',
|
|
19
|
-
age: 40,
|
|
20
|
-
visits: 40,
|
|
21
|
-
status: 'Single',
|
|
22
|
-
progress: 80,
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
firstName: 'joe',
|
|
26
|
-
lastName: 'bergevin',
|
|
27
|
-
age: 45,
|
|
28
|
-
visits: 20,
|
|
29
|
-
status: 'Complicated',
|
|
30
|
-
progress: 10,
|
|
31
|
-
},
|
|
32
|
-
]
|
|
33
|
-
function Table({ columns, data }) {
|
|
34
|
-
const defaultColumn = React.useMemo(
|
|
35
|
-
() => ({
|
|
36
|
-
minWidth: 30,
|
|
37
|
-
width: 150,
|
|
38
|
-
maxWidth: 400,
|
|
39
|
-
}),
|
|
40
|
-
[]
|
|
41
|
-
)
|
|
42
|
-
|
|
43
|
-
const { getTableProps, getTableBodyProps, headerGroups, rows, prepareRow } =
|
|
44
|
-
useTable(
|
|
45
|
-
{
|
|
46
|
-
columns,
|
|
47
|
-
data,
|
|
48
|
-
defaultColumn,
|
|
49
|
-
},
|
|
50
|
-
useBlockLayout,
|
|
51
|
-
useResizeColumns
|
|
52
|
-
)
|
|
53
|
-
|
|
54
|
-
return (
|
|
55
|
-
<div {...getTableProps()} className="table">
|
|
56
|
-
<div>
|
|
57
|
-
{headerGroups.map(headerGroup => (
|
|
58
|
-
<div {...headerGroup.getHeaderGroupProps()} className="tr">
|
|
59
|
-
{headerGroup.headers.map(column => (
|
|
60
|
-
<div {...column.getHeaderProps()} className="th">
|
|
61
|
-
{column.render('Header')}
|
|
62
|
-
{/* Use column.getResizerProps to hook up the events correctly */}
|
|
63
|
-
<div
|
|
64
|
-
{...column.getResizerProps()}
|
|
65
|
-
className={`resizer${column.isResizing ? ' isResizing' : ''}`}
|
|
66
|
-
/>
|
|
67
|
-
</div>
|
|
68
|
-
))}
|
|
69
|
-
</div>
|
|
70
|
-
))}
|
|
71
|
-
</div>
|
|
72
|
-
|
|
73
|
-
<div {...getTableBodyProps()}>
|
|
74
|
-
{rows.map((row, i) => {
|
|
75
|
-
prepareRow(row)
|
|
76
|
-
return (
|
|
77
|
-
<div {...row.getRowProps()} className="tr">
|
|
78
|
-
{row.cells.map(cell => {
|
|
79
|
-
return (
|
|
80
|
-
<div {...cell.getCellProps()} className="td">
|
|
81
|
-
{cell.render('Cell')}
|
|
82
|
-
</div>
|
|
83
|
-
)
|
|
84
|
-
})}
|
|
85
|
-
</div>
|
|
86
|
-
)
|
|
87
|
-
})}
|
|
88
|
-
</div>
|
|
89
|
-
</div>
|
|
90
|
-
)
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
function App() {
|
|
94
|
-
const columns = React.useMemo(
|
|
95
|
-
() => [
|
|
96
|
-
{
|
|
97
|
-
Header: 'Name',
|
|
98
|
-
columns: [
|
|
99
|
-
{
|
|
100
|
-
Header: 'First Name',
|
|
101
|
-
accessor: 'firstName',
|
|
102
|
-
},
|
|
103
|
-
{
|
|
104
|
-
Header: 'Last Name',
|
|
105
|
-
accessor: 'lastName',
|
|
106
|
-
},
|
|
107
|
-
],
|
|
108
|
-
},
|
|
109
|
-
{
|
|
110
|
-
Header: 'Info',
|
|
111
|
-
columns: [
|
|
112
|
-
{
|
|
113
|
-
Header: 'Age',
|
|
114
|
-
accessor: 'age',
|
|
115
|
-
width: 50,
|
|
116
|
-
},
|
|
117
|
-
{
|
|
118
|
-
Header: 'Visits',
|
|
119
|
-
accessor: 'visits',
|
|
120
|
-
width: 60,
|
|
121
|
-
},
|
|
122
|
-
{
|
|
123
|
-
Header: 'Status',
|
|
124
|
-
accessor: 'status',
|
|
125
|
-
},
|
|
126
|
-
{
|
|
127
|
-
Header: 'Profile Progress',
|
|
128
|
-
accessor: 'progress',
|
|
129
|
-
},
|
|
130
|
-
],
|
|
131
|
-
},
|
|
132
|
-
],
|
|
133
|
-
[]
|
|
134
|
-
)
|
|
135
|
-
|
|
136
|
-
return <Table columns={columns} data={data} />
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
const start = 20
|
|
140
|
-
const move = 100
|
|
141
|
-
const end = 100
|
|
142
|
-
|
|
143
|
-
const sizesBefore = [
|
|
144
|
-
'300px',
|
|
145
|
-
'410px',
|
|
146
|
-
'150px',
|
|
147
|
-
'150px',
|
|
148
|
-
'50px',
|
|
149
|
-
'60px',
|
|
150
|
-
'150px',
|
|
151
|
-
'150px',
|
|
152
|
-
]
|
|
153
|
-
|
|
154
|
-
const sizesAfter = [
|
|
155
|
-
'300px',
|
|
156
|
-
'490px',
|
|
157
|
-
'150px',
|
|
158
|
-
'150px',
|
|
159
|
-
'59.75609756097561px',
|
|
160
|
-
'71.70731707317073px',
|
|
161
|
-
'179.26829268292684px',
|
|
162
|
-
'179.26829268292684px',
|
|
163
|
-
]
|
|
164
|
-
|
|
165
|
-
test('table can be resized by a mouse', () => {
|
|
166
|
-
const rtl = render(<App />)
|
|
167
|
-
|
|
168
|
-
const infoResizer = rtl
|
|
169
|
-
.getAllByRole('separator')
|
|
170
|
-
.find(d => d.previousSibling.textContent === 'Info')
|
|
171
|
-
|
|
172
|
-
expect(rtl.getAllByRole('columnheader').map(d => d.style.width)).toEqual(
|
|
173
|
-
sizesBefore
|
|
174
|
-
)
|
|
175
|
-
|
|
176
|
-
fireEvent.mouseDown(infoResizer, { clientX: start })
|
|
177
|
-
fireEvent.mouseMove(infoResizer, { clientX: move })
|
|
178
|
-
fireEvent.mouseUp(infoResizer, { clientX: end })
|
|
179
|
-
|
|
180
|
-
expect(rtl.getAllByRole('columnheader').map(d => d.style.width)).toEqual(
|
|
181
|
-
sizesAfter
|
|
182
|
-
)
|
|
183
|
-
})
|
|
184
|
-
|
|
185
|
-
test('table can be resized by a touch device', () => {
|
|
186
|
-
const rtl = render(<App />)
|
|
187
|
-
|
|
188
|
-
const infoResizer = rtl
|
|
189
|
-
.getAllByRole('separator')
|
|
190
|
-
.find(d => d.previousSibling.textContent === 'Info')
|
|
191
|
-
|
|
192
|
-
expect(rtl.getAllByRole('columnheader').map(d => d.style.width)).toEqual(
|
|
193
|
-
sizesBefore
|
|
194
|
-
)
|
|
195
|
-
|
|
196
|
-
fireEvent.touchStart(infoResizer, { touches: [{ clientX: start }] })
|
|
197
|
-
fireEvent.touchMove(infoResizer, { touches: [{ clientX: move }] })
|
|
198
|
-
fireEvent.touchEnd(infoResizer, { touches: [{ clientX: end }] })
|
|
199
|
-
|
|
200
|
-
expect(rtl.getAllByRole('columnheader').map(d => d.style.width)).toEqual(
|
|
201
|
-
sizesAfter
|
|
202
|
-
)
|
|
203
|
-
})
|
|
204
|
-
|
|
205
|
-
test('table can not be resized with multiple touches', () => {
|
|
206
|
-
const rtl = render(<App />)
|
|
207
|
-
|
|
208
|
-
const infoResizer = rtl
|
|
209
|
-
.getAllByRole('separator')
|
|
210
|
-
.find(d => d.previousSibling.textContent === 'Info')
|
|
211
|
-
|
|
212
|
-
expect(rtl.getAllByRole('columnheader').map(d => d.style.width)).toEqual(
|
|
213
|
-
sizesBefore
|
|
214
|
-
)
|
|
215
|
-
|
|
216
|
-
fireEvent.touchStart(infoResizer, {
|
|
217
|
-
touches: [{ clientX: start }, { clientX: start }],
|
|
218
|
-
})
|
|
219
|
-
fireEvent.touchMove(infoResizer, {
|
|
220
|
-
touches: [{ clientX: move }, { clientX: move }],
|
|
221
|
-
})
|
|
222
|
-
fireEvent.touchEnd(infoResizer, {
|
|
223
|
-
touches: [{ clientX: end }, { clientX: end }],
|
|
224
|
-
})
|
|
225
|
-
|
|
226
|
-
expect(rtl.getAllByRole('columnheader').map(d => d.style.width)).toEqual(
|
|
227
|
-
sizesBefore
|
|
228
|
-
)
|
|
229
|
-
})
|
|
@@ -1,250 +0,0 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
import { render, fireEvent } from '@testing-library/react'
|
|
3
|
-
import { useTable } from '../../hooks/useTable'
|
|
4
|
-
import { useRowSelect } from '../useRowSelect'
|
|
5
|
-
import { useExpanded } from '../useExpanded'
|
|
6
|
-
|
|
7
|
-
const dataPiece = [
|
|
8
|
-
{
|
|
9
|
-
firstName: 'tanner',
|
|
10
|
-
lastName: 'linsley',
|
|
11
|
-
age: 29,
|
|
12
|
-
visits: 100,
|
|
13
|
-
status: 'In Relationship',
|
|
14
|
-
progress: 50,
|
|
15
|
-
},
|
|
16
|
-
{
|
|
17
|
-
firstName: 'derek',
|
|
18
|
-
lastName: 'perkins',
|
|
19
|
-
age: 40,
|
|
20
|
-
visits: 40,
|
|
21
|
-
status: 'Single',
|
|
22
|
-
progress: 80,
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
firstName: 'joe',
|
|
26
|
-
lastName: 'bergevin',
|
|
27
|
-
age: 45,
|
|
28
|
-
visits: 20,
|
|
29
|
-
status: 'Complicated',
|
|
30
|
-
progress: 10,
|
|
31
|
-
expanded: true,
|
|
32
|
-
subRows: [
|
|
33
|
-
{
|
|
34
|
-
firstName: 'bob',
|
|
35
|
-
lastName: 'ross',
|
|
36
|
-
age: 52,
|
|
37
|
-
visits: 40,
|
|
38
|
-
status: 'In Relationship',
|
|
39
|
-
progress: 30,
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
firstName: 'john',
|
|
43
|
-
lastName: 'smith',
|
|
44
|
-
age: 21,
|
|
45
|
-
visits: 30,
|
|
46
|
-
status: 'Single',
|
|
47
|
-
progress: 60,
|
|
48
|
-
},
|
|
49
|
-
],
|
|
50
|
-
},
|
|
51
|
-
{
|
|
52
|
-
firstName: 'jaylen',
|
|
53
|
-
lastName: 'linsley',
|
|
54
|
-
age: 26,
|
|
55
|
-
visits: 99,
|
|
56
|
-
status: 'In Relationship',
|
|
57
|
-
progress: 70,
|
|
58
|
-
},
|
|
59
|
-
]
|
|
60
|
-
|
|
61
|
-
const data = [
|
|
62
|
-
...dataPiece,
|
|
63
|
-
...dataPiece,
|
|
64
|
-
...dataPiece,
|
|
65
|
-
...dataPiece,
|
|
66
|
-
...dataPiece,
|
|
67
|
-
...dataPiece,
|
|
68
|
-
]
|
|
69
|
-
|
|
70
|
-
function Table({ columns, data }) {
|
|
71
|
-
// Use the state and functions returned from useTable to build your UI
|
|
72
|
-
const { getTableProps, getTableBodyProps, headerGroups, rows, prepareRow } =
|
|
73
|
-
useTable(
|
|
74
|
-
{
|
|
75
|
-
columns,
|
|
76
|
-
data,
|
|
77
|
-
},
|
|
78
|
-
useRowSelect,
|
|
79
|
-
useExpanded,
|
|
80
|
-
hooks => {
|
|
81
|
-
hooks.leafColumns.push(columns => [
|
|
82
|
-
// Let's make a column for selection
|
|
83
|
-
{
|
|
84
|
-
id: 'selection',
|
|
85
|
-
// The header can use the table's getToggleAllRowsSelectedProps method
|
|
86
|
-
// to render a checkbox
|
|
87
|
-
Header: ({ instance: { getToggleAllRowsSelectedProps } }) => (
|
|
88
|
-
<div>
|
|
89
|
-
<label>
|
|
90
|
-
<IndeterminateCheckbox {...getToggleAllRowsSelectedProps()} />{' '}
|
|
91
|
-
Select All
|
|
92
|
-
</label>
|
|
93
|
-
</div>
|
|
94
|
-
),
|
|
95
|
-
// The cell can use the individual row's getToggleRowSelectedProps method
|
|
96
|
-
// to the render a checkbox
|
|
97
|
-
Cell: ({ row }) => (
|
|
98
|
-
<div>
|
|
99
|
-
<label>
|
|
100
|
-
<IndeterminateCheckbox {...row.getToggleRowSelectedProps()} />{' '}
|
|
101
|
-
Select Row
|
|
102
|
-
</label>
|
|
103
|
-
</div>
|
|
104
|
-
),
|
|
105
|
-
},
|
|
106
|
-
...columns,
|
|
107
|
-
])
|
|
108
|
-
}
|
|
109
|
-
)
|
|
110
|
-
|
|
111
|
-
// Render the UI for your table
|
|
112
|
-
return (
|
|
113
|
-
<>
|
|
114
|
-
<table {...getTableProps()}>
|
|
115
|
-
<thead>
|
|
116
|
-
{headerGroups.map(headerGroup => (
|
|
117
|
-
<tr {...headerGroup.getHeaderGroupProps()}>
|
|
118
|
-
{headerGroup.headers.map(column => (
|
|
119
|
-
<th {...column.getHeaderProps()}>{column.render('Header')}</th>
|
|
120
|
-
))}
|
|
121
|
-
</tr>
|
|
122
|
-
))}
|
|
123
|
-
</thead>
|
|
124
|
-
<tbody {...getTableBodyProps()}>
|
|
125
|
-
{rows.map(
|
|
126
|
-
(row, i) =>
|
|
127
|
-
prepareRow(row) || (
|
|
128
|
-
<tr {...row.getRowProps()}>
|
|
129
|
-
{row.cells.map(cell => {
|
|
130
|
-
return (
|
|
131
|
-
<td {...cell.getCellProps()}>{cell.render('Cell')}</td>
|
|
132
|
-
)
|
|
133
|
-
})}
|
|
134
|
-
</tr>
|
|
135
|
-
)
|
|
136
|
-
)}
|
|
137
|
-
</tbody>
|
|
138
|
-
</table>
|
|
139
|
-
</>
|
|
140
|
-
)
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
const IndeterminateCheckbox = React.forwardRef(
|
|
144
|
-
({ indeterminate, ...rest }, ref) => {
|
|
145
|
-
const defaultRef = React.useRef()
|
|
146
|
-
const resolvedRef = ref || defaultRef
|
|
147
|
-
|
|
148
|
-
React.useEffect(() => {
|
|
149
|
-
resolvedRef.current.indeterminate = indeterminate
|
|
150
|
-
}, [resolvedRef, indeterminate])
|
|
151
|
-
|
|
152
|
-
return <input type="checkbox" ref={resolvedRef} {...rest} />
|
|
153
|
-
}
|
|
154
|
-
)
|
|
155
|
-
|
|
156
|
-
function App() {
|
|
157
|
-
const columns = React.useMemo(
|
|
158
|
-
() => [
|
|
159
|
-
{
|
|
160
|
-
id: 'selectedStatus',
|
|
161
|
-
Cell: ({ row }) =>
|
|
162
|
-
row.isSelected ? (
|
|
163
|
-
<div>
|
|
164
|
-
<div>Selected</div>
|
|
165
|
-
<div>Row {row.id}</div>
|
|
166
|
-
</div>
|
|
167
|
-
) : null,
|
|
168
|
-
},
|
|
169
|
-
{
|
|
170
|
-
Header: 'Name',
|
|
171
|
-
columns: [
|
|
172
|
-
{
|
|
173
|
-
Header: 'First Name',
|
|
174
|
-
accessor: 'firstName',
|
|
175
|
-
},
|
|
176
|
-
{
|
|
177
|
-
Header: 'Last Name',
|
|
178
|
-
accessor: 'lastName',
|
|
179
|
-
},
|
|
180
|
-
],
|
|
181
|
-
},
|
|
182
|
-
{
|
|
183
|
-
Header: 'Info',
|
|
184
|
-
columns: [
|
|
185
|
-
{
|
|
186
|
-
Header: 'Age',
|
|
187
|
-
accessor: 'age',
|
|
188
|
-
},
|
|
189
|
-
{
|
|
190
|
-
Header: 'Visits',
|
|
191
|
-
accessor: 'visits',
|
|
192
|
-
},
|
|
193
|
-
{
|
|
194
|
-
Header: 'Status',
|
|
195
|
-
accessor: 'status',
|
|
196
|
-
},
|
|
197
|
-
{
|
|
198
|
-
Header: 'Profile Progress',
|
|
199
|
-
accessor: 'progress',
|
|
200
|
-
},
|
|
201
|
-
],
|
|
202
|
-
},
|
|
203
|
-
],
|
|
204
|
-
[]
|
|
205
|
-
)
|
|
206
|
-
|
|
207
|
-
return <Table columns={columns} data={data} />
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
test('renders a table with selectable rows', () => {
|
|
211
|
-
const rtl = render(<App />)
|
|
212
|
-
|
|
213
|
-
fireEvent.click(rtl.getByLabelText('Select All'))
|
|
214
|
-
|
|
215
|
-
expect(rtl.getAllByText('Selected').length).toBe(24)
|
|
216
|
-
|
|
217
|
-
fireEvent.click(rtl.getAllByLabelText('Select Row')[2])
|
|
218
|
-
|
|
219
|
-
expect(rtl.queryAllByText('Selected').length).toBe(23)
|
|
220
|
-
|
|
221
|
-
fireEvent.click(rtl.getByLabelText('Select All'))
|
|
222
|
-
|
|
223
|
-
expect(rtl.queryAllByText('Selected').length).toBe(24)
|
|
224
|
-
|
|
225
|
-
fireEvent.click(rtl.getByLabelText('Select All'))
|
|
226
|
-
|
|
227
|
-
expect(rtl.queryAllByText('Selected').length).toBe(0)
|
|
228
|
-
|
|
229
|
-
fireEvent.click(rtl.getAllByLabelText('Select Row')[0])
|
|
230
|
-
fireEvent.click(rtl.getAllByLabelText('Select Row')[2])
|
|
231
|
-
|
|
232
|
-
rtl.getByText('Row 0')
|
|
233
|
-
rtl.getByText('Row 2')
|
|
234
|
-
|
|
235
|
-
fireEvent.click(rtl.getAllByLabelText('Select Row')[2])
|
|
236
|
-
|
|
237
|
-
expect(rtl.queryByText('Row 2')).toBeNull()
|
|
238
|
-
|
|
239
|
-
fireEvent.click(rtl.getAllByLabelText('Select Row')[3])
|
|
240
|
-
|
|
241
|
-
rtl.queryByText('Row 3')
|
|
242
|
-
|
|
243
|
-
fireEvent.click(rtl.getAllByLabelText('Select Row')[4])
|
|
244
|
-
|
|
245
|
-
rtl.queryByText('Row 4')
|
|
246
|
-
|
|
247
|
-
fireEvent.click(rtl.getAllByLabelText('Select Row')[4])
|
|
248
|
-
|
|
249
|
-
expect(rtl.queryByText('Row 4')).toBeNull()
|
|
250
|
-
})
|
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
import { render, fireEvent } from '../../../test-utils/react-testing'
|
|
3
|
-
import { useTable } from '../../hooks/useTable'
|
|
4
|
-
import { useRowState } from '../useRowState'
|
|
5
|
-
|
|
6
|
-
const data = [
|
|
7
|
-
{
|
|
8
|
-
firstName: 'tanner',
|
|
9
|
-
lastName: 'linsley',
|
|
10
|
-
age: 29,
|
|
11
|
-
visits: 100,
|
|
12
|
-
status: 'In Relationship',
|
|
13
|
-
progress: 50,
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
firstName: 'derek',
|
|
17
|
-
lastName: 'perkins',
|
|
18
|
-
age: 40,
|
|
19
|
-
visits: 40,
|
|
20
|
-
status: 'Single',
|
|
21
|
-
progress: 80,
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
firstName: 'joe',
|
|
25
|
-
lastName: 'bergevin',
|
|
26
|
-
age: 45,
|
|
27
|
-
visits: 20,
|
|
28
|
-
status: 'Complicated',
|
|
29
|
-
progress: 10,
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
firstName: 'jaylen',
|
|
33
|
-
lastName: 'linsley',
|
|
34
|
-
age: 26,
|
|
35
|
-
visits: 99,
|
|
36
|
-
status: 'In Relationship',
|
|
37
|
-
progress: 70,
|
|
38
|
-
},
|
|
39
|
-
]
|
|
40
|
-
|
|
41
|
-
const defaultColumn = {
|
|
42
|
-
Cell: ({ column, cell, row }) => (
|
|
43
|
-
<div>
|
|
44
|
-
Row {row.id} Cell {column.id} Count {cell.state.count}{' '}
|
|
45
|
-
<button
|
|
46
|
-
onClick={() => cell.setState(old => ({ ...old, count: old.count + 1 }))}
|
|
47
|
-
>
|
|
48
|
-
Row {row.id} Cell {column.id} Toggle
|
|
49
|
-
</button>
|
|
50
|
-
</div>
|
|
51
|
-
),
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function Table({ columns, data }) {
|
|
55
|
-
const { getTableProps, getTableBodyProps, headerGroups, rows, prepareRow } =
|
|
56
|
-
useTable(
|
|
57
|
-
{
|
|
58
|
-
columns,
|
|
59
|
-
data,
|
|
60
|
-
defaultColumn,
|
|
61
|
-
initialRowStateAccessor: () => ({ count: 0 }),
|
|
62
|
-
initialCellStateAccessor: () => ({ count: 0 }),
|
|
63
|
-
},
|
|
64
|
-
useRowState
|
|
65
|
-
)
|
|
66
|
-
|
|
67
|
-
return (
|
|
68
|
-
<table {...getTableProps()}>
|
|
69
|
-
<thead>
|
|
70
|
-
{headerGroups.map(headerGroup => (
|
|
71
|
-
<tr {...headerGroup.getHeaderGroupProps()}>
|
|
72
|
-
{headerGroup.headers.map(column => (
|
|
73
|
-
<th {...column.getHeaderProps()}>{column.render('Header')}</th>
|
|
74
|
-
))}
|
|
75
|
-
</tr>
|
|
76
|
-
))}
|
|
77
|
-
</thead>
|
|
78
|
-
<tbody {...getTableBodyProps()}>
|
|
79
|
-
{rows.map(
|
|
80
|
-
(row, i) =>
|
|
81
|
-
prepareRow(row) || (
|
|
82
|
-
<tr {...row.getRowProps()}>
|
|
83
|
-
<td>
|
|
84
|
-
<pre>Row Count {row.state.count}</pre>
|
|
85
|
-
<button
|
|
86
|
-
onClick={() =>
|
|
87
|
-
row.setState(old => ({
|
|
88
|
-
...old,
|
|
89
|
-
count: old.count + 1,
|
|
90
|
-
}))
|
|
91
|
-
}
|
|
92
|
-
>
|
|
93
|
-
Row {row.id} Toggle
|
|
94
|
-
</button>
|
|
95
|
-
</td>
|
|
96
|
-
{row.cells.map(cell => (
|
|
97
|
-
<td {...cell.getCellProps()}>{cell.render('Cell')}</td>
|
|
98
|
-
))}
|
|
99
|
-
</tr>
|
|
100
|
-
)
|
|
101
|
-
)}
|
|
102
|
-
</tbody>
|
|
103
|
-
</table>
|
|
104
|
-
)
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
function App() {
|
|
108
|
-
const columns = React.useMemo(
|
|
109
|
-
() => [
|
|
110
|
-
{
|
|
111
|
-
Header: 'Name',
|
|
112
|
-
columns: [
|
|
113
|
-
{
|
|
114
|
-
Header: 'First Name',
|
|
115
|
-
accessor: 'firstName',
|
|
116
|
-
},
|
|
117
|
-
{
|
|
118
|
-
Header: 'Last Name',
|
|
119
|
-
accessor: 'lastName',
|
|
120
|
-
},
|
|
121
|
-
],
|
|
122
|
-
},
|
|
123
|
-
{
|
|
124
|
-
Header: 'Info',
|
|
125
|
-
columns: [
|
|
126
|
-
{
|
|
127
|
-
Header: 'Age',
|
|
128
|
-
accessor: 'age',
|
|
129
|
-
},
|
|
130
|
-
{
|
|
131
|
-
Header: 'Visits',
|
|
132
|
-
accessor: 'visits',
|
|
133
|
-
},
|
|
134
|
-
{
|
|
135
|
-
Header: 'Status',
|
|
136
|
-
accessor: 'status',
|
|
137
|
-
},
|
|
138
|
-
{
|
|
139
|
-
Header: 'Profile Progress',
|
|
140
|
-
accessor: 'progress',
|
|
141
|
-
},
|
|
142
|
-
],
|
|
143
|
-
},
|
|
144
|
-
],
|
|
145
|
-
[]
|
|
146
|
-
)
|
|
147
|
-
|
|
148
|
-
return <Table columns={columns} data={data} />
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
test('renders a filterable table', () => {
|
|
152
|
-
const rendered = render(<App />)
|
|
153
|
-
|
|
154
|
-
fireEvent.click(rendered.getByText('Row 1 Toggle'))
|
|
155
|
-
fireEvent.click(rendered.getByText('Row 1 Toggle'))
|
|
156
|
-
|
|
157
|
-
rendered.getByText('Row Count 2')
|
|
158
|
-
|
|
159
|
-
fireEvent.click(rendered.getByText('Row 1 Cell firstName Toggle'))
|
|
160
|
-
|
|
161
|
-
rendered.getByText('Row 1 Cell firstName Count 1')
|
|
162
|
-
|
|
163
|
-
fireEvent.click(rendered.getByText('Row 2 Cell lastName Toggle'))
|
|
164
|
-
fireEvent.click(rendered.getByText('Row 2 Cell lastName Toggle'))
|
|
165
|
-
|
|
166
|
-
rendered.getByText('Row 2 Cell lastName Count 2')
|
|
167
|
-
|
|
168
|
-
fireEvent.click(rendered.getByText('Row 3 Cell age Toggle'))
|
|
169
|
-
fireEvent.click(rendered.getByText('Row 3 Cell age Toggle'))
|
|
170
|
-
fireEvent.click(rendered.getByText('Row 3 Cell age Toggle'))
|
|
171
|
-
|
|
172
|
-
rendered.getByText('Row 3 Cell age Count 3')
|
|
173
|
-
|
|
174
|
-
fireEvent.click(rendered.getByText('Row 1 Toggle'))
|
|
175
|
-
fireEvent.click(rendered.getByText('Row 1 Toggle'))
|
|
176
|
-
|
|
177
|
-
rendered.getByText('Row Count 4')
|
|
178
|
-
})
|