@patternfly/react-data-view 6.1.0-prerelease.1 → 6.2.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 (239) hide show
  1. package/dist/cjs/DataView/DataView.d.ts +15 -1
  2. package/dist/cjs/DataView/DataView.js +14 -3
  3. package/dist/cjs/DataViewCheckboxFilter/DataViewCheckboxFilter.d.ts +29 -0
  4. package/dist/cjs/DataViewCheckboxFilter/DataViewCheckboxFilter.js +70 -0
  5. package/dist/cjs/DataViewCheckboxFilter/DataViewCheckboxFilter.test.d.ts +1 -0
  6. package/dist/cjs/DataViewCheckboxFilter/DataViewCheckboxFilter.test.js +25 -0
  7. package/dist/cjs/DataViewCheckboxFilter/index.d.ts +2 -0
  8. package/dist/cjs/DataViewCheckboxFilter/index.js +23 -0
  9. package/dist/cjs/DataViewEventsContext/DataViewEventsContext.d.ts +16 -0
  10. package/dist/cjs/DataViewEventsContext/DataViewEventsContext.js +62 -0
  11. package/dist/cjs/DataViewEventsContext/DataViewEventsContext.test.d.ts +1 -0
  12. package/dist/cjs/DataViewEventsContext/DataViewEventsContext.test.js +72 -0
  13. package/dist/cjs/DataViewEventsContext/index.d.ts +2 -0
  14. package/dist/cjs/DataViewEventsContext/index.js +23 -0
  15. package/dist/cjs/DataViewFilters/DataViewFilters.d.ts +25 -0
  16. package/dist/cjs/DataViewFilters/DataViewFilters.js +85 -0
  17. package/dist/cjs/DataViewFilters/DataViewFilters.test.d.ts +1 -0
  18. package/dist/cjs/DataViewFilters/DataViewFilters.test.js +19 -0
  19. package/dist/cjs/DataViewFilters/index.d.ts +2 -0
  20. package/dist/cjs/DataViewFilters/index.js +23 -0
  21. package/dist/cjs/DataViewTable/DataViewTable.d.ts +49 -0
  22. package/dist/cjs/DataViewTable/DataViewTable.js +18 -0
  23. package/dist/cjs/DataViewTable/DataViewTable.test.d.ts +1 -0
  24. package/dist/cjs/DataViewTable/DataViewTable.test.js +57 -0
  25. package/dist/cjs/DataViewTable/index.d.ts +2 -0
  26. package/dist/cjs/DataViewTable/index.js +23 -0
  27. package/dist/cjs/DataViewTableBasic/DataViewTableBasic.d.ts +19 -0
  28. package/dist/cjs/DataViewTableBasic/DataViewTableBasic.js +71 -0
  29. package/dist/cjs/DataViewTableBasic/DataViewTableBasic.test.d.ts +1 -0
  30. package/dist/cjs/DataViewTableBasic/DataViewTableBasic.test.js +43 -0
  31. package/dist/cjs/DataViewTableBasic/index.d.ts +2 -0
  32. package/dist/cjs/DataViewTableBasic/index.js +23 -0
  33. package/dist/cjs/DataViewTableHead/DataViewTableHead.d.ts +14 -0
  34. package/dist/cjs/DataViewTableHead/DataViewTableHead.js +57 -0
  35. package/dist/cjs/DataViewTableHead/DataViewTableHead.test.d.ts +1 -0
  36. package/dist/cjs/DataViewTableHead/DataViewTableHead.test.js +36 -0
  37. package/dist/cjs/DataViewTableHead/index.d.ts +2 -0
  38. package/dist/cjs/DataViewTableHead/index.js +23 -0
  39. package/dist/cjs/DataViewTableTree/DataViewTableTree.d.ts +25 -0
  40. package/dist/cjs/DataViewTableTree/DataViewTableTree.js +144 -0
  41. package/dist/cjs/DataViewTableTree/DataViewTableTree.test.d.ts +1 -0
  42. package/dist/cjs/DataViewTableTree/DataViewTableTree.test.js +90 -0
  43. package/dist/cjs/DataViewTableTree/index.d.ts +2 -0
  44. package/dist/cjs/DataViewTableTree/index.js +23 -0
  45. package/dist/cjs/DataViewTextFilter/DataViewTextFilter.d.ts +21 -0
  46. package/dist/cjs/DataViewTextFilter/DataViewTextFilter.js +26 -0
  47. package/dist/cjs/DataViewTextFilter/DataViewTextFilter.test.d.ts +1 -0
  48. package/dist/cjs/DataViewTextFilter/DataViewTextFilter.test.js +22 -0
  49. package/dist/cjs/DataViewTextFilter/index.d.ts +2 -0
  50. package/dist/cjs/DataViewTextFilter/index.js +23 -0
  51. package/dist/cjs/DataViewToolbar/DataViewToolbar.d.ts +13 -3
  52. package/dist/cjs/DataViewToolbar/DataViewToolbar.js +31 -6
  53. package/dist/cjs/Hooks/filters.d.ts +14 -0
  54. package/dist/cjs/Hooks/filters.js +69 -0
  55. package/dist/cjs/Hooks/filters.test.d.ts +1 -0
  56. package/dist/cjs/Hooks/filters.test.js +75 -0
  57. package/dist/cjs/Hooks/index.d.ts +2 -0
  58. package/dist/cjs/Hooks/index.js +2 -0
  59. package/dist/cjs/Hooks/pagination.d.ts +14 -1
  60. package/dist/cjs/Hooks/pagination.js +36 -4
  61. package/dist/cjs/Hooks/pagination.test.js +1 -1
  62. package/dist/cjs/Hooks/selection.d.ts +3 -3
  63. package/dist/cjs/Hooks/selection.js +4 -4
  64. package/dist/cjs/Hooks/selection.test.js +4 -4
  65. package/dist/cjs/Hooks/sort.d.ts +32 -0
  66. package/dist/cjs/Hooks/sort.js +47 -0
  67. package/dist/cjs/Hooks/sort.test.d.ts +1 -0
  68. package/dist/cjs/Hooks/sort.test.js +68 -0
  69. package/dist/cjs/InternalContext/InternalContext.d.ts +26 -0
  70. package/dist/cjs/InternalContext/InternalContext.js +40 -0
  71. package/dist/cjs/InternalContext/InternalContext.test.d.ts +1 -0
  72. package/dist/cjs/InternalContext/InternalContext.test.js +56 -0
  73. package/dist/cjs/InternalContext/index.d.ts +2 -0
  74. package/dist/cjs/InternalContext/index.js +23 -0
  75. package/dist/cjs/index.d.ts +16 -0
  76. package/dist/cjs/index.js +26 -2
  77. package/dist/dynamic/DataViewCheckboxFilter/package.json +1 -0
  78. package/dist/dynamic/DataViewEventsContext/package.json +1 -0
  79. package/dist/dynamic/DataViewFilters/package.json +1 -0
  80. package/dist/dynamic/DataViewTable/package.json +1 -0
  81. package/dist/dynamic/DataViewTableBasic/package.json +1 -0
  82. package/dist/dynamic/DataViewTableHead/package.json +1 -0
  83. package/dist/dynamic/DataViewTableTree/package.json +1 -0
  84. package/dist/dynamic/DataViewTextFilter/package.json +1 -0
  85. package/dist/dynamic/InternalContext/package.json +1 -0
  86. package/dist/esm/DataView/DataView.d.ts +15 -1
  87. package/dist/esm/DataView/DataView.js +13 -2
  88. package/dist/esm/DataViewCheckboxFilter/DataViewCheckboxFilter.d.ts +29 -0
  89. package/dist/esm/DataViewCheckboxFilter/DataViewCheckboxFilter.js +62 -0
  90. package/dist/esm/DataViewCheckboxFilter/DataViewCheckboxFilter.test.d.ts +1 -0
  91. package/dist/esm/DataViewCheckboxFilter/DataViewCheckboxFilter.test.js +20 -0
  92. package/dist/esm/DataViewCheckboxFilter/index.d.ts +2 -0
  93. package/dist/esm/DataViewCheckboxFilter/index.js +2 -0
  94. package/dist/esm/DataViewEventsContext/DataViewEventsContext.d.ts +16 -0
  95. package/dist/esm/DataViewEventsContext/DataViewEventsContext.js +34 -0
  96. package/dist/esm/DataViewEventsContext/DataViewEventsContext.test.d.ts +1 -0
  97. package/dist/esm/DataViewEventsContext/DataViewEventsContext.test.js +67 -0
  98. package/dist/esm/DataViewEventsContext/index.d.ts +2 -0
  99. package/dist/esm/DataViewEventsContext/index.js +2 -0
  100. package/dist/esm/DataViewFilters/DataViewFilters.d.ts +25 -0
  101. package/dist/esm/DataViewFilters/DataViewFilters.js +58 -0
  102. package/dist/esm/DataViewFilters/DataViewFilters.test.d.ts +1 -0
  103. package/dist/esm/DataViewFilters/DataViewFilters.test.js +14 -0
  104. package/dist/esm/DataViewFilters/index.d.ts +2 -0
  105. package/dist/esm/DataViewFilters/index.js +2 -0
  106. package/dist/esm/DataViewTable/DataViewTable.d.ts +49 -0
  107. package/dist/esm/DataViewTable/DataViewTable.js +8 -0
  108. package/dist/esm/DataViewTable/DataViewTable.test.d.ts +1 -0
  109. package/dist/esm/DataViewTable/DataViewTable.test.js +52 -0
  110. package/dist/esm/DataViewTable/index.d.ts +2 -0
  111. package/dist/esm/DataViewTable/index.js +2 -0
  112. package/dist/esm/DataViewTableBasic/DataViewTableBasic.d.ts +19 -0
  113. package/dist/esm/DataViewTableBasic/DataViewTableBasic.js +44 -0
  114. package/dist/esm/DataViewTableBasic/DataViewTableBasic.test.d.ts +1 -0
  115. package/dist/esm/DataViewTableBasic/DataViewTableBasic.test.js +38 -0
  116. package/dist/esm/DataViewTableBasic/index.d.ts +2 -0
  117. package/dist/esm/DataViewTableBasic/index.js +2 -0
  118. package/dist/esm/DataViewTableHead/DataViewTableHead.d.ts +14 -0
  119. package/dist/esm/DataViewTableHead/DataViewTableHead.js +30 -0
  120. package/dist/esm/DataViewTableHead/DataViewTableHead.test.d.ts +1 -0
  121. package/dist/esm/DataViewTableHead/DataViewTableHead.test.js +31 -0
  122. package/dist/esm/DataViewTableHead/index.d.ts +2 -0
  123. package/dist/esm/DataViewTableHead/index.js +2 -0
  124. package/dist/esm/DataViewTableTree/DataViewTableTree.d.ts +25 -0
  125. package/dist/esm/DataViewTableTree/DataViewTableTree.js +117 -0
  126. package/dist/esm/DataViewTableTree/DataViewTableTree.test.d.ts +1 -0
  127. package/dist/esm/DataViewTableTree/DataViewTableTree.test.js +85 -0
  128. package/dist/esm/DataViewTableTree/index.d.ts +2 -0
  129. package/dist/esm/DataViewTableTree/index.js +2 -0
  130. package/dist/esm/DataViewTextFilter/DataViewTextFilter.d.ts +21 -0
  131. package/dist/esm/DataViewTextFilter/DataViewTextFilter.js +19 -0
  132. package/dist/esm/DataViewTextFilter/DataViewTextFilter.test.d.ts +1 -0
  133. package/dist/esm/DataViewTextFilter/DataViewTextFilter.test.js +17 -0
  134. package/dist/esm/DataViewTextFilter/index.d.ts +2 -0
  135. package/dist/esm/DataViewTextFilter/index.js +2 -0
  136. package/dist/esm/DataViewToolbar/DataViewToolbar.d.ts +13 -3
  137. package/dist/esm/DataViewToolbar/DataViewToolbar.js +9 -4
  138. package/dist/esm/Hooks/filters.d.ts +14 -0
  139. package/dist/esm/Hooks/filters.js +65 -0
  140. package/dist/esm/Hooks/filters.test.d.ts +1 -0
  141. package/dist/esm/Hooks/filters.test.js +73 -0
  142. package/dist/esm/Hooks/index.d.ts +2 -0
  143. package/dist/esm/Hooks/index.js +2 -0
  144. package/dist/esm/Hooks/pagination.d.ts +14 -1
  145. package/dist/esm/Hooks/pagination.js +36 -4
  146. package/dist/esm/Hooks/pagination.test.js +1 -1
  147. package/dist/esm/Hooks/selection.d.ts +3 -3
  148. package/dist/esm/Hooks/selection.js +4 -4
  149. package/dist/esm/Hooks/selection.test.js +4 -4
  150. package/dist/esm/Hooks/sort.d.ts +32 -0
  151. package/dist/esm/Hooks/sort.js +43 -0
  152. package/dist/esm/Hooks/sort.test.d.ts +1 -0
  153. package/dist/esm/Hooks/sort.test.js +66 -0
  154. package/dist/esm/InternalContext/InternalContext.d.ts +26 -0
  155. package/dist/esm/InternalContext/InternalContext.js +12 -0
  156. package/dist/esm/InternalContext/InternalContext.test.d.ts +1 -0
  157. package/dist/esm/InternalContext/InternalContext.test.js +51 -0
  158. package/dist/esm/InternalContext/index.d.ts +2 -0
  159. package/dist/esm/InternalContext/index.js +2 -0
  160. package/dist/esm/index.d.ts +16 -0
  161. package/dist/esm/index.js +16 -0
  162. package/dist/tsconfig.tsbuildinfo +1 -0
  163. package/package.json +16 -15
  164. package/patternfly-docs/content/extensions/data-view/examples/DataView/DataView.md +63 -0
  165. package/patternfly-docs/content/extensions/data-view/examples/DataView/EventsExample.tsx +130 -0
  166. package/patternfly-docs/content/extensions/data-view/examples/DataView/PredefinedLayoutFullExample.tsx +275 -0
  167. package/patternfly-docs/content/extensions/data-view/examples/Table/DataViewTableEmptyExample.tsx +57 -0
  168. package/patternfly-docs/content/extensions/data-view/examples/Table/DataViewTableErrorExample.tsx +45 -0
  169. package/patternfly-docs/content/extensions/data-view/examples/Table/DataViewTableExample.tsx +67 -0
  170. package/patternfly-docs/content/extensions/data-view/examples/Table/DataViewTableLoadingExample.tsx +27 -0
  171. package/patternfly-docs/content/extensions/data-view/examples/Table/DataViewTableTreeExample.tsx +71 -0
  172. package/patternfly-docs/content/extensions/data-view/examples/Table/SortingExample.tsx +87 -0
  173. package/patternfly-docs/content/extensions/data-view/examples/Table/Table.md +130 -0
  174. package/patternfly-docs/content/extensions/data-view/examples/Toolbar/AllSelectedExample.tsx +116 -0
  175. package/patternfly-docs/content/extensions/data-view/examples/Toolbar/DataViewToolbarActionsExample.tsx +27 -0
  176. package/patternfly-docs/content/extensions/data-view/examples/Toolbar/DataViewToolbarExample.tsx +36 -0
  177. package/patternfly-docs/content/extensions/data-view/examples/Toolbar/FiltersExample.tsx +107 -0
  178. package/patternfly-docs/content/extensions/data-view/examples/Toolbar/PaginationExample.tsx +56 -0
  179. package/patternfly-docs/content/extensions/data-view/examples/Toolbar/SelectionExample.tsx +57 -0
  180. package/patternfly-docs/content/extensions/data-view/examples/Toolbar/Toolbar.md +154 -0
  181. package/patternfly-docs/pages/index.js +1 -1
  182. package/release.config.js +1 -1
  183. package/src/DataView/DataView.tsx +28 -5
  184. package/src/DataView/__snapshots__/DataView.test.tsx.snap +2 -2
  185. package/src/DataViewCheckboxFilter/DataViewCheckboxFilter.test.tsx +24 -0
  186. package/src/DataViewCheckboxFilter/DataViewCheckboxFilter.tsx +175 -0
  187. package/src/DataViewCheckboxFilter/__snapshots__/DataViewCheckboxFilter.test.tsx.snap +197 -0
  188. package/src/DataViewCheckboxFilter/index.ts +2 -0
  189. package/src/DataViewEventsContext/DataViewEventsContext.test.tsx +105 -0
  190. package/src/DataViewEventsContext/DataViewEventsContext.tsx +70 -0
  191. package/src/DataViewEventsContext/index.ts +2 -0
  192. package/src/DataViewFilters/DataViewFilters.test.tsx +21 -0
  193. package/src/DataViewFilters/DataViewFilters.tsx +144 -0
  194. package/src/DataViewFilters/__snapshots__/DataViewFilters.test.tsx.snap +194 -0
  195. package/src/DataViewFilters/index.tsx +2 -0
  196. package/src/DataViewTable/DataViewTable.test.tsx +80 -0
  197. package/src/DataViewTable/DataViewTable.tsx +57 -0
  198. package/src/DataViewTable/__snapshots__/DataViewTable.test.tsx.snap +1042 -0
  199. package/src/DataViewTable/index.ts +2 -0
  200. package/src/DataViewTableBasic/DataViewTableBasic.test.tsx +65 -0
  201. package/src/DataViewTableBasic/DataViewTableBasic.tsx +83 -0
  202. package/src/DataViewTableBasic/__snapshots__/DataViewTableBasic.test.tsx.snap +555 -0
  203. package/src/DataViewTableBasic/index.ts +2 -0
  204. package/src/DataViewTableHead/DataViewTableHead.test.tsx +50 -0
  205. package/src/DataViewTableHead/DataViewTableHead.tsx +54 -0
  206. package/src/DataViewTableHead/__snapshots__/DataViewTableHead.test.tsx.snap +227 -0
  207. package/src/DataViewTableHead/index.ts +2 -0
  208. package/src/DataViewTableTree/DataViewTableTree.test.tsx +113 -0
  209. package/src/DataViewTableTree/DataViewTableTree.tsx +186 -0
  210. package/src/DataViewTableTree/__snapshots__/DataViewTableTree.test.tsx.snap +1200 -0
  211. package/src/DataViewTableTree/index.ts +2 -0
  212. package/src/DataViewTextFilter/DataViewTextFilter.test.tsx +24 -0
  213. package/src/DataViewTextFilter/DataViewTextFilter.tsx +54 -0
  214. package/src/DataViewTextFilter/__snapshots__/DataViewTextFilter.test.tsx.snap +203 -0
  215. package/src/DataViewTextFilter/index.ts +2 -0
  216. package/src/DataViewToolbar/DataViewToolbar.tsx +55 -22
  217. package/src/DataViewToolbar/__snapshots__/DataViewToolbar.test.tsx.snap +52 -8
  218. package/src/Hooks/filters.test.tsx +89 -0
  219. package/src/Hooks/filters.ts +97 -0
  220. package/src/Hooks/index.ts +2 -0
  221. package/src/Hooks/pagination.test.tsx +1 -1
  222. package/src/Hooks/pagination.ts +69 -12
  223. package/src/Hooks/selection.test.tsx +5 -5
  224. package/src/Hooks/selection.ts +7 -7
  225. package/src/Hooks/sort.test.tsx +84 -0
  226. package/src/Hooks/sort.ts +87 -0
  227. package/src/InternalContext/InternalContext.test.tsx +89 -0
  228. package/src/InternalContext/InternalContext.tsx +52 -0
  229. package/src/InternalContext/index.ts +2 -0
  230. package/src/index.ts +24 -0
  231. package/patternfly-docs/content/extensions/data-view/about-data-view.md +0 -14
  232. package/patternfly-docs/content/extensions/data-view/examples/Components/Components.md +0 -31
  233. package/patternfly-docs/content/extensions/data-view/examples/Components/DataViewToolbarExample.tsx +0 -20
  234. package/patternfly-docs/content/extensions/data-view/examples/Functionality/Functionality.md +0 -77
  235. package/patternfly-docs/content/extensions/data-view/examples/Functionality/PaginationExample.tsx +0 -65
  236. package/patternfly-docs/content/extensions/data-view/examples/Functionality/SelectionExample.tsx +0 -88
  237. package/patternfly-docs/content/extensions/data-view/examples/Layout/Layout.md +0 -39
  238. package/patternfly-docs/content/extensions/data-view/examples/Layout/PredefinedLayoutExample.tsx +0 -120
  239. /package/patternfly-docs/content/extensions/data-view/examples/{Layout → DataView}/AbstractLayoutExample.tsx +0 -0
@@ -0,0 +1,154 @@
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: Toolbar
9
+ title: Data view toolbar
10
+ # Tab (react | react-demos | html | html-demos | design-guidelines | accessibility)
11
+ source: react
12
+ # If you use typescript, the name of the interface to display props for
13
+ # These are found through the sourceProps function provided in patternfly-docs.source.js
14
+ sortValue: 2
15
+ propComponents: ['DataViewToolbar', 'DataViewFilters', 'DataViewTextFilter', 'DataViewCheckboxFilter']
16
+ sourceLink: https://github.com/patternfly/react-data-view/blob/main/packages/module/patternfly-docs/content/extensions/data-view/examples/Toolbar/Toolbar.md
17
+ ---
18
+ import { useMemo, useState, useEffect } from 'react';
19
+ import { BrowserRouter, useSearchParams } from 'react-router-dom';
20
+ import { Pagination, ToggleGroup, ToggleGroupItem } from '@patternfly/react-core';
21
+ import { useDataViewPagination, useDataViewSelection, useDataViewFilters } from '@patternfly/react-data-view/dist/dynamic/Hooks';
22
+ import { DataView } from '@patternfly/react-data-view/dist/dynamic/DataView';
23
+ import { BulkSelect, BulkSelectValue, ErrorState, ResponsiveAction, ResponsiveActions, SkeletonTableHead, SkeletonTableBody } from '@patternfly/react-component-groups';
24
+ import { DataViewToolbar } from '@patternfly/react-data-view/dist/dynamic/DataViewToolbar';
25
+ import { DataViewTable } from '@patternfly/react-data-view/dist/dynamic/DataViewTable';
26
+ import { DataViewFilters } from '@patternfly/react-data-view/dist/dynamic/DataViewFilters';
27
+ import { DataViewTextFilter } from '@patternfly/react-data-view/dist/dynamic/DataViewTextFilter';
28
+ import { DataViewCheckboxFilter } from '@patternfly/react-data-view/dist/dynamic/DataViewCheckboxFilter';
29
+
30
+ The **data view toolbar** component renders a default opinionated data view toolbar above or below the data section.
31
+
32
+ Data view toolbar can contain pagination, bulk select, filters, actions, or other custom child content. To pass child items to the toolbar, use the [toolbar item](/components/toolbar#toolbar-items) component or predefined `<DataViewToolbar>` props for specific use cases.
33
+
34
+ You can further customize toolbar interactions by referring to the additional documentation:
35
+ - [Actions](#toolbar-actions)
36
+ - [Pagination](#pagination)
37
+ - [Selection](#selection)
38
+ - [Filters](#filters)
39
+
40
+ ### Toolbar example
41
+
42
+ ```js file="./DataViewToolbarExample.tsx"
43
+
44
+ ```
45
+
46
+ ## Toolbar actions
47
+ To support additional user needs, you can pass relevant actions to the toolbar via `actions`. Add standard PatternFly actions (like buttons) or choose predefined [responsive actions](/component-groups/responsive-actions) which ensure the responsive behavior of multiple actions in 1 toolbar.
48
+
49
+ ### Actions example
50
+
51
+ ```js file="./DataViewToolbarActionsExample.tsx"
52
+
53
+ ```
54
+
55
+ ## Pagination
56
+
57
+ To help users navigate data records that span multiple pages, add pagination support to your toolbar.
58
+
59
+ The data view toolbar can display a pagination using the `pagination` prop. You can also pass a custom `ouiaId` to the toolbar for testing purposes. You can also persist pagination values in the URL to make it easier to share or bookmark specific pages of your data.
60
+
61
+ ### Pagination state
62
+
63
+ The `useDataViewPagination` hook manages the pagination state of the data view.
64
+
65
+ **Initial values:**
66
+ - `perPage` initial value.
67
+ - Optional `page` initial value.
68
+ - Optional `searchParams` object.
69
+ - Optional `setSearchParams` function.
70
+
71
+ While the hook works seamlessly with the [React Router](https://reactrouter.com/) library, you do not need to use it to take advantage of URL persistence. The `searchParams` and `setSearchParams` props can be managed using native browser APIs (`URLSearchParams` and `window.history.pushState`) or any other routing library of your choice. If you don't pass these two props, the pagination state will be stored internally without the URL usage.
72
+
73
+ You can also pass custom `pageParam` or `perPageParam` names, renaming the pagination parameters in the URL.
74
+
75
+ The retrieved values are named to match the PatternFly pagination component props.
76
+
77
+ **Return values:**
78
+ - Current `page` number.
79
+ - `onSetPage` to modify current page.
80
+ - Items `perPage` value.
81
+ - `onPerPageSelect` to modify per page value.
82
+
83
+ ### Pagination example
84
+ This example uses the URL to persist the pagination state.
85
+
86
+ ```js file="./PaginationExample.tsx"
87
+
88
+ ```
89
+
90
+ ## Selection
91
+ To allow users to select data records inside the data view, add selection support that displays a row's selection state.
92
+
93
+ The data view toolbar can display a bulk selection component by using the predefined [component group extension bulk select](/extensions/component-groups/bulk-select) component.
94
+
95
+ ### Selection state
96
+
97
+ The `useDataViewSelection` hook manages the selection state of the data view.
98
+
99
+ **Initial values:**
100
+ - Optional `initialSelected` array of record's identifiers selected by default.
101
+ - `matchOption` function to check if the record is selected.
102
+ - When no `matchOption` is passed, the `Array.prototype.includes()` operation is performed on the `selected` array.
103
+
104
+ **Return values:**
105
+ - `selected` array of currently selected records.
106
+ - `isSelected` function returning the selection state for the record.
107
+ - `onSelect` callback to modify the selection state. This accepts the `isSelecting` flag (indicates if records are being selected or deselected) and `items` (affected records).
108
+
109
+ ### Selection example
110
+
111
+ ```js file="./SelectionExample.tsx"
112
+
113
+ ```
114
+
115
+ ## Filters
116
+ To allow users to filter data records in the data view, add filtering support that displays the applied filter chips.
117
+
118
+ The data view toolbar can include a set of filters by passing a React node to the `filters` property. You can use the predefined components `<DataViewFilters>`, `<DataViewTextFilter>`, and `<DataViewCheckboxFilter>` to customize and handle filtering directly in the toolbar. The `<DataViewFilters>` component is a wrapper that allows conditional filtering using multiple attributes. If you need just a single filter, you can use `<DataViewTextFilter>`, `<DataViewCheckboxFilter>`, or a different filter component alone. Props of these filter components are listed in the [props section of this page](#props).
119
+
120
+ You can either pass a `value` and `onChange` event to every filter separately, or you can pass `values` and `onChange` to the `<DataViewFilters>` wrapper, which makes them available to its children. Props directly passed to child filters have a higher priority than the "inherited" ones.
121
+
122
+ ### Filters state
123
+
124
+ The `useDataViewFilters` hook manages the filter state of the data view. It allows you to define default filter values, synchronize filter state with URL parameters, and handle filter changes efficiently.
125
+
126
+ **Initial values:**
127
+ - `initialFilters` object with default filter values (if the filter param allows multiple values, pass an array).
128
+ - Optional `searchParams` object for managing URL-based filter state.
129
+ - Optional `setSearchParams` function to update the URL when filters are modified.
130
+
131
+ The `useDataViewFilters` hook works well with the [React Router](https://reactrouter.com/) library to support URL-based filtering. Alternatively, you can manage the filter state in the URL using `URLSearchParams` and `window.history.pushState` APIs, or other routing libraries. If no URL parameters are provided, the filter state is managed internally.
132
+
133
+ **Return values:**
134
+ - `filters` object representing the current filter values.
135
+ - `onSetFilters` function to update the filter state.
136
+ - `clearAllFilters` function to reset all filters to their initial values.
137
+
138
+ ### Filtering example
139
+ This example demonstrates the setup and usage of filters within the data view. It includes text filters for different attributes, the ability to clear all filters, and persistence of filter state in the URL.
140
+
141
+ ```js file="./FiltersExample.tsx"
142
+
143
+ ```
144
+
145
+
146
+ ## All/selected data switch
147
+ All/selected data switch allows users to toggle between displaying the entire table (All) and only the rows they have selected (Selected). If the user deselects the last selected row, the filter automatically switches back to All, displaying all table rows again. Until at least one row is selected, a tooltip with guidance is displayed, and the Selected button does not perform any action. The Selected button is intentionally not disabled for accessibility reasons but instead has `aria-disabled` set.
148
+
149
+ ### All/selected example
150
+ This example demonstrates the setup and usage of All/selected row switch.
151
+
152
+ ```js file="./AllSelectedExample.tsx"
153
+
154
+ ```
@@ -10,7 +10,7 @@ const centerStyle = {
10
10
 
11
11
  const IndexPage = () => {
12
12
  return (
13
- <PageSection style={centerStyle}>
13
+ <PageSection hasBodyWrapper={false} style={centerStyle}>
14
14
  <div style={{ flex: 'none', textAlign: 'center' }}>
15
15
  <Title size="4xl" headingLevel="h1">
16
16
  My extension docs
package/release.config.js CHANGED
@@ -10,5 +10,5 @@ module.exports = {
10
10
  '@semantic-release/npm'
11
11
  ],
12
12
  tagFormat: 'prerelease-v${version}',
13
- dryRun: false
13
+ dryRun: true
14
14
  };
@@ -1,16 +1,33 @@
1
1
  import React from 'react';
2
- import { Stack, StackItem } from '@patternfly/react-core';
3
- export interface DataViewProps {
2
+ import { Stack, StackItem, StackProps } from '@patternfly/react-core';
3
+ import { DataViewSelection, InternalContextProvider } from '../InternalContext';
4
+
5
+ export const DataViewState = {
6
+ empty: 'empty',
7
+ loading: 'loading',
8
+ error: 'error'
9
+ } as const;
10
+
11
+ export type DataViewState = typeof DataViewState[keyof typeof DataViewState];
12
+
13
+ /** extends StackProps */
14
+ export interface DataViewProps extends StackProps {
4
15
  /** Content rendered inside the data view */
5
16
  children: React.ReactNode;
6
17
  /** Custom OUIA ID */
7
18
  ouiaId?: string;
19
+ /** Selection context configuration */
20
+ selection?: DataViewSelection;
21
+ /** Currently active state */
22
+ activeState?: DataViewState | string;
8
23
  }
9
24
 
10
- export const DataView: React.FC<DataViewProps> = ({
25
+ export type DataViewImpementationProps = Omit<DataViewProps, 'onSelect' | 'isItemSelected' | 'isItemSelectDisabled'>;
26
+
27
+ const DataViewImplementation: React.FC<DataViewImpementationProps> = ({
11
28
  children, ouiaId = 'DataView', ...props
12
- }: DataViewProps) => (
13
- <Stack data-ouia-component-id={`${ouiaId}-stack}`} {...props}>
29
+ }: DataViewImpementationProps) => (
30
+ <Stack data-ouia-component-id={`${ouiaId}-stack`} {...props}>
14
31
  {React.Children.map(children, (child, index) => (
15
32
  <StackItem data-ouia-component-id={`${ouiaId}-stack-item-${index}`}>
16
33
  {child}
@@ -19,4 +36,10 @@ export const DataView: React.FC<DataViewProps> = ({
19
36
  </Stack>
20
37
  )
21
38
 
39
+ export const DataView: React.FC<DataViewProps> = ({ children, selection, activeState, ...props }: DataViewProps) => (
40
+ <InternalContextProvider selection={selection} activeState={activeState} >
41
+ <DataViewImplementation {...props}>{children}</DataViewImplementation>
42
+ </InternalContextProvider>
43
+ );
44
+
22
45
  export default DataView;
@@ -7,7 +7,7 @@ exports[`DataView component should render correctly 1`] = `
7
7
  <div>
8
8
  <div
9
9
  class="pf-v6-l-stack"
10
- data-ouia-component-id="DataView-stack}"
10
+ data-ouia-component-id="DataView-stack"
11
11
  >
12
12
  <div
13
13
  class="pf-v6-l-stack__item"
@@ -45,7 +45,7 @@ exports[`DataView component should render correctly 1`] = `
45
45
  "container": <div>
46
46
  <div
47
47
  class="pf-v6-l-stack"
48
- data-ouia-component-id="DataView-stack}"
48
+ data-ouia-component-id="DataView-stack"
49
49
  >
50
50
  <div
51
51
  class="pf-v6-l-stack__item"
@@ -0,0 +1,24 @@
1
+ import React from 'react';
2
+ import { render } from '@testing-library/react';
3
+ import DataViewCheckboxFilter, { DataViewCheckboxFilterProps } from './DataViewCheckboxFilter';
4
+ import DataViewToolbar from '../DataViewToolbar';
5
+
6
+ describe('DataViewCheckboxFilter component', () => {
7
+ const defaultProps: DataViewCheckboxFilterProps = {
8
+ filterId: 'test-checkbox-filter',
9
+ title: 'Test Checkbox Filter',
10
+ value: [ 'workspace-one' ],
11
+ options: [
12
+ { label: 'Workspace one', value: 'workspace-one' },
13
+ { label: 'Workspace two', value: 'workspace-two' },
14
+ { label: 'Workspace three', value: 'workspace-three' },
15
+ ],
16
+ };
17
+
18
+ it('should render correctly', () => {
19
+ const { container } = render(
20
+ <DataViewToolbar filters={<DataViewCheckboxFilter {...defaultProps} />} />
21
+ );
22
+ expect(container).toMatchSnapshot();
23
+ });
24
+ });
@@ -0,0 +1,175 @@
1
+ import React from 'react';
2
+ import {
3
+ Badge,
4
+ Menu,
5
+ MenuContent,
6
+ MenuItem,
7
+ MenuList,
8
+ MenuProps,
9
+ MenuToggle,
10
+ Popper,
11
+ ToolbarLabel,
12
+ ToolbarFilter,
13
+ } from '@patternfly/react-core';
14
+ import { FilterIcon } from '@patternfly/react-icons';
15
+ import { DataViewFilterOption } from '../DataViewFilters';
16
+
17
+ const isToolbarLabel = (label: string | ToolbarLabel): label is ToolbarLabel =>
18
+ typeof label === 'object' && 'key' in label;
19
+
20
+ export const isDataViewFilterOption = (obj: unknown): obj is DataViewFilterOption =>
21
+ !!obj &&
22
+ typeof obj === 'object' &&
23
+ 'label' in obj &&
24
+ 'value' in obj &&
25
+ typeof (obj as DataViewFilterOption).value === 'string';
26
+
27
+ /** extends MenuProps */
28
+ export interface DataViewCheckboxFilterProps extends Omit<MenuProps, 'onSelect' | 'onChange'> {
29
+ /** Unique key for the filter attribute */
30
+ filterId: string;
31
+ /** Array of current filter values */
32
+ value?: string[];
33
+ /** Filter title displayed in the toolbar */
34
+ title: string;
35
+ /** Placeholder text of the menu */
36
+ placeholder?: string;
37
+ /** Filter options displayed */
38
+ options: (DataViewFilterOption | string)[];
39
+ /** Callback for updating when item selection changes. */
40
+ onChange?: (event?: React.MouseEvent, values?: string[]) => void;
41
+ /** Controls visibility of the filter in the toolbar */
42
+ showToolbarItem?: boolean;
43
+ /** Controls visibility of the filter icon */
44
+ showIcon?: boolean;
45
+ /** Controls visibility of the selected items badge */
46
+ showBadge?: boolean;
47
+ /** Custom OUIA ID */
48
+ ouiaId?: string;
49
+ }
50
+
51
+ export const DataViewCheckboxFilter: React.FC<DataViewCheckboxFilterProps> = ({
52
+ filterId,
53
+ title,
54
+ value = [],
55
+ onChange,
56
+ placeholder,
57
+ options = [],
58
+ showToolbarItem,
59
+ showIcon = !placeholder,
60
+ showBadge = !placeholder,
61
+ ouiaId = 'DataViewCheckboxFilter',
62
+ ...props
63
+ }: DataViewCheckboxFilterProps) => {
64
+ const [ isOpen, setIsOpen ] = React.useState(false);
65
+ const toggleRef = React.useRef<HTMLButtonElement>(null);
66
+ const menuRef = React.useRef<HTMLDivElement>(null);
67
+ const containerRef = React.useRef<HTMLDivElement>(null);
68
+
69
+ const normalizeOptions = React.useMemo(
70
+ () =>
71
+ options.map(option =>
72
+ typeof option === 'string'
73
+ ? { label: option, value: option }
74
+ : option
75
+ ),
76
+ [ options ]
77
+ );
78
+
79
+ const handleToggleClick = (event: React.MouseEvent) => {
80
+ event.stopPropagation();
81
+ setTimeout(() => {
82
+ const firstElement = menuRef.current?.querySelector('li > button:not(:disabled)') as HTMLElement;
83
+ firstElement?.focus();
84
+ }, 0);
85
+ setIsOpen(prev => !prev);
86
+ };
87
+
88
+ const handleSelect = (event?: React.MouseEvent, itemId?: string | number) => {
89
+ const activeItem = String(itemId);
90
+ const isSelected = value.includes(activeItem);
91
+
92
+ onChange?.(
93
+ event,
94
+ isSelected ? value.filter(item => item !== activeItem) : [ activeItem, ...value ]
95
+ );
96
+ };
97
+
98
+ const handleClickOutside = (event: MouseEvent) =>
99
+ isOpen &&
100
+ menuRef.current && toggleRef.current &&
101
+ !menuRef.current.contains(event.target as Node) && !toggleRef.current.contains(event.target as Node)
102
+ && setIsOpen(false);
103
+
104
+
105
+ React.useEffect(() => {
106
+ window.addEventListener('click', handleClickOutside);
107
+ return () => {
108
+ window.removeEventListener('click', handleClickOutside);
109
+ };
110
+ }, [ isOpen ]); // eslint-disable-line react-hooks/exhaustive-deps
111
+
112
+ return (
113
+ <ToolbarFilter
114
+ key={ouiaId}
115
+ data-ouia-component-id={ouiaId}
116
+ labels={value.map(item => {
117
+ const activeOption = normalizeOptions.find(option => option.value === item);
118
+ return ({ key: activeOption?.value as string, node: activeOption?.label })
119
+ })}
120
+ deleteLabel={(_, label) =>
121
+ onChange?.(undefined, value.filter(item => item !== (isToolbarLabel(label) ? label.key : label)))
122
+ }
123
+ categoryName={title}
124
+ showToolbarItem={showToolbarItem}
125
+ >
126
+ <Popper
127
+ trigger={
128
+ <MenuToggle
129
+ ouiaId={`${ouiaId}-toggle`}
130
+ ref={toggleRef}
131
+ onClick={handleToggleClick}
132
+ isExpanded={isOpen}
133
+ icon={showIcon ? <FilterIcon /> : undefined}
134
+ badge={value.length > 0 && showBadge ? <Badge data-ouia-component-id={`${ouiaId}-badge`} isRead>{value.length}</Badge> : undefined}
135
+ style={{ width: '200px' }}
136
+ >
137
+ {placeholder ?? title}
138
+ </MenuToggle>
139
+ }
140
+ triggerRef={toggleRef}
141
+ popper={
142
+ <Menu
143
+ ref={menuRef}
144
+ ouiaId={`${ouiaId}-menu`}
145
+ onSelect={handleSelect}
146
+ selected={value}
147
+ {...props}
148
+ >
149
+ <MenuContent>
150
+ <MenuList>
151
+ {normalizeOptions.map(option => (
152
+ <MenuItem
153
+ data-ouia-component-id={`${ouiaId}-filter-item-${option.value}`}
154
+ key={option.value}
155
+ itemId={option.value}
156
+ isSelected={value.includes(option.value)}
157
+ hasCheckbox
158
+ >
159
+ {option.label}
160
+ </MenuItem>
161
+ ))}
162
+ </MenuList>
163
+ </MenuContent>
164
+ </Menu>
165
+ }
166
+ popperRef={menuRef}
167
+ appendTo={containerRef.current || undefined}
168
+ aria-label={`${title ?? filterId} filter`}
169
+ isVisible={isOpen}
170
+ />
171
+ </ToolbarFilter>
172
+ );
173
+ };
174
+
175
+ export default DataViewCheckboxFilter;
@@ -0,0 +1,197 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`DataViewCheckboxFilter component should render correctly 1`] = `
4
+ <div>
5
+ <div
6
+ class="pf-v6-c-toolbar"
7
+ data-ouia-component-id="DataViewToolbar"
8
+ data-ouia-component-type="PF6/Toolbar"
9
+ data-ouia-safe="true"
10
+ id="pf-random-id-0"
11
+ >
12
+ <div
13
+ class="pf-v6-c-toolbar__content"
14
+ >
15
+ <div
16
+ class="pf-v6-c-toolbar__content-section"
17
+ >
18
+ <div
19
+ class="pf-v6-c-toolbar__item"
20
+ >
21
+ <div
22
+ class="pf-v6-c-toolbar__item"
23
+ data-ouia-component-id="DataViewCheckboxFilter"
24
+ >
25
+ <button
26
+ aria-expanded="false"
27
+ class="pf-v6-c-menu-toggle"
28
+ data-ouia-component-id="DataViewCheckboxFilter-toggle"
29
+ data-ouia-component-type="PF6/MenuToggle"
30
+ data-ouia-safe="true"
31
+ style="width: 200px;"
32
+ type="button"
33
+ >
34
+ <span
35
+ class="pf-v6-c-menu-toggle__icon"
36
+ >
37
+ <svg
38
+ aria-hidden="true"
39
+ class="pf-v6-svg"
40
+ fill="currentColor"
41
+ height="1em"
42
+ role="img"
43
+ viewBox="0 0 512 512"
44
+ width="1em"
45
+ >
46
+ <path
47
+ d="M487.976 0H24.028C2.71 0-8.047 25.866 7.058 40.971L192 225.941V432c0 7.831 3.821 15.17 10.237 19.662l80 55.98C298.02 518.69 320 507.493 320 487.98V225.941l184.947-184.97C520.021 25.896 509.338 0 487.976 0z"
48
+ />
49
+ </svg>
50
+ </span>
51
+ <span
52
+ class="pf-v6-c-menu-toggle__text"
53
+ >
54
+ Test Checkbox Filter
55
+ </span>
56
+ <span
57
+ class="pf-v6-c-menu-toggle__count"
58
+ >
59
+ <span
60
+ class="pf-v6-c-badge pf-m-read"
61
+ data-ouia-component-id="DataViewCheckboxFilter-badge"
62
+ >
63
+ 1
64
+ </span>
65
+ </span>
66
+ <span
67
+ class="pf-v6-c-menu-toggle__controls"
68
+ >
69
+ <span
70
+ class="pf-v6-c-menu-toggle__toggle-icon"
71
+ >
72
+ <svg
73
+ aria-hidden="true"
74
+ class="pf-v6-svg"
75
+ fill="currentColor"
76
+ height="1em"
77
+ role="img"
78
+ viewBox="0 0 320 512"
79
+ width="1em"
80
+ >
81
+ <path
82
+ 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"
83
+ />
84
+ </svg>
85
+ </span>
86
+ </span>
87
+ </button>
88
+ </div>
89
+ </div>
90
+ </div>
91
+ </div>
92
+ <div
93
+ class="pf-v6-c-toolbar__content"
94
+ >
95
+ <div
96
+ class="pf-v6-c-toolbar__group"
97
+ >
98
+ <div
99
+ class="pf-v6-c-toolbar__item pf-m-label-group pf-m-label-group"
100
+ >
101
+ <div
102
+ class="pf-v6-c-label-group pf-m-category"
103
+ >
104
+ <div
105
+ class="pf-v6-c-label-group__main"
106
+ >
107
+ <span
108
+ aria-hidden="true"
109
+ class="pf-v6-c-label-group__label"
110
+ id="pf-random-id-1"
111
+ >
112
+ Test Checkbox Filter
113
+ </span>
114
+ <ul
115
+ aria-labelledby="pf-random-id-1"
116
+ class="pf-v6-c-label-group__list"
117
+ role="list"
118
+ >
119
+ <li
120
+ class="pf-v6-c-label-group__list-item"
121
+ >
122
+ <span
123
+ class="pf-v6-c-label pf-m-filled"
124
+ >
125
+ <span
126
+ class="pf-v6-c-label__content"
127
+ >
128
+ <span
129
+ class="pf-v6-c-label__text"
130
+ >
131
+ Workspace one
132
+ </span>
133
+ </span>
134
+ <span
135
+ class="pf-v6-c-label__actions"
136
+ >
137
+ <button
138
+ aria-disabled="false"
139
+ aria-label="Close Workspace one"
140
+ class="pf-v6-c-button pf-m-plain pf-m-no-padding"
141
+ data-ouia-component-id="OUIA-Generated-Button-plain-1"
142
+ data-ouia-component-type="PF6/Button"
143
+ data-ouia-safe="true"
144
+ type="button"
145
+ >
146
+ <span
147
+ class="pf-v6-c-button__icon"
148
+ >
149
+ <svg
150
+ aria-hidden="true"
151
+ class="pf-v6-svg"
152
+ fill="currentColor"
153
+ height="1em"
154
+ role="img"
155
+ viewBox="0 0 352 512"
156
+ width="1em"
157
+ >
158
+ <path
159
+ d="M242.72 256l100.07-100.07c12.28-12.28 12.28-32.19 0-44.48l-22.24-22.24c-12.28-12.28-32.19-12.28-44.48 0L176 189.28 75.93 89.21c-12.28-12.28-32.19-12.28-44.48 0L9.21 111.45c-12.28 12.28-12.28 32.19 0 44.48L109.28 256 9.21 356.07c-12.28 12.28-12.28 32.19 0 44.48l22.24 22.24c12.28 12.28 32.2 12.28 44.48 0L176 322.72l100.07 100.07c12.28 12.28 32.2 12.28 44.48 0l22.24-22.24c12.28-12.28 12.28-32.19 0-44.48L242.72 256z"
160
+ />
161
+ </svg>
162
+ </span>
163
+ </button>
164
+ </span>
165
+ </span>
166
+ </li>
167
+ </ul>
168
+ </div>
169
+ </div>
170
+ </div>
171
+ </div>
172
+ <div
173
+ class="pf-v6-c-toolbar__group pf-m-action-group-inline"
174
+ >
175
+ <div
176
+ class="pf-v6-c-toolbar__item"
177
+ >
178
+ <button
179
+ aria-disabled="false"
180
+ class="pf-v6-c-button pf-m-link pf-m-inline"
181
+ data-ouia-component-id="DataViewToolbar-clear-all-filters"
182
+ data-ouia-component-type="PF6/Button"
183
+ data-ouia-safe="true"
184
+ type="button"
185
+ >
186
+ <span
187
+ class="pf-v6-c-button__text"
188
+ >
189
+ Clear filters
190
+ </span>
191
+ </button>
192
+ </div>
193
+ </div>
194
+ </div>
195
+ </div>
196
+ </div>
197
+ `;
@@ -0,0 +1,2 @@
1
+ export { default } from './DataViewCheckboxFilter';
2
+ export * from './DataViewCheckboxFilter';