playbook_ui 13.17.0 → 13.18.0.pre.alpha.PBNTR191AdvancedTableFinalFixes2159
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/pb_kits/playbook/_reset.scss +2 -2
- data/app/pb_kits/playbook/pb_advanced_table/Components/CustomCell.tsx +5 -3
- data/app/pb_kits/playbook/pb_advanced_table/Components/SubRowHeaderRow.tsx +4 -3
- data/app/pb_kits/playbook/pb_advanced_table/Components/TableHeaderCell.tsx +18 -13
- data/app/pb_kits/playbook/pb_advanced_table/SubKits/TableBody.tsx +26 -4
- data/app/pb_kits/playbook/pb_advanced_table/SubKits/TableHeader.tsx +18 -4
- data/app/pb_kits/playbook/pb_advanced_table/Utilities/ExpansionControlHelpers.tsx +3 -4
- data/app/pb_kits/playbook/pb_advanced_table/_advanced_table.tsx +15 -7
- data/app/pb_kits/playbook/pb_advanced_table/advanced_table.test.jsx +328 -3
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_collapsible_trail.jsx +52 -0
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_collapsible_trail.md +1 -0
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_default.md +7 -2
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_expanded_control.jsx +59 -0
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_expanded_control.md +18 -0
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_loading.jsx +60 -0
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_loading.md +3 -0
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_sort.jsx +1 -6
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_sort.md +5 -0
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_sort_control.jsx +63 -0
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_sort_control.md +3 -0
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_subrow_headers.jsx +57 -0
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_subrow_headers.md +3 -0
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_table_options.jsx +61 -0
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_table_options.md +3 -0
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_table_props.jsx +55 -0
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_table_props.md +1 -0
- data/app/pb_kits/playbook/pb_advanced_table/docs/example.yml +10 -4
- data/app/pb_kits/playbook/pb_advanced_table/docs/index.js +7 -0
- data/app/pb_kits/playbook/pb_advanced_table/scss_partials/_loading.scss +4 -3
- data/app/pb_kits/playbook/pb_collapsible/_collapsible.scss +2 -2
- data/app/pb_kits/playbook/pb_date_picker/sass_partials/_flatpickr_styles.scss +1 -1
- data/app/pb_kits/playbook/pb_phone_number_input/docs/_phone_number_input_validation.html.erb +5 -7
- data/app/pb_kits/playbook/pb_popover/_popover.tsx +12 -14
- data/app/pb_kits/playbook/pb_popover/docs/_popover_actionable_content.html.erb +30 -0
- data/app/pb_kits/playbook/pb_popover/docs/_popover_actionable_content.jsx +57 -0
- data/app/pb_kits/playbook/pb_popover/docs/example.yml +2 -1
- data/app/pb_kits/playbook/pb_popover/docs/index.js +1 -0
- data/app/pb_kits/playbook/pb_popover/popover.test.js +29 -31
- data/app/pb_kits/playbook/pb_table/_table.tsx +3 -0
- data/app/pb_kits/playbook/pb_table/docs/_table_striped.html.erb +48 -0
- data/app/pb_kits/playbook/pb_table/docs/_table_striped.jsx +58 -0
- data/app/pb_kits/playbook/pb_table/docs/_table_striped.md +1 -0
- data/app/pb_kits/playbook/pb_table/docs/example.yml +2 -0
- data/app/pb_kits/playbook/pb_table/docs/index.js +1 -0
- data/app/pb_kits/playbook/pb_table/styles/_all.scss +1 -0
- data/app/pb_kits/playbook/pb_table/styles/_striped.scss +19 -0
- data/app/pb_kits/playbook/pb_table/table.rb +7 -1
- data/app/pb_kits/playbook/pb_table/table.test.js +5 -0
- data/dist/menu.yml +102 -3
- data/dist/playbook-rails.js +7 -7
- data/dist/reset.css +1 -2
- data/lib/playbook/version.rb +2 -2
- metadata +28 -7
@@ -1,4 +1,4 @@
|
|
1
|
-
import React from "react";
|
1
|
+
import React, {useState} from "react";
|
2
2
|
import { render, screen } from "../utilities/test-utils";
|
3
3
|
|
4
4
|
import { AdvancedTable } from "../";
|
@@ -13,7 +13,25 @@ const MOCK_DATA = [
|
|
13
13
|
scheduledMeetings: "10",
|
14
14
|
children: [
|
15
15
|
{
|
16
|
-
year: "
|
16
|
+
year: "2021",
|
17
|
+
quarter: "Q1",
|
18
|
+
month: null,
|
19
|
+
day: null,
|
20
|
+
newEnrollments: "2",
|
21
|
+
scheduledMeetings: "35",
|
22
|
+
},
|
23
|
+
],
|
24
|
+
},
|
25
|
+
{
|
26
|
+
year: "2022",
|
27
|
+
quarter: null,
|
28
|
+
month: null,
|
29
|
+
day: null,
|
30
|
+
newEnrollments: "20",
|
31
|
+
scheduledMeetings: "10",
|
32
|
+
children: [
|
33
|
+
{
|
34
|
+
year: "2022",
|
17
35
|
quarter: "Q1",
|
18
36
|
month: null,
|
19
37
|
day: null,
|
@@ -40,9 +58,70 @@ const columnDefinitions = [
|
|
40
58
|
},
|
41
59
|
];
|
42
60
|
|
61
|
+
const subRowHeaders = ["Quarter"]
|
62
|
+
|
43
63
|
const testId = "advanced_table";
|
44
64
|
|
45
|
-
|
65
|
+
const AdvancedTableExpandControl = () => {
|
66
|
+
const [expanded, setExpanded] = useState({'0': true})
|
67
|
+
|
68
|
+
const expandedControl = {
|
69
|
+
value: expanded,
|
70
|
+
onChange: setExpanded,
|
71
|
+
}
|
72
|
+
|
73
|
+
return (
|
74
|
+
<div>
|
75
|
+
<AdvancedTable
|
76
|
+
columnDefinitions={columnDefinitions}
|
77
|
+
data={{ testid: testId }}
|
78
|
+
expandedControl={expandedControl}
|
79
|
+
tableData={MOCK_DATA}
|
80
|
+
/>
|
81
|
+
</div>
|
82
|
+
);
|
83
|
+
}
|
84
|
+
|
85
|
+
const AdvancedTableSortControl = () => {
|
86
|
+
const [isSortDesc, setIsSortDesc] = useState({desc: false})
|
87
|
+
|
88
|
+
const sortControl = {
|
89
|
+
value: isSortDesc,
|
90
|
+
onChange: setIsSortDesc,
|
91
|
+
}
|
92
|
+
|
93
|
+
return (
|
94
|
+
<div>
|
95
|
+
<AdvancedTable
|
96
|
+
columnDefinitions={columnDefinitions}
|
97
|
+
data={{testid: testId}}
|
98
|
+
sortControl={sortControl}
|
99
|
+
tableData={MOCK_DATA}
|
100
|
+
>
|
101
|
+
<AdvancedTable.Header enableSorting />
|
102
|
+
<AdvancedTable.Body />
|
103
|
+
</AdvancedTable>
|
104
|
+
</div>
|
105
|
+
);
|
106
|
+
}
|
107
|
+
|
108
|
+
const tableOptions = {
|
109
|
+
initialState: {
|
110
|
+
sorting: [
|
111
|
+
{
|
112
|
+
id: "year",
|
113
|
+
desc: true,
|
114
|
+
},
|
115
|
+
],
|
116
|
+
},
|
117
|
+
}
|
118
|
+
|
119
|
+
const tableProps = {
|
120
|
+
container: false,
|
121
|
+
sticky: true
|
122
|
+
}
|
123
|
+
|
124
|
+
test("Generates default kit and classname", () => {
|
46
125
|
render(
|
47
126
|
<AdvancedTable
|
48
127
|
columnDefinitions={columnDefinitions}
|
@@ -53,4 +132,250 @@ test("generated scaffold test", () => {
|
|
53
132
|
|
54
133
|
const kit = screen.getByTestId(testId);
|
55
134
|
expect(kit).toBeInTheDocument();
|
135
|
+
expect(kit).toHaveClass('pb_advanced_table')
|
136
|
+
});
|
137
|
+
|
138
|
+
test("Generates aria label", () => {
|
139
|
+
render(
|
140
|
+
<AdvancedTable
|
141
|
+
aria={{label:testId}}
|
142
|
+
columnDefinitions={columnDefinitions}
|
143
|
+
data={{ testid: testId }}
|
144
|
+
tableData={MOCK_DATA}
|
145
|
+
/>
|
146
|
+
);
|
147
|
+
|
148
|
+
const kit = screen.getByTestId(testId);
|
149
|
+
expect(kit).toHaveAttribute('aria-label', testId)
|
150
|
+
});
|
151
|
+
|
152
|
+
test("Row toggle button exists and toggles subrows open and closed", () => {
|
153
|
+
render(
|
154
|
+
<AdvancedTable
|
155
|
+
columnDefinitions={columnDefinitions}
|
156
|
+
data={{ testid: testId }}
|
157
|
+
tableData={MOCK_DATA}
|
158
|
+
/>
|
159
|
+
);
|
160
|
+
|
161
|
+
const kit = screen.getByTestId(testId);
|
162
|
+
const rowButton = kit.querySelector(".gray-icon.expand-toggle-icon")
|
163
|
+
expect(rowButton).toBeInTheDocument()
|
164
|
+
const subRow1 = kit.querySelector(".bg-white.depth-sub-row-1")
|
165
|
+
expect(subRow1).not.toBeInTheDocument()
|
166
|
+
rowButton.click()
|
167
|
+
const subRow = kit.querySelector(".bg-white.depth-sub-row-1")
|
168
|
+
expect(subRow).toBeInTheDocument()
|
169
|
+
});
|
170
|
+
|
171
|
+
test("toggleExpansionAll button exists and toggles subrows open and closed", () => {
|
172
|
+
render(
|
173
|
+
<AdvancedTable
|
174
|
+
columnDefinitions={columnDefinitions}
|
175
|
+
data={{ testid: testId }}
|
176
|
+
tableData={MOCK_DATA}
|
177
|
+
/>
|
178
|
+
);
|
179
|
+
|
180
|
+
const kit = screen.getByTestId(testId);
|
181
|
+
const toggleButton = kit.querySelector(".gray-icon.toggle-all-icon")
|
182
|
+
expect(toggleButton).toBeInTheDocument()
|
183
|
+
const subRow1 = kit.querySelector(".bg-white.depth-sub-row-1")
|
184
|
+
expect(subRow1).not.toBeInTheDocument()
|
185
|
+
toggleButton.click()
|
186
|
+
const subRow = kit.querySelector(".bg-white.depth-sub-row-1")
|
187
|
+
expect(subRow).toBeInTheDocument()
|
188
|
+
});
|
189
|
+
|
190
|
+
test("loading state + initialLoadingRowCount prop", () => {
|
191
|
+
render(
|
192
|
+
<AdvancedTable
|
193
|
+
columnDefinitions={columnDefinitions}
|
194
|
+
data={{ testid: testId }}
|
195
|
+
initialLoadingRowsCount={13}
|
196
|
+
loading
|
197
|
+
tableData={MOCK_DATA}
|
198
|
+
/>
|
199
|
+
);
|
200
|
+
|
201
|
+
const kit = screen.getByTestId(testId);
|
202
|
+
const table = kit.querySelector('table')
|
203
|
+
expect(table).toHaveClass('pb_table table-sm table-responsive-none table-card data_table ns_tabular content-loading')
|
204
|
+
|
205
|
+
const tableBody = kit.querySelector('tbody')
|
206
|
+
const tableRows = tableBody.getElementsByTagName('tr')
|
207
|
+
expect(tableRows).toHaveLength(13)
|
208
|
+
});
|
209
|
+
|
210
|
+
test("subRowHeaders are rendered", () => {
|
211
|
+
render(
|
212
|
+
<AdvancedTable
|
213
|
+
columnDefinitions={columnDefinitions}
|
214
|
+
data={{ testid: testId }}
|
215
|
+
tableData={MOCK_DATA}
|
216
|
+
>
|
217
|
+
<AdvancedTable.Header />
|
218
|
+
<AdvancedTable.Body subRowHeaders={subRowHeaders}/>
|
219
|
+
</AdvancedTable>
|
220
|
+
);
|
221
|
+
|
222
|
+
const kit = screen.getByTestId(testId);
|
223
|
+
|
224
|
+
const rowButton = kit.querySelector(".gray-icon.expand-toggle-icon")
|
225
|
+
rowButton.click()
|
226
|
+
|
227
|
+
const subRowHeader = kit.querySelector(".custom-row.bg-silver")
|
228
|
+
expect(subRowHeader).toBeInTheDocument()
|
229
|
+
});
|
230
|
+
|
231
|
+
test("expandControl prop works as expected", () => {
|
232
|
+
render (<AdvancedTableExpandControl/>)
|
233
|
+
|
234
|
+
const kit = screen.getByTestId(testId);
|
235
|
+
const subRow = kit.querySelector(".bg-white.depth-sub-row-1")
|
236
|
+
expect(subRow).toBeInTheDocument()
|
237
|
+
})
|
238
|
+
|
239
|
+
test("tableOptions prop functions as expected", () => {
|
240
|
+
render(
|
241
|
+
<AdvancedTable
|
242
|
+
columnDefinitions={columnDefinitions}
|
243
|
+
data={{ testid: testId }}
|
244
|
+
tableData={MOCK_DATA}
|
245
|
+
tableOptions={tableOptions}
|
246
|
+
/>
|
247
|
+
);
|
248
|
+
|
249
|
+
const kit = screen.getByTestId(testId);
|
250
|
+
const row1 = kit.getElementsByTagName('tr')[1]
|
251
|
+
|
252
|
+
expect(row1.id).toBe("1-1-0-row")
|
253
|
+
});
|
254
|
+
|
255
|
+
test("tableProps prop functions as expected", () => {
|
256
|
+
render(
|
257
|
+
<AdvancedTable
|
258
|
+
columnDefinitions={columnDefinitions}
|
259
|
+
data={{ testid: testId }}
|
260
|
+
tableData={MOCK_DATA}
|
261
|
+
tableProps={tableProps}
|
262
|
+
/>
|
263
|
+
);
|
264
|
+
|
265
|
+
const kit = screen.getByTestId(testId);
|
266
|
+
const table = kit.querySelector('table')
|
267
|
+
expect(table).toHaveClass("pb_table table-sm table-responsive-none data_table sticky-header ns_tabular")
|
268
|
+
});
|
269
|
+
|
270
|
+
test("enableExpansionIcon changes icon", () => {
|
271
|
+
render(
|
272
|
+
<AdvancedTable
|
273
|
+
columnDefinitions={columnDefinitions}
|
274
|
+
data={{ testid: testId }}
|
275
|
+
tableData={MOCK_DATA}
|
276
|
+
tableProps={tableProps}
|
277
|
+
toggleExpansionIcon= "chevron-up"
|
278
|
+
/>
|
279
|
+
);
|
280
|
+
|
281
|
+
const kit = screen.getByTestId(testId);
|
282
|
+
const tableHead = kit.querySelector('table')
|
283
|
+
const toggleIcon= tableHead.querySelector(".pb_icon_kit")
|
284
|
+
expect(toggleIcon).toHaveClass("fa-chevron-up")
|
285
|
+
});
|
286
|
+
|
287
|
+
test("sortIcon changes icon", () => {
|
288
|
+
render(
|
289
|
+
<AdvancedTable
|
290
|
+
columnDefinitions={columnDefinitions}
|
291
|
+
data={{ testid: testId }}
|
292
|
+
tableData={MOCK_DATA}
|
293
|
+
tableProps={tableProps}
|
294
|
+
>
|
295
|
+
<AdvancedTable.Header
|
296
|
+
enableSorting
|
297
|
+
sortIcon= {["chevron-up","chevron-down"]}
|
298
|
+
/>
|
299
|
+
<AdvancedTable.Body />
|
300
|
+
</AdvancedTable>
|
301
|
+
);
|
302
|
+
|
303
|
+
const kit = screen.getByTestId(testId);
|
304
|
+
const sortIcon = kit.querySelector('.sort-button-icon')
|
305
|
+
const icon= sortIcon.querySelector(".pb_icon_kit")
|
306
|
+
expect(icon).toHaveClass("fa-chevron-down")
|
307
|
+
});
|
308
|
+
|
309
|
+
test("Sort icon renders with enableSorting + sortControl works as expected", () => {
|
310
|
+
render (<AdvancedTableSortControl/>)
|
311
|
+
|
312
|
+
const kit = screen.getByTestId(testId);
|
313
|
+
const sortIcon = kit.querySelector(".sort-button-icon")
|
314
|
+
expect(sortIcon).toBeInTheDocument()
|
315
|
+
|
316
|
+
const row1 = kit.getElementsByTagName('tr')[1]
|
317
|
+
|
318
|
+
expect(row1.id).toBe("1-1-0-row")
|
319
|
+
})
|
320
|
+
|
321
|
+
test("sort button exists and sorts column data", () => {
|
322
|
+
render(
|
323
|
+
<AdvancedTable
|
324
|
+
columnDefinitions={columnDefinitions}
|
325
|
+
data={{ testid: testId }}
|
326
|
+
tableData={MOCK_DATA}
|
327
|
+
>
|
328
|
+
<AdvancedTable.Header enableSorting />
|
329
|
+
<AdvancedTable.Body />
|
330
|
+
</AdvancedTable>
|
331
|
+
);
|
332
|
+
|
333
|
+
const kit = screen.getByTestId(testId);
|
334
|
+
|
335
|
+
const sortButton= kit.querySelector(".pb_flex_kit_orientation_row_justify_content_between_align_items_top_spacing_none.pl_xxs.cursor_pointer.header-sort-button.pb_th_link")
|
336
|
+
expect(sortButton).toBeInTheDocument()
|
337
|
+
|
338
|
+
const row1 = kit.getElementsByTagName('tr')[1]
|
339
|
+
|
340
|
+
expect(row1.id).toBe("0-0-0-row")
|
341
|
+
sortButton.click()
|
342
|
+
|
343
|
+
const row2 = kit.getElementsByTagName('tr')[2]
|
344
|
+
expect(row2.id).toBe("0-0-0-row")
|
345
|
+
});
|
346
|
+
|
347
|
+
test("Generates Table.Header default + custom classname", () => {
|
348
|
+
render(
|
349
|
+
<AdvancedTable
|
350
|
+
columnDefinitions={columnDefinitions}
|
351
|
+
data={{ testid: testId }}
|
352
|
+
tableData={MOCK_DATA}
|
353
|
+
>
|
354
|
+
<AdvancedTable.Header className="custom-header" />
|
355
|
+
<AdvancedTable.Body />
|
356
|
+
|
357
|
+
</AdvancedTable>
|
358
|
+
);
|
359
|
+
|
360
|
+
const kit = screen.getByTestId(testId);
|
361
|
+
const tableHeader = kit.querySelector('thead')
|
362
|
+
expect(tableHeader).toHaveClass('pb_advanced_table_header custom-header')
|
363
|
+
});
|
364
|
+
|
365
|
+
test("Generates Table.Body default + custom classname", () => {
|
366
|
+
render(
|
367
|
+
<AdvancedTable
|
368
|
+
columnDefinitions={columnDefinitions}
|
369
|
+
data={{ testid: testId }}
|
370
|
+
tableData={MOCK_DATA}
|
371
|
+
>
|
372
|
+
<AdvancedTable.Header />
|
373
|
+
<AdvancedTable.Body className="custom-body-classname"/>
|
374
|
+
|
375
|
+
</AdvancedTable>
|
376
|
+
);
|
377
|
+
|
378
|
+
const kit = screen.getByTestId(testId);
|
379
|
+
const tableHeader = kit.querySelector('tbody')
|
380
|
+
expect(tableHeader).toHaveClass('pb_advanced_table_body custom-body-classname')
|
56
381
|
});
|
@@ -0,0 +1,52 @@
|
|
1
|
+
import React from "react";
|
2
|
+
import { AdvancedTable } from "../../";
|
3
|
+
import { MOCK_DATA } from "./_mock_data";
|
4
|
+
|
5
|
+
const AdvancedTableCollapsibleTrail = (props) => {
|
6
|
+
const columnDefinitions = [
|
7
|
+
{
|
8
|
+
accessor: "year",
|
9
|
+
label: "Year",
|
10
|
+
cellAccessors: ["quarter", "month", "day"],
|
11
|
+
},
|
12
|
+
{
|
13
|
+
accessor: "newEnrollments",
|
14
|
+
label: "New Enrollments",
|
15
|
+
},
|
16
|
+
{
|
17
|
+
accessor: "scheduledMeetings",
|
18
|
+
label: "Scheduled Meetings",
|
19
|
+
},
|
20
|
+
{
|
21
|
+
accessor: "attendanceRate",
|
22
|
+
label: "Attendance Rate",
|
23
|
+
},
|
24
|
+
{
|
25
|
+
accessor: "completedClasses",
|
26
|
+
label: "Completed Classes",
|
27
|
+
},
|
28
|
+
{
|
29
|
+
accessor: "classCompletionRate",
|
30
|
+
label: "Class Completion Rate",
|
31
|
+
},
|
32
|
+
{
|
33
|
+
accessor: "graduatedStudents",
|
34
|
+
label: "Graduated Students",
|
35
|
+
},
|
36
|
+
];
|
37
|
+
|
38
|
+
return (
|
39
|
+
<div>
|
40
|
+
<AdvancedTable
|
41
|
+
columnDefinitions={columnDefinitions}
|
42
|
+
tableData={MOCK_DATA}
|
43
|
+
{...props}
|
44
|
+
>
|
45
|
+
<AdvancedTable.Header />
|
46
|
+
<AdvancedTable.Body collapsibleTrail={false} />
|
47
|
+
</AdvancedTable>
|
48
|
+
</div>
|
49
|
+
);
|
50
|
+
};
|
51
|
+
|
52
|
+
export default AdvancedTableCollapsibleTrail;
|
@@ -0,0 +1 @@
|
|
1
|
+
`collapsibleTrail` is an optional prop that is set to 'true' by default. If set to 'false', it will remove the trail on the left of rows when subRows are toggled open.
|
@@ -1,7 +1,12 @@
|
|
1
|
-
The AdvancedTable kit
|
1
|
+
The AdvancedTable kit accepts tree data and automatically renders expansion controls for nested subrows, to any depth, based on the data it is given. In it's simplest form, __the kit has two required props__:
|
2
2
|
|
3
|
-
|
3
|
+
### tableData
|
4
4
|
|
5
|
+
`tableData` accepts an array of objects as the table data. Each object is a table row, and each key:value pair within an object is a column value within that row. Nested children within a data object are automatically rendered as subrows under their parent row. Each parent row is prepended with expansion controls for toggling its nested child rows. The `toggleExpansionAll` button in the first column header can also be used to toggle expansion of all parent rows within the table.
|
6
|
+
|
7
|
+
For a visual of the data structure needed for `tableData`, see [here](https://github.com/powerhome/playbook/tree/master/playbook/app/pb_kits/playbook/pb_advanced_table#readme).
|
8
|
+
|
9
|
+
### columnDefinitions
|
5
10
|
|
6
11
|
`columnDefinitions` maps to the columns prop on the Tanstack table. Column definitions are the single most important part of building a table as they are responsible for building the underlying data model that is used for all sorting, expansion, etc. `ColumnDefinitions` in the AdvancedTable kit is a array of objects as seen in the code snippet below. Each object within the array has two REQUIRED items:
|
7
12
|
|
@@ -0,0 +1,59 @@
|
|
1
|
+
import React, { useState } from "react";
|
2
|
+
import { AdvancedTable } from "../../";
|
3
|
+
import { MOCK_DATA } from "./_mock_data";
|
4
|
+
|
5
|
+
const AdvancedTableExpandedControl = (props) => {
|
6
|
+
const columnDefinitions = [
|
7
|
+
{
|
8
|
+
accessor: "year",
|
9
|
+
label: "Year",
|
10
|
+
cellAccessors: ["quarter", "month", "day"],
|
11
|
+
},
|
12
|
+
{
|
13
|
+
accessor: "newEnrollments",
|
14
|
+
label: "New Enrollments",
|
15
|
+
},
|
16
|
+
{
|
17
|
+
accessor: "scheduledMeetings",
|
18
|
+
label: "Scheduled Meetings",
|
19
|
+
},
|
20
|
+
{
|
21
|
+
accessor: "attendanceRate",
|
22
|
+
label: "Attendance Rate",
|
23
|
+
},
|
24
|
+
{
|
25
|
+
accessor: "completedClasses",
|
26
|
+
label: "Completed Classes",
|
27
|
+
},
|
28
|
+
{
|
29
|
+
accessor: "classCompletionRate",
|
30
|
+
label: "Class Completion Rate",
|
31
|
+
},
|
32
|
+
{
|
33
|
+
accessor: "graduatedStudents",
|
34
|
+
label: "Graduated Students",
|
35
|
+
},
|
36
|
+
];
|
37
|
+
|
38
|
+
//State for manually effecting what is expanded
|
39
|
+
const [expanded, setExpanded] = useState({'0': true, '0.0': true, '0.0.1': true})
|
40
|
+
|
41
|
+
//Passing expanded state to AdvancedTable as prop
|
42
|
+
const expandedControl = {
|
43
|
+
value: expanded,
|
44
|
+
onChange: setExpanded,
|
45
|
+
}
|
46
|
+
|
47
|
+
return (
|
48
|
+
<div>
|
49
|
+
<AdvancedTable
|
50
|
+
columnDefinitions={columnDefinitions}
|
51
|
+
expandedControl={expandedControl}
|
52
|
+
tableData={MOCK_DATA}
|
53
|
+
{...props}
|
54
|
+
/>
|
55
|
+
</div>
|
56
|
+
);
|
57
|
+
};
|
58
|
+
|
59
|
+
export default AdvancedTableExpandedControl;
|
@@ -0,0 +1,18 @@
|
|
1
|
+
`expandedControl` is an optional prop that can be used to gain greater control over the expansion state of the Advanced Table. Tanstack handles expansion itself, however it does provide for a way to handle the state manually if needed. Usecases for this include needing to store the expansion state so it persists on page reload, set an initial expansion state, etc.
|
2
|
+
|
3
|
+
In this example we are showing that if initial expansion state is set, it will render the table expanded according to that state.
|
4
|
+
|
5
|
+
The expanded state must be an object with key/value pairs where the key is the row id and the value is a boolean, true or false. Tanstack by default assigns row ids based on index and depth of the row as can be seen in this example. For more information on row ids, see [here](https://tanstack.com/table/v8/docs/api/core/row#id).
|
6
|
+
|
7
|
+
### Single Row Expansion
|
8
|
+
|
9
|
+
By default, the click event on the row level toggleExpansion icon simply toggles the immediate sub rows open or closed. If you want to attach further logic to that button, the optional `onRowToggleClick` prop can be used. This click event provides one argument that can be hooked into: the current `row` object. Any additional functionality provided through this onClick will be applied in addition to the default.
|
10
|
+
|
11
|
+
### Multi-Row Expansion
|
12
|
+
|
13
|
+
Similar to the row level click event, the default of the click event on the toggleExpansion buttons that render in the first column header (and the subRow Header rows if prop enabled) toggles all top level rows open and closed. If you want to attach further logic to that button, the optional `onToggleExpansionClick` prop can be used. This click event provides one argument that can be hooked into: the current `row` object. Any additional functionality provided through this onClick will be applied in addition to the default.
|
14
|
+
|
15
|
+
### ToggleExpansionIcon
|
16
|
+
|
17
|
+
`ToggleExpansionIcon` is another optional prop that can be used to customize the icon for the toggleExpansion button. This prop takes a string value with the default set to `arrows-from-line`. All strings must be valid FA icons.
|
18
|
+
|
@@ -0,0 +1,60 @@
|
|
1
|
+
import React, { useState } from "react";
|
2
|
+
import { AdvancedTable } from "../../";
|
3
|
+
import { Button } from "../../"
|
4
|
+
import { MOCK_DATA } from "./_mock_data";
|
5
|
+
|
6
|
+
const AdvancedTableLoading = (props) => {
|
7
|
+
|
8
|
+
const [isloading, setIsLoading] = useState(true)
|
9
|
+
|
10
|
+
const columnDefinitions = [
|
11
|
+
{
|
12
|
+
accessor: "year",
|
13
|
+
label: "Year",
|
14
|
+
cellAccessors: ["quarter", "month", "day"],
|
15
|
+
},
|
16
|
+
{
|
17
|
+
accessor: "newEnrollments",
|
18
|
+
label: "New Enrollments",
|
19
|
+
},
|
20
|
+
{
|
21
|
+
accessor: "scheduledMeetings",
|
22
|
+
label: "Scheduled Meetings",
|
23
|
+
},
|
24
|
+
{
|
25
|
+
accessor: "attendanceRate",
|
26
|
+
label: "Attendance Rate",
|
27
|
+
},
|
28
|
+
{
|
29
|
+
accessor: "completedClasses",
|
30
|
+
label: "Completed Classes",
|
31
|
+
},
|
32
|
+
{
|
33
|
+
accessor: "classCompletionRate",
|
34
|
+
label: "Class Completion Rate",
|
35
|
+
},
|
36
|
+
{
|
37
|
+
accessor: "graduatedStudents",
|
38
|
+
label: "Graduated Students",
|
39
|
+
},
|
40
|
+
];
|
41
|
+
|
42
|
+
return (
|
43
|
+
<div>
|
44
|
+
<Button marginBottom="md"
|
45
|
+
onClick={()=> setIsLoading(!isloading)}
|
46
|
+
text="Toggle Loading State"
|
47
|
+
variant="secondary"
|
48
|
+
{...props}
|
49
|
+
/>
|
50
|
+
<AdvancedTable
|
51
|
+
columnDefinitions={columnDefinitions}
|
52
|
+
loading={isloading}
|
53
|
+
tableData={MOCK_DATA}
|
54
|
+
{...props}
|
55
|
+
/>
|
56
|
+
</div>
|
57
|
+
);
|
58
|
+
};
|
59
|
+
|
60
|
+
export default AdvancedTableLoading;
|
@@ -0,0 +1,3 @@
|
|
1
|
+
the optional `loading` prop takes a boolean value that can be managed using state. If loading is true, the table will display the loading skeleton and once loading is false, the table will render with the data provided.
|
2
|
+
|
3
|
+
By default, the inital row count of the loading skeleton is set to 10. If you want more control over this initial row count, the optional `initialLoadingRowCount` prop can be used to to pass in a number. __NOTE__: This is only for the first render of the table, subsequent loading skeleton row count logic is handled within the kit itself.
|
@@ -35,20 +35,15 @@ const AdvancedTableSort = (props) => {
|
|
35
35
|
},
|
36
36
|
];
|
37
37
|
|
38
|
-
//Render the subRow header rows
|
39
|
-
const subRowHeaders = ["Quarter", "Month", "Day"]
|
40
|
-
|
41
|
-
|
42
38
|
return (
|
43
39
|
<div>
|
44
40
|
<AdvancedTable
|
45
41
|
columnDefinitions={columnDefinitions}
|
46
|
-
enableToggleExpansion="all"
|
47
42
|
tableData={MOCK_DATA}
|
48
43
|
{...props}
|
49
44
|
>
|
50
45
|
<AdvancedTable.Header enableSorting />
|
51
|
-
<AdvancedTable.Body
|
46
|
+
<AdvancedTable.Body />
|
52
47
|
</AdvancedTable>
|
53
48
|
</div>
|
54
49
|
);
|
@@ -0,0 +1,5 @@
|
|
1
|
+
the `enableSorting` prop is a boolean prop set to false by default. If true, the table will add sort logic linked to the sort button in the header. Clicking the sort button will toggle sort between ascending and descending. Currently this sort functionality is only available on the first column.
|
2
|
+
|
3
|
+
### sortIcon
|
4
|
+
|
5
|
+
An optional prop, `sortIcon` allows you to customize your icon sets by passing it an array of any comma-separated pair of icon values. The first icon value will replace the kit's default icon when sort direction is desc, and the second value will replace the default icon when sort direction is asc. `sortIcon` also allows you to pass it a single icon as a string, in which case the icon will not toggle with the sort state. Default for this prop is `["arrow-up-short-wide", "arrow-down-short-wide"]`. All strings must be valid FA icons.
|
@@ -0,0 +1,63 @@
|
|
1
|
+
import React, { useState } from "react";
|
2
|
+
import { AdvancedTable } from "../..";
|
3
|
+
import { MOCK_DATA } from "./_mock_data";
|
4
|
+
|
5
|
+
const AdvancedTableSortControl = (props) => {
|
6
|
+
const columnDefinitions = [
|
7
|
+
{
|
8
|
+
accessor: "year",
|
9
|
+
label: "Year",
|
10
|
+
cellAccessors: ["quarter", "month", "day"],
|
11
|
+
},
|
12
|
+
{
|
13
|
+
accessor: "newEnrollments",
|
14
|
+
label: "New Enrollments",
|
15
|
+
},
|
16
|
+
{
|
17
|
+
accessor: "scheduledMeetings",
|
18
|
+
label: "Scheduled Meetings",
|
19
|
+
},
|
20
|
+
{
|
21
|
+
accessor: "attendanceRate",
|
22
|
+
label: "Attendance Rate",
|
23
|
+
},
|
24
|
+
{
|
25
|
+
accessor: "completedClasses",
|
26
|
+
label: "Completed Classes",
|
27
|
+
},
|
28
|
+
{
|
29
|
+
accessor: "classCompletionRate",
|
30
|
+
label: "Class Completion Rate",
|
31
|
+
},
|
32
|
+
{
|
33
|
+
accessor: "graduatedStudents",
|
34
|
+
label: "Graduated Students",
|
35
|
+
},
|
36
|
+
];
|
37
|
+
|
38
|
+
//State for sort direction
|
39
|
+
const [isSortDesc, setIsSortDesc] = useState({desc: false})
|
40
|
+
|
41
|
+
// //Passing sort state to AdvancedTable as prop
|
42
|
+
const sortControl = {
|
43
|
+
value: isSortDesc,
|
44
|
+
onChange: setIsSortDesc,
|
45
|
+
}
|
46
|
+
|
47
|
+
|
48
|
+
return (
|
49
|
+
<div>
|
50
|
+
<AdvancedTable
|
51
|
+
columnDefinitions={columnDefinitions}
|
52
|
+
sortControl={sortControl}
|
53
|
+
tableData={MOCK_DATA}
|
54
|
+
{...props}
|
55
|
+
>
|
56
|
+
<AdvancedTable.Header enableSorting />
|
57
|
+
<AdvancedTable.Body />
|
58
|
+
</AdvancedTable>
|
59
|
+
</div>
|
60
|
+
);
|
61
|
+
};
|
62
|
+
|
63
|
+
export default AdvancedTableSortControl;
|
@@ -0,0 +1,3 @@
|
|
1
|
+
`sortControl` is an optional prop that can be used to gain greater control over the sort state of the Advanced Table. Tanstack handles sort itself, however it does provide for a way to handle the state manually if needed. Usecases for this include needing to store the sort state so it persists on page reload, set an initial sort state, etc.
|
2
|
+
|
3
|
+
The sort state must be an object with a single key/value pair, with the key being "desc" and the value being a boolean. The default for sort directino is `desc: true`.
|