@patternfly/react-data-view 1.0.0-prerelease.4 → 1.0.0-prerelease.5

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 (48) hide show
  1. package/dist/cjs/DataView/DataView.test.d.ts +1 -0
  2. package/dist/cjs/DataView/DataView.test.js +22 -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 +17 -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 +7 -6
  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/DataView.md → Layout/Layout.md} +8 -6
  36. package/patternfly-docs/content/extensions/data-view/examples/Layout/PredefinedLayoutExample.tsx +120 -0
  37. package/src/DataView/DataView.test.tsx +21 -0
  38. package/src/DataView/__snapshots__/DataView.test.tsx.snap +134 -0
  39. package/src/DataViewToolbar/DataViewToolbar.test.tsx +11 -0
  40. package/src/DataViewToolbar/DataViewToolbar.tsx +12 -5
  41. package/src/DataViewToolbar/__snapshots__/DataViewToolbar.test.tsx.snap +538 -0
  42. package/src/Hooks/index.ts +1 -0
  43. package/src/Hooks/pagination.ts +3 -0
  44. package/src/Hooks/selection.test.tsx +52 -0
  45. package/src/Hooks/selection.ts +32 -0
  46. package/patternfly-docs/content/extensions/data-view/examples/DataViewToolbar/DataViewToolbarExample.tsx +0 -7
  47. package/patternfly-docs/content/extensions/data-view/examples/Hooks/Hooks.md +0 -20
  48. /package/patternfly-docs/content/extensions/data-view/examples/{DataView/DataViewLayoutExample.tsx → Layout/AbstractLayoutExample.tsx} +0 -0
@@ -0,0 +1,538 @@
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-v6-c-toolbar"
10
+ data-ouia-component-id="DataViewToolbar"
11
+ data-ouia-component-type="PF6/Toolbar"
12
+ data-ouia-safe="true"
13
+ id="pf-random-id-0"
14
+ >
15
+ <div
16
+ class="pf-v6-c-toolbar__content"
17
+ >
18
+ <div
19
+ class="pf-v6-c-toolbar__content-section"
20
+ >
21
+ <div
22
+ class="pf-v6-c-toolbar__item pf-m-pagination"
23
+ data-ouia-component-id="DataViewToolbar-pagination"
24
+ >
25
+ <div
26
+ class="pf-v6-c-pagination"
27
+ data-ouia-component-id="OUIA-Generated-Pagination-top-1"
28
+ data-ouia-component-type="PF6/Pagination"
29
+ data-ouia-safe="true"
30
+ id="options-menu-top-pagination"
31
+ style="--pf-v6-c-pagination__nav-page-select--c-form-control--width-chars: 2;"
32
+ >
33
+ <div
34
+ class="pf-v6-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
+ <button
50
+ aria-expanded="false"
51
+ aria-haspopup="listbox"
52
+ class="pf-v6-c-menu-toggle pf-m-plain pf-m-text"
53
+ id="options-menu-top-toggle"
54
+ type="button"
55
+ >
56
+ <span
57
+ class="pf-v6-c-menu-toggle__text"
58
+ >
59
+ <b>
60
+ 1
61
+ -
62
+ 10
63
+ </b>
64
+
65
+ of
66
+
67
+ <b>
68
+ 0
69
+ </b>
70
+
71
+ </span>
72
+ <span
73
+ class="pf-v6-c-menu-toggle__controls"
74
+ >
75
+ <span
76
+ class="pf-v6-c-menu-toggle__toggle-icon"
77
+ >
78
+ <svg
79
+ aria-hidden="true"
80
+ class="pf-v6-svg"
81
+ fill="currentColor"
82
+ height="1em"
83
+ role="img"
84
+ viewBox="0 0 320 512"
85
+ width="1em"
86
+ >
87
+ <path
88
+ 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"
89
+ />
90
+ </svg>
91
+ </span>
92
+ </span>
93
+ </button>
94
+ <nav
95
+ aria-label="Pagination"
96
+ class="pf-v6-c-pagination__nav"
97
+ >
98
+ <div
99
+ class="pf-v6-c-pagination__nav-control pf-m-first"
100
+ >
101
+ <button
102
+ aria-disabled="false"
103
+ aria-label="Go to first page"
104
+ class="pf-v6-c-button pf-m-plain"
105
+ data-action="first"
106
+ data-ouia-component-id="OUIA-Generated-Button-plain-1"
107
+ data-ouia-component-type="PF6/Button"
108
+ data-ouia-safe="true"
109
+ disabled=""
110
+ type="button"
111
+ >
112
+ <svg
113
+ aria-hidden="true"
114
+ class="pf-v6-svg"
115
+ fill="currentColor"
116
+ height="1em"
117
+ role="img"
118
+ viewBox="0 0 448 512"
119
+ width="1em"
120
+ >
121
+ <path
122
+ 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"
123
+ />
124
+ </svg>
125
+ </button>
126
+ </div>
127
+ <div
128
+ class="pf-v6-c-pagination__nav-control"
129
+ >
130
+ <button
131
+ aria-disabled="false"
132
+ aria-label="Go to previous page"
133
+ class="pf-v6-c-button pf-m-plain"
134
+ data-action="previous"
135
+ data-ouia-component-id="OUIA-Generated-Button-plain-2"
136
+ data-ouia-component-type="PF6/Button"
137
+ data-ouia-safe="true"
138
+ disabled=""
139
+ type="button"
140
+ >
141
+ <svg
142
+ aria-hidden="true"
143
+ class="pf-v6-svg"
144
+ fill="currentColor"
145
+ height="1em"
146
+ role="img"
147
+ viewBox="0 0 256 512"
148
+ width="1em"
149
+ >
150
+ <path
151
+ 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"
152
+ />
153
+ </svg>
154
+ </button>
155
+ </div>
156
+ <div
157
+ class="pf-v6-c-pagination__nav-page-select"
158
+ >
159
+ <span
160
+ class="pf-v6-c-form-control"
161
+ >
162
+ <input
163
+ aria-invalid="false"
164
+ aria-label="Current page"
165
+ data-ouia-component-id="OUIA-Generated-TextInputBase-1"
166
+ data-ouia-component-type="PF6/TextInput"
167
+ data-ouia-safe="true"
168
+ max="2"
169
+ min="1"
170
+ type="number"
171
+ value="1"
172
+ />
173
+ </span>
174
+ </div>
175
+ <div
176
+ class="pf-v6-c-pagination__nav-control"
177
+ >
178
+ <button
179
+ aria-disabled="false"
180
+ aria-label="Go to next page"
181
+ class="pf-v6-c-button pf-m-plain"
182
+ data-action="next"
183
+ data-ouia-component-id="OUIA-Generated-Button-plain-3"
184
+ data-ouia-component-type="PF6/Button"
185
+ data-ouia-safe="true"
186
+ type="button"
187
+ >
188
+ <svg
189
+ aria-hidden="true"
190
+ class="pf-v6-svg"
191
+ fill="currentColor"
192
+ height="1em"
193
+ role="img"
194
+ viewBox="0 0 256 512"
195
+ width="1em"
196
+ >
197
+ <path
198
+ 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"
199
+ />
200
+ </svg>
201
+ </button>
202
+ </div>
203
+ <div
204
+ class="pf-v6-c-pagination__nav-control pf-m-last"
205
+ >
206
+ <button
207
+ aria-disabled="false"
208
+ aria-label="Go to last page"
209
+ class="pf-v6-c-button pf-m-plain"
210
+ data-action="last"
211
+ data-ouia-component-id="OUIA-Generated-Button-plain-4"
212
+ data-ouia-component-type="PF6/Button"
213
+ data-ouia-safe="true"
214
+ type="button"
215
+ >
216
+ <svg
217
+ aria-hidden="true"
218
+ class="pf-v6-svg"
219
+ fill="currentColor"
220
+ height="1em"
221
+ role="img"
222
+ viewBox="0 0 448 512"
223
+ width="1em"
224
+ >
225
+ <path
226
+ 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"
227
+ />
228
+ </svg>
229
+ </button>
230
+ </div>
231
+ </nav>
232
+ </div>
233
+ </div>
234
+ </div>
235
+ </div>
236
+ <div
237
+ class="pf-v6-c-toolbar__content pf-m-hidden"
238
+ hidden=""
239
+ >
240
+ <div
241
+ class="pf-v6-c-toolbar__group"
242
+ />
243
+ </div>
244
+ </div>
245
+ </div>
246
+ </body>,
247
+ "container": <div>
248
+ <div
249
+ class="pf-v6-c-toolbar"
250
+ data-ouia-component-id="DataViewToolbar"
251
+ data-ouia-component-type="PF6/Toolbar"
252
+ data-ouia-safe="true"
253
+ id="pf-random-id-0"
254
+ >
255
+ <div
256
+ class="pf-v6-c-toolbar__content"
257
+ >
258
+ <div
259
+ class="pf-v6-c-toolbar__content-section"
260
+ >
261
+ <div
262
+ class="pf-v6-c-toolbar__item pf-m-pagination"
263
+ data-ouia-component-id="DataViewToolbar-pagination"
264
+ >
265
+ <div
266
+ class="pf-v6-c-pagination"
267
+ data-ouia-component-id="OUIA-Generated-Pagination-top-1"
268
+ data-ouia-component-type="PF6/Pagination"
269
+ data-ouia-safe="true"
270
+ id="options-menu-top-pagination"
271
+ style="--pf-v6-c-pagination__nav-page-select--c-form-control--width-chars: 2;"
272
+ >
273
+ <div
274
+ class="pf-v6-c-pagination__total-items"
275
+ >
276
+ <b>
277
+ 1
278
+ -
279
+ 10
280
+ </b>
281
+
282
+ of
283
+
284
+ <b>
285
+ 0
286
+ </b>
287
+
288
+ </div>
289
+ <button
290
+ aria-expanded="false"
291
+ aria-haspopup="listbox"
292
+ class="pf-v6-c-menu-toggle pf-m-plain pf-m-text"
293
+ id="options-menu-top-toggle"
294
+ type="button"
295
+ >
296
+ <span
297
+ class="pf-v6-c-menu-toggle__text"
298
+ >
299
+ <b>
300
+ 1
301
+ -
302
+ 10
303
+ </b>
304
+
305
+ of
306
+
307
+ <b>
308
+ 0
309
+ </b>
310
+
311
+ </span>
312
+ <span
313
+ class="pf-v6-c-menu-toggle__controls"
314
+ >
315
+ <span
316
+ class="pf-v6-c-menu-toggle__toggle-icon"
317
+ >
318
+ <svg
319
+ aria-hidden="true"
320
+ class="pf-v6-svg"
321
+ fill="currentColor"
322
+ height="1em"
323
+ role="img"
324
+ viewBox="0 0 320 512"
325
+ width="1em"
326
+ >
327
+ <path
328
+ 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"
329
+ />
330
+ </svg>
331
+ </span>
332
+ </span>
333
+ </button>
334
+ <nav
335
+ aria-label="Pagination"
336
+ class="pf-v6-c-pagination__nav"
337
+ >
338
+ <div
339
+ class="pf-v6-c-pagination__nav-control pf-m-first"
340
+ >
341
+ <button
342
+ aria-disabled="false"
343
+ aria-label="Go to first page"
344
+ class="pf-v6-c-button pf-m-plain"
345
+ data-action="first"
346
+ data-ouia-component-id="OUIA-Generated-Button-plain-1"
347
+ data-ouia-component-type="PF6/Button"
348
+ data-ouia-safe="true"
349
+ disabled=""
350
+ type="button"
351
+ >
352
+ <svg
353
+ aria-hidden="true"
354
+ class="pf-v6-svg"
355
+ fill="currentColor"
356
+ height="1em"
357
+ role="img"
358
+ viewBox="0 0 448 512"
359
+ width="1em"
360
+ >
361
+ <path
362
+ 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"
363
+ />
364
+ </svg>
365
+ </button>
366
+ </div>
367
+ <div
368
+ class="pf-v6-c-pagination__nav-control"
369
+ >
370
+ <button
371
+ aria-disabled="false"
372
+ aria-label="Go to previous page"
373
+ class="pf-v6-c-button pf-m-plain"
374
+ data-action="previous"
375
+ data-ouia-component-id="OUIA-Generated-Button-plain-2"
376
+ data-ouia-component-type="PF6/Button"
377
+ data-ouia-safe="true"
378
+ disabled=""
379
+ type="button"
380
+ >
381
+ <svg
382
+ aria-hidden="true"
383
+ class="pf-v6-svg"
384
+ fill="currentColor"
385
+ height="1em"
386
+ role="img"
387
+ viewBox="0 0 256 512"
388
+ width="1em"
389
+ >
390
+ <path
391
+ 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"
392
+ />
393
+ </svg>
394
+ </button>
395
+ </div>
396
+ <div
397
+ class="pf-v6-c-pagination__nav-page-select"
398
+ >
399
+ <span
400
+ class="pf-v6-c-form-control"
401
+ >
402
+ <input
403
+ aria-invalid="false"
404
+ aria-label="Current page"
405
+ data-ouia-component-id="OUIA-Generated-TextInputBase-1"
406
+ data-ouia-component-type="PF6/TextInput"
407
+ data-ouia-safe="true"
408
+ max="2"
409
+ min="1"
410
+ type="number"
411
+ value="1"
412
+ />
413
+ </span>
414
+ </div>
415
+ <div
416
+ class="pf-v6-c-pagination__nav-control"
417
+ >
418
+ <button
419
+ aria-disabled="false"
420
+ aria-label="Go to next page"
421
+ class="pf-v6-c-button pf-m-plain"
422
+ data-action="next"
423
+ data-ouia-component-id="OUIA-Generated-Button-plain-3"
424
+ data-ouia-component-type="PF6/Button"
425
+ data-ouia-safe="true"
426
+ type="button"
427
+ >
428
+ <svg
429
+ aria-hidden="true"
430
+ class="pf-v6-svg"
431
+ fill="currentColor"
432
+ height="1em"
433
+ role="img"
434
+ viewBox="0 0 256 512"
435
+ width="1em"
436
+ >
437
+ <path
438
+ 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"
439
+ />
440
+ </svg>
441
+ </button>
442
+ </div>
443
+ <div
444
+ class="pf-v6-c-pagination__nav-control pf-m-last"
445
+ >
446
+ <button
447
+ aria-disabled="false"
448
+ aria-label="Go to last page"
449
+ class="pf-v6-c-button pf-m-plain"
450
+ data-action="last"
451
+ data-ouia-component-id="OUIA-Generated-Button-plain-4"
452
+ data-ouia-component-type="PF6/Button"
453
+ data-ouia-safe="true"
454
+ type="button"
455
+ >
456
+ <svg
457
+ aria-hidden="true"
458
+ class="pf-v6-svg"
459
+ fill="currentColor"
460
+ height="1em"
461
+ role="img"
462
+ viewBox="0 0 448 512"
463
+ width="1em"
464
+ >
465
+ <path
466
+ 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"
467
+ />
468
+ </svg>
469
+ </button>
470
+ </div>
471
+ </nav>
472
+ </div>
473
+ </div>
474
+ </div>
475
+ </div>
476
+ <div
477
+ class="pf-v6-c-toolbar__content pf-m-hidden"
478
+ hidden=""
479
+ >
480
+ <div
481
+ class="pf-v6-c-toolbar__group"
482
+ />
483
+ </div>
484
+ </div>
485
+ </div>,
486
+ "debug": [Function],
487
+ "findAllByAltText": [Function],
488
+ "findAllByDisplayValue": [Function],
489
+ "findAllByLabelText": [Function],
490
+ "findAllByPlaceholderText": [Function],
491
+ "findAllByRole": [Function],
492
+ "findAllByTestId": [Function],
493
+ "findAllByText": [Function],
494
+ "findAllByTitle": [Function],
495
+ "findByAltText": [Function],
496
+ "findByDisplayValue": [Function],
497
+ "findByLabelText": [Function],
498
+ "findByPlaceholderText": [Function],
499
+ "findByRole": [Function],
500
+ "findByTestId": [Function],
501
+ "findByText": [Function],
502
+ "findByTitle": [Function],
503
+ "getAllByAltText": [Function],
504
+ "getAllByDisplayValue": [Function],
505
+ "getAllByLabelText": [Function],
506
+ "getAllByPlaceholderText": [Function],
507
+ "getAllByRole": [Function],
508
+ "getAllByTestId": [Function],
509
+ "getAllByText": [Function],
510
+ "getAllByTitle": [Function],
511
+ "getByAltText": [Function],
512
+ "getByDisplayValue": [Function],
513
+ "getByLabelText": [Function],
514
+ "getByPlaceholderText": [Function],
515
+ "getByRole": [Function],
516
+ "getByTestId": [Function],
517
+ "getByText": [Function],
518
+ "getByTitle": [Function],
519
+ "queryAllByAltText": [Function],
520
+ "queryAllByDisplayValue": [Function],
521
+ "queryAllByLabelText": [Function],
522
+ "queryAllByPlaceholderText": [Function],
523
+ "queryAllByRole": [Function],
524
+ "queryAllByTestId": [Function],
525
+ "queryAllByText": [Function],
526
+ "queryAllByTitle": [Function],
527
+ "queryByAltText": [Function],
528
+ "queryByDisplayValue": [Function],
529
+ "queryByLabelText": [Function],
530
+ "queryByPlaceholderText": [Function],
531
+ "queryByRole": [Function],
532
+ "queryByTestId": [Function],
533
+ "queryByText": [Function],
534
+ "queryByTitle": [Function],
535
+ "rerender": [Function],
536
+ "unmount": [Function],
537
+ }
538
+ `;
@@ -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.