@patternfly/react-data-view 1.0.0-prerelease.4 → 5.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 (50) hide show
  1. package/dist/cjs/DataView/DataView.test.d.ts +1 -0
  2. package/dist/cjs/DataView/DataView.test.js +23 -0
  3. package/dist/cjs/DataViewToolbar/DataViewToolbar.d.ts +5 -3
  4. package/dist/cjs/DataViewToolbar/DataViewToolbar.js +3 -2
  5. package/dist/cjs/DataViewToolbar/DataViewToolbar.test.d.ts +1 -0
  6. package/dist/cjs/DataViewToolbar/DataViewToolbar.test.js +14 -0
  7. package/dist/cjs/Hooks/index.d.ts +1 -0
  8. package/dist/cjs/Hooks/index.js +1 -0
  9. package/dist/cjs/Hooks/pagination.d.ts +3 -0
  10. package/dist/cjs/Hooks/selection.d.ts +11 -0
  11. package/dist/cjs/Hooks/selection.js +26 -0
  12. package/dist/cjs/Hooks/selection.test.d.ts +1 -0
  13. package/dist/cjs/Hooks/selection.test.js +55 -0
  14. package/dist/esm/DataView/DataView.test.d.ts +1 -0
  15. package/dist/esm/DataView/DataView.test.js +18 -0
  16. package/dist/esm/DataViewToolbar/DataViewToolbar.d.ts +5 -3
  17. package/dist/esm/DataViewToolbar/DataViewToolbar.js +3 -2
  18. package/dist/esm/DataViewToolbar/DataViewToolbar.test.d.ts +1 -0
  19. package/dist/esm/DataViewToolbar/DataViewToolbar.test.js +9 -0
  20. package/dist/esm/Hooks/index.d.ts +1 -0
  21. package/dist/esm/Hooks/index.js +1 -0
  22. package/dist/esm/Hooks/pagination.d.ts +3 -0
  23. package/dist/esm/Hooks/selection.d.ts +11 -0
  24. package/dist/esm/Hooks/selection.js +22 -0
  25. package/dist/esm/Hooks/selection.test.d.ts +1 -0
  26. package/dist/esm/Hooks/selection.test.js +53 -0
  27. package/generate-fed-package-json.js +7 -8
  28. package/generate-index.js +2 -2
  29. package/package.json +8 -8
  30. package/patternfly-docs/content/extensions/data-view/examples/{DataViewToolbar/DataViewToolbar.md → Components/Components.md} +9 -5
  31. package/patternfly-docs/content/extensions/data-view/examples/Components/DataViewToolbarExample.tsx +20 -0
  32. package/patternfly-docs/content/extensions/data-view/examples/Functionality/Functionality.md +77 -0
  33. package/patternfly-docs/content/extensions/data-view/examples/{DataView/DataViewPredefinedLayoutExample.tsx → Functionality/PaginationExample.tsx} +2 -2
  34. package/patternfly-docs/content/extensions/data-view/examples/Functionality/SelectionExample.tsx +88 -0
  35. package/patternfly-docs/content/extensions/data-view/examples/{DataView/DataViewLayoutExample.tsx → Layout/AbstractLayoutExample.tsx} +4 -3
  36. package/patternfly-docs/content/extensions/data-view/examples/{DataView/DataView.md → Layout/Layout.md} +8 -6
  37. package/patternfly-docs/content/extensions/data-view/examples/Layout/PredefinedLayoutExample.tsx +120 -0
  38. package/patternfly-docs/pages/index.js +1 -1
  39. package/release.config.js +6 -2
  40. package/src/DataView/DataView.test.tsx +22 -0
  41. package/src/DataView/__snapshots__/DataView.test.tsx.snap +134 -0
  42. package/src/DataViewToolbar/DataViewToolbar.test.tsx +11 -0
  43. package/src/DataViewToolbar/DataViewToolbar.tsx +12 -5
  44. package/src/DataViewToolbar/__snapshots__/DataViewToolbar.test.tsx.snap +542 -0
  45. package/src/Hooks/index.ts +1 -0
  46. package/src/Hooks/pagination.ts +3 -0
  47. package/src/Hooks/selection.test.tsx +52 -0
  48. package/src/Hooks/selection.ts +32 -0
  49. package/patternfly-docs/content/extensions/data-view/examples/DataViewToolbar/DataViewToolbarExample.tsx +0 -7
  50. package/patternfly-docs/content/extensions/data-view/examples/Hooks/Hooks.md +0 -20
@@ -0,0 +1,542 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`DataViewToolbar component should render correctly 1`] = `
4
+ {
5
+ "asFragment": [Function],
6
+ "baseElement": <body>
7
+ <div>
8
+ <div
9
+ class="pf-v5-c-toolbar"
10
+ data-ouia-component-id="DataViewToolbar"
11
+ data-ouia-component-type="PF5/Toolbar"
12
+ data-ouia-safe="true"
13
+ id="pf-random-id-0"
14
+ >
15
+ <div
16
+ class="pf-v5-c-toolbar__content"
17
+ >
18
+ <div
19
+ class="pf-v5-c-toolbar__content-section"
20
+ >
21
+ <div
22
+ class="pf-v5-c-toolbar__item pf-m-pagination"
23
+ data-ouia-component-id="DataViewToolbar-pagination"
24
+ >
25
+ <div
26
+ class="pf-v5-c-pagination"
27
+ data-ouia-component-id="OUIA-Generated-Pagination-top-1"
28
+ data-ouia-component-type="PF5/Pagination"
29
+ data-ouia-safe="true"
30
+ id="options-menu-top-pagination"
31
+ style="--pf-v5-c-pagination__nav-page-select--c-form-control--width-chars: 2;"
32
+ >
33
+ <div
34
+ class="pf-v5-c-pagination__total-items"
35
+ >
36
+ <b>
37
+ 1
38
+ -
39
+ 10
40
+ </b>
41
+
42
+ of
43
+
44
+ <b>
45
+ 0
46
+ </b>
47
+
48
+ </div>
49
+ <div>
50
+ <button
51
+ aria-expanded="false"
52
+ aria-haspopup="listbox"
53
+ class="pf-v5-c-menu-toggle pf-m-plain pf-m-text"
54
+ id="options-menu-top-toggle"
55
+ type="button"
56
+ >
57
+ <span
58
+ class="pf-v5-c-menu-toggle__text"
59
+ >
60
+ <b>
61
+ 1
62
+ -
63
+ 10
64
+ </b>
65
+
66
+ of
67
+
68
+ <b>
69
+ 0
70
+ </b>
71
+
72
+ </span>
73
+ <span
74
+ class="pf-v5-c-menu-toggle__controls"
75
+ >
76
+ <span
77
+ class="pf-v5-c-menu-toggle__toggle-icon"
78
+ >
79
+ <svg
80
+ aria-hidden="true"
81
+ class="pf-v5-svg"
82
+ fill="currentColor"
83
+ height="1em"
84
+ role="img"
85
+ viewBox="0 0 320 512"
86
+ width="1em"
87
+ >
88
+ <path
89
+ d="M31.3 192h257.3c17.8 0 26.7 21.5 14.1 34.1L174.1 354.8c-7.8 7.8-20.5 7.8-28.3 0L17.2 226.1C4.6 213.5 13.5 192 31.3 192z"
90
+ />
91
+ </svg>
92
+ </span>
93
+ </span>
94
+ </button>
95
+ </div>
96
+ <nav
97
+ aria-label="Pagination"
98
+ class="pf-v5-c-pagination__nav"
99
+ >
100
+ <div
101
+ class="pf-v5-c-pagination__nav-control pf-m-first"
102
+ >
103
+ <button
104
+ aria-disabled="true"
105
+ aria-label="Go to first page"
106
+ class="pf-v5-c-button pf-m-plain pf-m-disabled"
107
+ data-action="first"
108
+ data-ouia-component-id="OUIA-Generated-Button-plain-1"
109
+ data-ouia-component-type="PF5/Button"
110
+ data-ouia-safe="true"
111
+ disabled=""
112
+ type="button"
113
+ >
114
+ <svg
115
+ aria-hidden="true"
116
+ class="pf-v5-svg"
117
+ fill="currentColor"
118
+ height="1em"
119
+ role="img"
120
+ viewBox="0 0 448 512"
121
+ width="1em"
122
+ >
123
+ <path
124
+ d="M223.7 239l136-136c9.4-9.4 24.6-9.4 33.9 0l22.6 22.6c9.4 9.4 9.4 24.6 0 33.9L319.9 256l96.4 96.4c9.4 9.4 9.4 24.6 0 33.9L393.7 409c-9.4 9.4-24.6 9.4-33.9 0l-136-136c-9.5-9.4-9.5-24.6-.1-34zm-192 34l136 136c9.4 9.4 24.6 9.4 33.9 0l22.6-22.6c9.4-9.4 9.4-24.6 0-33.9L127.9 256l96.4-96.4c9.4-9.4 9.4-24.6 0-33.9L201.7 103c-9.4-9.4-24.6-9.4-33.9 0l-136 136c-9.5 9.4-9.5 24.6-.1 34z"
125
+ />
126
+ </svg>
127
+ </button>
128
+ </div>
129
+ <div
130
+ class="pf-v5-c-pagination__nav-control"
131
+ >
132
+ <button
133
+ aria-disabled="true"
134
+ aria-label="Go to previous page"
135
+ class="pf-v5-c-button pf-m-plain pf-m-disabled"
136
+ data-action="previous"
137
+ data-ouia-component-id="OUIA-Generated-Button-plain-2"
138
+ data-ouia-component-type="PF5/Button"
139
+ data-ouia-safe="true"
140
+ disabled=""
141
+ type="button"
142
+ >
143
+ <svg
144
+ aria-hidden="true"
145
+ class="pf-v5-svg"
146
+ fill="currentColor"
147
+ height="1em"
148
+ role="img"
149
+ viewBox="0 0 256 512"
150
+ width="1em"
151
+ >
152
+ <path
153
+ d="M31.7 239l136-136c9.4-9.4 24.6-9.4 33.9 0l22.6 22.6c9.4 9.4 9.4 24.6 0 33.9L127.9 256l96.4 96.4c9.4 9.4 9.4 24.6 0 33.9L201.7 409c-9.4 9.4-24.6 9.4-33.9 0l-136-136c-9.5-9.4-9.5-24.6-.1-34z"
154
+ />
155
+ </svg>
156
+ </button>
157
+ </div>
158
+ <div
159
+ class="pf-v5-c-pagination__nav-page-select"
160
+ >
161
+ <span
162
+ class="pf-v5-c-form-control"
163
+ >
164
+ <input
165
+ aria-invalid="false"
166
+ aria-label="Current page"
167
+ data-ouia-component-id="OUIA-Generated-TextInputBase-1"
168
+ data-ouia-component-type="PF5/TextInput"
169
+ data-ouia-safe="true"
170
+ max="2"
171
+ min="1"
172
+ type="number"
173
+ value="1"
174
+ />
175
+ </span>
176
+ </div>
177
+ <div
178
+ class="pf-v5-c-pagination__nav-control"
179
+ >
180
+ <button
181
+ aria-disabled="false"
182
+ aria-label="Go to next page"
183
+ class="pf-v5-c-button pf-m-plain"
184
+ data-action="next"
185
+ data-ouia-component-id="OUIA-Generated-Button-plain-3"
186
+ data-ouia-component-type="PF5/Button"
187
+ data-ouia-safe="true"
188
+ type="button"
189
+ >
190
+ <svg
191
+ aria-hidden="true"
192
+ class="pf-v5-svg"
193
+ fill="currentColor"
194
+ height="1em"
195
+ role="img"
196
+ viewBox="0 0 256 512"
197
+ width="1em"
198
+ >
199
+ <path
200
+ d="M224.3 273l-136 136c-9.4 9.4-24.6 9.4-33.9 0l-22.6-22.6c-9.4-9.4-9.4-24.6 0-33.9l96.4-96.4-96.4-96.4c-9.4-9.4-9.4-24.6 0-33.9L54.3 103c9.4-9.4 24.6-9.4 33.9 0l136 136c9.5 9.4 9.5 24.6.1 34z"
201
+ />
202
+ </svg>
203
+ </button>
204
+ </div>
205
+ <div
206
+ class="pf-v5-c-pagination__nav-control pf-m-last"
207
+ >
208
+ <button
209
+ aria-disabled="false"
210
+ aria-label="Go to last page"
211
+ class="pf-v5-c-button pf-m-plain"
212
+ data-action="last"
213
+ data-ouia-component-id="OUIA-Generated-Button-plain-4"
214
+ data-ouia-component-type="PF5/Button"
215
+ data-ouia-safe="true"
216
+ type="button"
217
+ >
218
+ <svg
219
+ aria-hidden="true"
220
+ class="pf-v5-svg"
221
+ fill="currentColor"
222
+ height="1em"
223
+ role="img"
224
+ viewBox="0 0 448 512"
225
+ width="1em"
226
+ >
227
+ <path
228
+ d="M224.3 273l-136 136c-9.4 9.4-24.6 9.4-33.9 0l-22.6-22.6c-9.4-9.4-9.4-24.6 0-33.9l96.4-96.4-96.4-96.4c-9.4-9.4-9.4-24.6 0-33.9L54.3 103c9.4-9.4 24.6-9.4 33.9 0l136 136c9.5 9.4 9.5 24.6.1 34zm192-34l-136-136c-9.4-9.4-24.6-9.4-33.9 0l-22.6 22.6c-9.4 9.4-9.4 24.6 0 33.9l96.4 96.4-96.4 96.4c-9.4 9.4-9.4 24.6 0 33.9l22.6 22.6c9.4 9.4 24.6 9.4 33.9 0l136-136c9.4-9.2 9.4-24.4 0-33.8z"
229
+ />
230
+ </svg>
231
+ </button>
232
+ </div>
233
+ </nav>
234
+ </div>
235
+ </div>
236
+ </div>
237
+ </div>
238
+ <div
239
+ class="pf-v5-c-toolbar__content pf-m-hidden"
240
+ hidden=""
241
+ >
242
+ <div
243
+ class="pf-v5-c-toolbar__group"
244
+ />
245
+ </div>
246
+ </div>
247
+ </div>
248
+ </body>,
249
+ "container": <div>
250
+ <div
251
+ class="pf-v5-c-toolbar"
252
+ data-ouia-component-id="DataViewToolbar"
253
+ data-ouia-component-type="PF5/Toolbar"
254
+ data-ouia-safe="true"
255
+ id="pf-random-id-0"
256
+ >
257
+ <div
258
+ class="pf-v5-c-toolbar__content"
259
+ >
260
+ <div
261
+ class="pf-v5-c-toolbar__content-section"
262
+ >
263
+ <div
264
+ class="pf-v5-c-toolbar__item pf-m-pagination"
265
+ data-ouia-component-id="DataViewToolbar-pagination"
266
+ >
267
+ <div
268
+ class="pf-v5-c-pagination"
269
+ data-ouia-component-id="OUIA-Generated-Pagination-top-1"
270
+ data-ouia-component-type="PF5/Pagination"
271
+ data-ouia-safe="true"
272
+ id="options-menu-top-pagination"
273
+ style="--pf-v5-c-pagination__nav-page-select--c-form-control--width-chars: 2;"
274
+ >
275
+ <div
276
+ class="pf-v5-c-pagination__total-items"
277
+ >
278
+ <b>
279
+ 1
280
+ -
281
+ 10
282
+ </b>
283
+
284
+ of
285
+
286
+ <b>
287
+ 0
288
+ </b>
289
+
290
+ </div>
291
+ <div>
292
+ <button
293
+ aria-expanded="false"
294
+ aria-haspopup="listbox"
295
+ class="pf-v5-c-menu-toggle pf-m-plain pf-m-text"
296
+ id="options-menu-top-toggle"
297
+ type="button"
298
+ >
299
+ <span
300
+ class="pf-v5-c-menu-toggle__text"
301
+ >
302
+ <b>
303
+ 1
304
+ -
305
+ 10
306
+ </b>
307
+
308
+ of
309
+
310
+ <b>
311
+ 0
312
+ </b>
313
+
314
+ </span>
315
+ <span
316
+ class="pf-v5-c-menu-toggle__controls"
317
+ >
318
+ <span
319
+ class="pf-v5-c-menu-toggle__toggle-icon"
320
+ >
321
+ <svg
322
+ aria-hidden="true"
323
+ class="pf-v5-svg"
324
+ fill="currentColor"
325
+ height="1em"
326
+ role="img"
327
+ viewBox="0 0 320 512"
328
+ width="1em"
329
+ >
330
+ <path
331
+ d="M31.3 192h257.3c17.8 0 26.7 21.5 14.1 34.1L174.1 354.8c-7.8 7.8-20.5 7.8-28.3 0L17.2 226.1C4.6 213.5 13.5 192 31.3 192z"
332
+ />
333
+ </svg>
334
+ </span>
335
+ </span>
336
+ </button>
337
+ </div>
338
+ <nav
339
+ aria-label="Pagination"
340
+ class="pf-v5-c-pagination__nav"
341
+ >
342
+ <div
343
+ class="pf-v5-c-pagination__nav-control pf-m-first"
344
+ >
345
+ <button
346
+ aria-disabled="true"
347
+ aria-label="Go to first page"
348
+ class="pf-v5-c-button pf-m-plain pf-m-disabled"
349
+ data-action="first"
350
+ data-ouia-component-id="OUIA-Generated-Button-plain-1"
351
+ data-ouia-component-type="PF5/Button"
352
+ data-ouia-safe="true"
353
+ disabled=""
354
+ type="button"
355
+ >
356
+ <svg
357
+ aria-hidden="true"
358
+ class="pf-v5-svg"
359
+ fill="currentColor"
360
+ height="1em"
361
+ role="img"
362
+ viewBox="0 0 448 512"
363
+ width="1em"
364
+ >
365
+ <path
366
+ d="M223.7 239l136-136c9.4-9.4 24.6-9.4 33.9 0l22.6 22.6c9.4 9.4 9.4 24.6 0 33.9L319.9 256l96.4 96.4c9.4 9.4 9.4 24.6 0 33.9L393.7 409c-9.4 9.4-24.6 9.4-33.9 0l-136-136c-9.5-9.4-9.5-24.6-.1-34zm-192 34l136 136c9.4 9.4 24.6 9.4 33.9 0l22.6-22.6c9.4-9.4 9.4-24.6 0-33.9L127.9 256l96.4-96.4c9.4-9.4 9.4-24.6 0-33.9L201.7 103c-9.4-9.4-24.6-9.4-33.9 0l-136 136c-9.5 9.4-9.5 24.6-.1 34z"
367
+ />
368
+ </svg>
369
+ </button>
370
+ </div>
371
+ <div
372
+ class="pf-v5-c-pagination__nav-control"
373
+ >
374
+ <button
375
+ aria-disabled="true"
376
+ aria-label="Go to previous page"
377
+ class="pf-v5-c-button pf-m-plain pf-m-disabled"
378
+ data-action="previous"
379
+ data-ouia-component-id="OUIA-Generated-Button-plain-2"
380
+ data-ouia-component-type="PF5/Button"
381
+ data-ouia-safe="true"
382
+ disabled=""
383
+ type="button"
384
+ >
385
+ <svg
386
+ aria-hidden="true"
387
+ class="pf-v5-svg"
388
+ fill="currentColor"
389
+ height="1em"
390
+ role="img"
391
+ viewBox="0 0 256 512"
392
+ width="1em"
393
+ >
394
+ <path
395
+ d="M31.7 239l136-136c9.4-9.4 24.6-9.4 33.9 0l22.6 22.6c9.4 9.4 9.4 24.6 0 33.9L127.9 256l96.4 96.4c9.4 9.4 9.4 24.6 0 33.9L201.7 409c-9.4 9.4-24.6 9.4-33.9 0l-136-136c-9.5-9.4-9.5-24.6-.1-34z"
396
+ />
397
+ </svg>
398
+ </button>
399
+ </div>
400
+ <div
401
+ class="pf-v5-c-pagination__nav-page-select"
402
+ >
403
+ <span
404
+ class="pf-v5-c-form-control"
405
+ >
406
+ <input
407
+ aria-invalid="false"
408
+ aria-label="Current page"
409
+ data-ouia-component-id="OUIA-Generated-TextInputBase-1"
410
+ data-ouia-component-type="PF5/TextInput"
411
+ data-ouia-safe="true"
412
+ max="2"
413
+ min="1"
414
+ type="number"
415
+ value="1"
416
+ />
417
+ </span>
418
+ </div>
419
+ <div
420
+ class="pf-v5-c-pagination__nav-control"
421
+ >
422
+ <button
423
+ aria-disabled="false"
424
+ aria-label="Go to next page"
425
+ class="pf-v5-c-button pf-m-plain"
426
+ data-action="next"
427
+ data-ouia-component-id="OUIA-Generated-Button-plain-3"
428
+ data-ouia-component-type="PF5/Button"
429
+ data-ouia-safe="true"
430
+ type="button"
431
+ >
432
+ <svg
433
+ aria-hidden="true"
434
+ class="pf-v5-svg"
435
+ fill="currentColor"
436
+ height="1em"
437
+ role="img"
438
+ viewBox="0 0 256 512"
439
+ width="1em"
440
+ >
441
+ <path
442
+ d="M224.3 273l-136 136c-9.4 9.4-24.6 9.4-33.9 0l-22.6-22.6c-9.4-9.4-9.4-24.6 0-33.9l96.4-96.4-96.4-96.4c-9.4-9.4-9.4-24.6 0-33.9L54.3 103c9.4-9.4 24.6-9.4 33.9 0l136 136c9.5 9.4 9.5 24.6.1 34z"
443
+ />
444
+ </svg>
445
+ </button>
446
+ </div>
447
+ <div
448
+ class="pf-v5-c-pagination__nav-control pf-m-last"
449
+ >
450
+ <button
451
+ aria-disabled="false"
452
+ aria-label="Go to last page"
453
+ class="pf-v5-c-button pf-m-plain"
454
+ data-action="last"
455
+ data-ouia-component-id="OUIA-Generated-Button-plain-4"
456
+ data-ouia-component-type="PF5/Button"
457
+ data-ouia-safe="true"
458
+ type="button"
459
+ >
460
+ <svg
461
+ aria-hidden="true"
462
+ class="pf-v5-svg"
463
+ fill="currentColor"
464
+ height="1em"
465
+ role="img"
466
+ viewBox="0 0 448 512"
467
+ width="1em"
468
+ >
469
+ <path
470
+ d="M224.3 273l-136 136c-9.4 9.4-24.6 9.4-33.9 0l-22.6-22.6c-9.4-9.4-9.4-24.6 0-33.9l96.4-96.4-96.4-96.4c-9.4-9.4-9.4-24.6 0-33.9L54.3 103c9.4-9.4 24.6-9.4 33.9 0l136 136c9.5 9.4 9.5 24.6.1 34zm192-34l-136-136c-9.4-9.4-24.6-9.4-33.9 0l-22.6 22.6c-9.4 9.4-9.4 24.6 0 33.9l96.4 96.4-96.4 96.4c-9.4 9.4-9.4 24.6 0 33.9l22.6 22.6c9.4 9.4 24.6 9.4 33.9 0l136-136c9.4-9.2 9.4-24.4 0-33.8z"
471
+ />
472
+ </svg>
473
+ </button>
474
+ </div>
475
+ </nav>
476
+ </div>
477
+ </div>
478
+ </div>
479
+ </div>
480
+ <div
481
+ class="pf-v5-c-toolbar__content pf-m-hidden"
482
+ hidden=""
483
+ >
484
+ <div
485
+ class="pf-v5-c-toolbar__group"
486
+ />
487
+ </div>
488
+ </div>
489
+ </div>,
490
+ "debug": [Function],
491
+ "findAllByAltText": [Function],
492
+ "findAllByDisplayValue": [Function],
493
+ "findAllByLabelText": [Function],
494
+ "findAllByPlaceholderText": [Function],
495
+ "findAllByRole": [Function],
496
+ "findAllByTestId": [Function],
497
+ "findAllByText": [Function],
498
+ "findAllByTitle": [Function],
499
+ "findByAltText": [Function],
500
+ "findByDisplayValue": [Function],
501
+ "findByLabelText": [Function],
502
+ "findByPlaceholderText": [Function],
503
+ "findByRole": [Function],
504
+ "findByTestId": [Function],
505
+ "findByText": [Function],
506
+ "findByTitle": [Function],
507
+ "getAllByAltText": [Function],
508
+ "getAllByDisplayValue": [Function],
509
+ "getAllByLabelText": [Function],
510
+ "getAllByPlaceholderText": [Function],
511
+ "getAllByRole": [Function],
512
+ "getAllByTestId": [Function],
513
+ "getAllByText": [Function],
514
+ "getAllByTitle": [Function],
515
+ "getByAltText": [Function],
516
+ "getByDisplayValue": [Function],
517
+ "getByLabelText": [Function],
518
+ "getByPlaceholderText": [Function],
519
+ "getByRole": [Function],
520
+ "getByTestId": [Function],
521
+ "getByText": [Function],
522
+ "getByTitle": [Function],
523
+ "queryAllByAltText": [Function],
524
+ "queryAllByDisplayValue": [Function],
525
+ "queryAllByLabelText": [Function],
526
+ "queryAllByPlaceholderText": [Function],
527
+ "queryAllByRole": [Function],
528
+ "queryAllByTestId": [Function],
529
+ "queryAllByText": [Function],
530
+ "queryAllByTitle": [Function],
531
+ "queryByAltText": [Function],
532
+ "queryByDisplayValue": [Function],
533
+ "queryByLabelText": [Function],
534
+ "queryByPlaceholderText": [Function],
535
+ "queryByRole": [Function],
536
+ "queryByTestId": [Function],
537
+ "queryByText": [Function],
538
+ "queryByTitle": [Function],
539
+ "rerender": [Function],
540
+ "unmount": [Function],
541
+ }
542
+ `;
@@ -1 +1,2 @@
1
1
  export * from './pagination';
2
+ export * from './selection';
@@ -1,11 +1,14 @@
1
1
  import { useState } from "react";
2
2
 
3
3
  export interface UseDataViewPaginationProps {
4
+ /** Initial page */
4
5
  page?: number;
6
+ /** Items per page */
5
7
  perPage: number;
6
8
  }
7
9
 
8
10
  export interface DataViewPaginationProps extends UseDataViewPaginationProps {
11
+ /** Current page number */
9
12
  page: number;
10
13
  }
11
14
 
@@ -0,0 +1,52 @@
1
+ import '@testing-library/jest-dom';
2
+ import { renderHook, act } from '@testing-library/react';
3
+ import { useDataViewSelection } from './selection';
4
+
5
+ describe('useDataViewSelection', () => {
6
+ it('should get initial state correctly - no initialSelected', () => {
7
+ const { result } = renderHook(() => useDataViewSelection({}))
8
+ expect(result.current).toEqual({
9
+ selected: [],
10
+ onSelect: expect.any(Function),
11
+ isSelected: expect.any(Function),
12
+ })
13
+ });
14
+
15
+ it('should get initial state correctly - with initialSelected', () => {
16
+ const initialSelected = [ { id: 1, name: 'test1' } ];
17
+ const { result } = renderHook(() => useDataViewSelection({ initialSelected }))
18
+ expect(result.current).toEqual({
19
+ selected: initialSelected,
20
+ onSelect: expect.any(Function),
21
+ isSelected: expect.any(Function),
22
+ })
23
+ });
24
+
25
+ it('should select items correctly - objects', async () => {
26
+ const initialSelected = [ { id: 1, name: 'test1' } ];
27
+ const { result } = renderHook(() => useDataViewSelection({ initialSelected }))
28
+
29
+ await act(async () => {
30
+ result.current.onSelect(true, { id: 2, name: 'test2' });
31
+ });
32
+ expect(result.current.selected).toEqual([ ...initialSelected, { id: 2, name: 'test2' } ]);
33
+ });
34
+
35
+ it('should deselect items correctly - strings', async () => {
36
+ const initialSelected = [ 'test1', 'test2' ];
37
+ const { result } = renderHook(() => useDataViewSelection({ initialSelected }))
38
+
39
+ await act(async () => {
40
+ result.current.onSelect(false, 'test2');
41
+ });
42
+ expect(result.current.selected).toEqual([ 'test1' ])
43
+ });
44
+
45
+ it('should check if item is selected correctly - objects', () => {
46
+ const initialSelected = [ { id: 1, name: 'test1' }, { id: 2, name: 'test2' } ];
47
+ const { result } = renderHook(() => useDataViewSelection({ initialSelected, matchOption: (a,b) => a.id === b.id }))
48
+
49
+ expect(result.current.isSelected({ id: 1, name: 'test1' })).toBe(true);
50
+ expect(result.current.isSelected({ id: 3, name: 'test2' })).toBe(false);
51
+ });
52
+ });
@@ -0,0 +1,32 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ import { useState } from "react";
3
+
4
+ export interface UseDataViewSelectionProps {
5
+ /** Array of initially selected entries */
6
+ initialSelected?: (any)[];
7
+ /** Function to compare items when checking if entry is selected */
8
+ matchOption?: (item: any, another: any) => boolean;
9
+ }
10
+
11
+ export const useDataViewSelection = (props: UseDataViewSelectionProps) => {
12
+ const [ selected, setSelected ] = useState<any[]>(props.initialSelected ?? []);
13
+ const matchOption = props.matchOption ? props.matchOption : (option, another) => (option === another);
14
+
15
+ const onSelect = (isSelecting: boolean, items?: any[] | any) => {
16
+ isSelecting ?
17
+ setSelected(prev => {
18
+ const newSelectedItems = [ ...prev ];
19
+ (Array.isArray(items) ? items : [ items ]).forEach(newItem => !prev.some(prevItem => matchOption(prevItem, newItem)) && newSelectedItems.push(newItem));
20
+ return newSelectedItems;
21
+ })
22
+ : setSelected(items ? prev => prev.filter(prevSelected => !(Array.isArray(items) ? items : [ items ]).some(item => matchOption(item, prevSelected))) : []);
23
+ };
24
+
25
+ const isSelected = (item: any): boolean => props?.matchOption ? Boolean(selected.find(selected => matchOption(selected, item))) : selected.includes(item);
26
+
27
+ return {
28
+ selected,
29
+ onSelect,
30
+ isSelected
31
+ };
32
+ };
@@ -1,7 +0,0 @@
1
- import React from 'react';
2
- import { Pagination } from '@patternfly/react-core';
3
- import DataViewToolbar from '@patternfly/react-data-view/dist/dynamic/DataViewToolbar';
4
-
5
- export const BasicExample: React.FunctionComponent = () => (
6
- <DataViewToolbar pagination={<Pagination page={1} perPage={10} />} />
7
- )
@@ -1,20 +0,0 @@
1
- ---
2
- # Sidenav top-level section
3
- # should be the same for all markdown files
4
- section: extensions
5
- subsection: Data view
6
- # Sidenav secondary level section
7
- # should be the same for all markdown files
8
- id: Hooks
9
- # Tab (react | react-demos | html | html-demos | design-guidelines | accessibility)
10
- source: react
11
- # If you use typescript, the name of the interface to display props for
12
- # These are found through the sourceProps function provided in patternfly-docs.source.js
13
- propComponents: []
14
- sourceLink: https://github.com/patternfly/react-data-view/blob/main/packages/module/patternfly-docs/content/extensions/data-view/examples/Hooks/Hooks.md
15
- ---
16
- Data view hooks provide a predefined solution to manage state of the data view. This modular approach allows them to be easily replaced with a custom implementation in case of more specific needs.
17
-
18
- ### useDataViewPagination()
19
-
20
- The `useDataViewPagination` hook manages the pagination state of the data view. It retrieves the current `page` and `perPage` values together with functions to set them (`onSetPage`, `onPerPageSelect`). You can easily spread the retrieved values to the PatternFly [pagination](/components/pagination) component and make it live.