@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,2 @@
1
+ export { default } from './DataViewTableTree';
2
+ export * from './DataViewTableTree';
@@ -0,0 +1,24 @@
1
+ import React from 'react';
2
+ import { render } from '@testing-library/react';
3
+ import DataViewTextFilter, { DataViewTextFilterProps } from './DataViewTextFilter';
4
+ import DataViewToolbar from '../DataViewToolbar';
5
+
6
+ describe('DataViewTextFilter component', () => {
7
+ const mockOnChange = jest.fn();
8
+
9
+ const defaultProps: DataViewTextFilterProps = {
10
+ filterId: 'test-filter',
11
+ title: 'Test Filter',
12
+ value: 'initial value',
13
+ onChange: mockOnChange,
14
+ };
15
+
16
+ it('should render correctly', () => {
17
+ const { container } = render(<DataViewToolbar
18
+ filters={
19
+ <DataViewTextFilter {...defaultProps} />
20
+ }
21
+ />);
22
+ expect(container).toMatchSnapshot();
23
+ });
24
+ });
@@ -0,0 +1,54 @@
1
+ import React from 'react';
2
+ import { SearchInput, SearchInputProps, ToolbarFilter, ToolbarFilterProps } from '@patternfly/react-core';
3
+
4
+ /** extends SearchInputProps */
5
+ export interface DataViewTextFilterProps extends SearchInputProps {
6
+ /** Unique key for the filter attribute */
7
+ filterId: string;
8
+ /** Current filter value */
9
+ value?: string;
10
+ /** Filter title displayed in the toolbar */
11
+ title: string;
12
+ /** Callback for when the input value changes */
13
+ onChange?: (event: React.FormEvent<HTMLInputElement> | undefined, value: string) => void;
14
+ /** Controls visibility of the filter in the toolbar */
15
+ showToolbarItem?: ToolbarFilterProps['showToolbarItem'];
16
+ /** Trims input value on change */
17
+ trimValue?: boolean;
18
+ /** Custom OUIA ID */
19
+ ouiaId?: string;
20
+ }
21
+
22
+ export const DataViewTextFilter: React.FC<DataViewTextFilterProps> = ({
23
+ filterId,
24
+ title,
25
+ value = '',
26
+ onChange,
27
+ onClear = () => onChange?.(undefined, ''),
28
+ showToolbarItem,
29
+ trimValue = true,
30
+ ouiaId = 'DataViewTextFilter',
31
+ ...props
32
+ }: DataViewTextFilterProps) => (
33
+ <ToolbarFilter
34
+ key={ouiaId}
35
+ data-ouia-component-id={ouiaId}
36
+ labels={value.length > 0 ? [ { key: title, node: value } ] : []}
37
+ deleteLabel={() => onChange?.(undefined, '')}
38
+ categoryName={title}
39
+ showToolbarItem={showToolbarItem}
40
+ >
41
+ <SearchInput
42
+ searchInputId={filterId}
43
+ value={value}
44
+ onChange={(e, inputValue) => onChange?.(e, trimValue ? inputValue.trim() : inputValue)}
45
+ onClear={onClear}
46
+ placeholder={`Filter by ${title}`}
47
+ aria-label={`${title ?? filterId} filter`}
48
+ data-ouia-component-id={`${ouiaId}-input`}
49
+ {...props}
50
+ />
51
+ </ToolbarFilter>
52
+ );
53
+
54
+ export default DataViewTextFilter;
@@ -0,0 +1,203 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`DataViewTextFilter 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="DataViewTextFilter"
24
+ >
25
+ <div
26
+ class="pf-v6-c-text-input-group"
27
+ data-ouia-component-id="DataViewTextFilter-input"
28
+ >
29
+ <div
30
+ class="pf-v6-c-text-input-group__main pf-m-icon"
31
+ >
32
+ <span
33
+ class="pf-v6-c-text-input-group__text"
34
+ >
35
+ <span
36
+ class="pf-v6-c-text-input-group__icon"
37
+ >
38
+ <svg
39
+ aria-hidden="true"
40
+ class="pf-v6-svg"
41
+ fill="currentColor"
42
+ height="1em"
43
+ role="img"
44
+ viewBox="0 0 512 512"
45
+ width="1em"
46
+ >
47
+ <path
48
+ d="M505 442.7L405.3 343c-4.5-4.5-10.6-7-17-7H372c27.6-35.3 44-79.7 44-128C416 93.1 322.9 0 208 0S0 93.1 0 208s93.1 208 208 208c48.3 0 92.7-16.4 128-44v16.3c0 6.4 2.5 12.5 7 17l99.7 99.7c9.4 9.4 24.6 9.4 33.9 0l28.3-28.3c9.4-9.4 9.4-24.6.1-34zM208 336c-70.7 0-128-57.2-128-128 0-70.7 57.2-128 128-128 70.7 0 128 57.2 128 128 0 70.7-57.2 128-128 128z"
49
+ />
50
+ </svg>
51
+ </span>
52
+ <input
53
+ aria-label="Test Filter filter"
54
+ class="pf-v6-c-text-input-group__text-input"
55
+ id="test-filter"
56
+ placeholder="Filter by Test Filter"
57
+ type="text"
58
+ value="initial value"
59
+ />
60
+ </span>
61
+ </div>
62
+ <div
63
+ class="pf-v6-c-text-input-group__utilities"
64
+ >
65
+ <button
66
+ aria-disabled="false"
67
+ aria-label="Reset"
68
+ class="pf-v6-c-button pf-m-plain"
69
+ data-ouia-component-id="OUIA-Generated-Button-plain-2"
70
+ data-ouia-component-type="PF6/Button"
71
+ data-ouia-safe="true"
72
+ type="button"
73
+ >
74
+ <span
75
+ class="pf-v6-c-button__icon"
76
+ >
77
+ <svg
78
+ aria-hidden="true"
79
+ class="pf-v6-svg"
80
+ fill="currentColor"
81
+ height="1em"
82
+ role="img"
83
+ viewBox="0 0 352 512"
84
+ width="1em"
85
+ >
86
+ <path
87
+ 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"
88
+ />
89
+ </svg>
90
+ </span>
91
+ </button>
92
+ </div>
93
+ </div>
94
+ </div>
95
+ </div>
96
+ </div>
97
+ </div>
98
+ <div
99
+ class="pf-v6-c-toolbar__content"
100
+ >
101
+ <div
102
+ class="pf-v6-c-toolbar__group"
103
+ >
104
+ <div
105
+ class="pf-v6-c-toolbar__item pf-m-label-group pf-m-label-group"
106
+ >
107
+ <div
108
+ class="pf-v6-c-label-group pf-m-category"
109
+ >
110
+ <div
111
+ class="pf-v6-c-label-group__main"
112
+ >
113
+ <span
114
+ aria-hidden="true"
115
+ class="pf-v6-c-label-group__label"
116
+ id="pf-random-id-1"
117
+ >
118
+ Test Filter
119
+ </span>
120
+ <ul
121
+ aria-labelledby="pf-random-id-1"
122
+ class="pf-v6-c-label-group__list"
123
+ role="list"
124
+ >
125
+ <li
126
+ class="pf-v6-c-label-group__list-item"
127
+ >
128
+ <span
129
+ class="pf-v6-c-label pf-m-filled"
130
+ >
131
+ <span
132
+ class="pf-v6-c-label__content"
133
+ >
134
+ <span
135
+ class="pf-v6-c-label__text"
136
+ >
137
+ initial value
138
+ </span>
139
+ </span>
140
+ <span
141
+ class="pf-v6-c-label__actions"
142
+ >
143
+ <button
144
+ aria-disabled="false"
145
+ aria-label="Close initial value"
146
+ class="pf-v6-c-button pf-m-plain pf-m-no-padding"
147
+ data-ouia-component-id="OUIA-Generated-Button-plain-3"
148
+ data-ouia-component-type="PF6/Button"
149
+ data-ouia-safe="true"
150
+ type="button"
151
+ >
152
+ <span
153
+ class="pf-v6-c-button__icon"
154
+ >
155
+ <svg
156
+ aria-hidden="true"
157
+ class="pf-v6-svg"
158
+ fill="currentColor"
159
+ height="1em"
160
+ role="img"
161
+ viewBox="0 0 352 512"
162
+ width="1em"
163
+ >
164
+ <path
165
+ 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"
166
+ />
167
+ </svg>
168
+ </span>
169
+ </button>
170
+ </span>
171
+ </span>
172
+ </li>
173
+ </ul>
174
+ </div>
175
+ </div>
176
+ </div>
177
+ </div>
178
+ <div
179
+ class="pf-v6-c-toolbar__group pf-m-action-group-inline"
180
+ >
181
+ <div
182
+ class="pf-v6-c-toolbar__item"
183
+ >
184
+ <button
185
+ aria-disabled="false"
186
+ class="pf-v6-c-button pf-m-link pf-m-inline"
187
+ data-ouia-component-id="DataViewToolbar-clear-all-filters"
188
+ data-ouia-component-type="PF6/Button"
189
+ data-ouia-safe="true"
190
+ type="button"
191
+ >
192
+ <span
193
+ class="pf-v6-c-button__text"
194
+ >
195
+ Clear filters
196
+ </span>
197
+ </button>
198
+ </div>
199
+ </div>
200
+ </div>
201
+ </div>
202
+ </div>
203
+ `;
@@ -0,0 +1,2 @@
1
+ export { default } from './DataViewTextFilter';
2
+ export * from './DataViewTextFilter';
@@ -1,34 +1,67 @@
1
- import React, { PropsWithChildren } from 'react';
2
- import { Toolbar, ToolbarContent, ToolbarItem, ToolbarItemVariant } from '@patternfly/react-core';
1
+ import React, { PropsWithChildren, useRef } from 'react';
2
+ import { Button, Toolbar, ToolbarContent, ToolbarItem, ToolbarItemVariant, ToolbarProps } from '@patternfly/react-core';
3
3
 
4
- export interface DataViewToolbarProps extends PropsWithChildren {
4
+ /** extends ToolbarProps */
5
+ export interface DataViewToolbarProps extends Omit<PropsWithChildren<ToolbarProps>, 'ref'> {
5
6
  /** Toolbar className */
6
7
  className?: string;
7
8
  /** Custom OUIA ID */
8
9
  ouiaId?: string;
9
- /** React component to display bulk select */
10
+ /** React node to display bulk select */
10
11
  bulkSelect?: React.ReactNode;
11
- /** React component to display pagination */
12
+ /** React node to display pagination */
12
13
  pagination?: React.ReactNode;
14
+ /** React node to display actions */
15
+ actions?: React.ReactNode;
16
+ /** React node to display toggle group */
17
+ toggleGroup?: React.ReactNode;
18
+ /** React node to display filters */
19
+ filters?: React.ReactNode;
20
+ /** React node to display custom filter labels */
21
+ customLabelGroupContent?: React.ReactNode;
13
22
  }
14
23
 
15
- export const DataViewToolbar: React.FC<DataViewToolbarProps> = ({ className, ouiaId = 'DataViewToolbar', bulkSelect, pagination, children, ...props }: DataViewToolbarProps) => (
16
- <Toolbar ouiaId={ouiaId} className={className} {...props}>
17
- <ToolbarContent>
18
- {bulkSelect && (
19
- <ToolbarItem data-ouia-component-id={`${ouiaId}-bulk-select`}>
20
- {bulkSelect}
21
- </ToolbarItem>
22
- )}
23
- {pagination && (
24
- <ToolbarItem variant={ToolbarItemVariant.pagination} data-ouia-component-id={`${ouiaId}-pagination`}>
25
- {pagination}
26
- </ToolbarItem>
27
- )}
28
- {children}
29
- </ToolbarContent>
30
- </Toolbar>
31
- );
24
+ export const DataViewToolbar: React.FC<DataViewToolbarProps> = ({ className, ouiaId = 'DataViewToolbar', bulkSelect, actions, toggleGroup, pagination, filters, customLabelGroupContent, clearAllFilters, children, ...props }: DataViewToolbarProps) => {
25
+ const defaultClearFilters = useRef(
26
+ <ToolbarItem>
27
+ <Button ouiaId={`${ouiaId}-clear-all-filters`} variant="link" onClick={clearAllFilters} isInline>
28
+ Clear filters
29
+ </Button>
30
+ </ToolbarItem>
31
+ );
32
+ return (
33
+ <Toolbar ouiaId={ouiaId} className={className} customLabelGroupContent={customLabelGroupContent ?? defaultClearFilters.current} {...props}>
34
+ <ToolbarContent>
35
+ {bulkSelect && (
36
+ <ToolbarItem data-ouia-component-id={`${ouiaId}-bulk-select`}>
37
+ {bulkSelect}
38
+ </ToolbarItem>
39
+ )}
40
+ {filters && (
41
+ <ToolbarItem>
42
+ {filters}
43
+ </ToolbarItem>
44
+ )}
45
+ {actions && (
46
+ <ToolbarItem>
47
+ {actions}
48
+ </ToolbarItem>
49
+ )}
50
+ {toggleGroup && (
51
+ <ToolbarItem>
52
+ {toggleGroup}
53
+ </ToolbarItem>
54
+ )}
55
+ {pagination && (
56
+ <ToolbarItem variant={ToolbarItemVariant.pagination} data-ouia-component-id={`${ouiaId}-pagination`}>
57
+ {pagination}
58
+ </ToolbarItem>
59
+ )}
60
+ {children}
61
+ </ToolbarContent>
62
+ </Toolbar>
63
+ )
64
+ };
32
65
 
33
66
  export default DataViewToolbar;
34
67
 
@@ -117,7 +117,7 @@ exports[`DataViewToolbar component should render correctly 1`] = `
117
117
  type="button"
118
118
  >
119
119
  <span
120
- class="pf-v6-c-button__icon pf-m-start"
120
+ class="pf-v6-c-button__icon"
121
121
  >
122
122
  <svg
123
123
  aria-hidden="true"
@@ -150,7 +150,7 @@ exports[`DataViewToolbar component should render correctly 1`] = `
150
150
  type="button"
151
151
  >
152
152
  <span
153
- class="pf-v6-c-button__icon pf-m-start"
153
+ class="pf-v6-c-button__icon"
154
154
  >
155
155
  <svg
156
156
  aria-hidden="true"
@@ -201,7 +201,7 @@ exports[`DataViewToolbar component should render correctly 1`] = `
201
201
  type="button"
202
202
  >
203
203
  <span
204
- class="pf-v6-c-button__icon pf-m-start"
204
+ class="pf-v6-c-button__icon"
205
205
  >
206
206
  <svg
207
207
  aria-hidden="true"
@@ -233,7 +233,7 @@ exports[`DataViewToolbar component should render correctly 1`] = `
233
233
  type="button"
234
234
  >
235
235
  <span
236
- class="pf-v6-c-button__icon pf-m-start"
236
+ class="pf-v6-c-button__icon"
237
237
  >
238
238
  <svg
239
239
  aria-hidden="true"
@@ -263,6 +263,28 @@ exports[`DataViewToolbar component should render correctly 1`] = `
263
263
  <div
264
264
  class="pf-v6-c-toolbar__group"
265
265
  />
266
+ <div
267
+ class="pf-v6-c-toolbar__group pf-m-action-group-inline"
268
+ >
269
+ <div
270
+ class="pf-v6-c-toolbar__item"
271
+ >
272
+ <button
273
+ aria-disabled="false"
274
+ class="pf-v6-c-button pf-m-link pf-m-inline"
275
+ data-ouia-component-id="DataViewToolbar-clear-all-filters"
276
+ data-ouia-component-type="PF6/Button"
277
+ data-ouia-safe="true"
278
+ type="button"
279
+ >
280
+ <span
281
+ class="pf-v6-c-button__text"
282
+ >
283
+ Clear filters
284
+ </span>
285
+ </button>
286
+ </div>
287
+ </div>
266
288
  </div>
267
289
  </div>
268
290
  </div>
@@ -380,7 +402,7 @@ exports[`DataViewToolbar component should render correctly 1`] = `
380
402
  type="button"
381
403
  >
382
404
  <span
383
- class="pf-v6-c-button__icon pf-m-start"
405
+ class="pf-v6-c-button__icon"
384
406
  >
385
407
  <svg
386
408
  aria-hidden="true"
@@ -413,7 +435,7 @@ exports[`DataViewToolbar component should render correctly 1`] = `
413
435
  type="button"
414
436
  >
415
437
  <span
416
- class="pf-v6-c-button__icon pf-m-start"
438
+ class="pf-v6-c-button__icon"
417
439
  >
418
440
  <svg
419
441
  aria-hidden="true"
@@ -464,7 +486,7 @@ exports[`DataViewToolbar component should render correctly 1`] = `
464
486
  type="button"
465
487
  >
466
488
  <span
467
- class="pf-v6-c-button__icon pf-m-start"
489
+ class="pf-v6-c-button__icon"
468
490
  >
469
491
  <svg
470
492
  aria-hidden="true"
@@ -496,7 +518,7 @@ exports[`DataViewToolbar component should render correctly 1`] = `
496
518
  type="button"
497
519
  >
498
520
  <span
499
- class="pf-v6-c-button__icon pf-m-start"
521
+ class="pf-v6-c-button__icon"
500
522
  >
501
523
  <svg
502
524
  aria-hidden="true"
@@ -526,6 +548,28 @@ exports[`DataViewToolbar component should render correctly 1`] = `
526
548
  <div
527
549
  class="pf-v6-c-toolbar__group"
528
550
  />
551
+ <div
552
+ class="pf-v6-c-toolbar__group pf-m-action-group-inline"
553
+ >
554
+ <div
555
+ class="pf-v6-c-toolbar__item"
556
+ >
557
+ <button
558
+ aria-disabled="false"
559
+ class="pf-v6-c-button pf-m-link pf-m-inline"
560
+ data-ouia-component-id="DataViewToolbar-clear-all-filters"
561
+ data-ouia-component-type="PF6/Button"
562
+ data-ouia-safe="true"
563
+ type="button"
564
+ >
565
+ <span
566
+ class="pf-v6-c-button__text"
567
+ >
568
+ Clear filters
569
+ </span>
570
+ </button>
571
+ </div>
572
+ </div>
529
573
  </div>
530
574
  </div>
531
575
  </div>,
@@ -0,0 +1,89 @@
1
+ import '@testing-library/jest-dom';
2
+ import { renderHook, act } from '@testing-library/react';
3
+ import { useDataViewFilters, UseDataViewFiltersProps } from './filters';
4
+
5
+ describe('useDataViewFilters', () => {
6
+ const initialFilters = { search: 'test', tags: [ 'tag1', 'tag2' ] };
7
+
8
+ it('should initialize with provided initial filters', () => {
9
+ const { result } = renderHook(() => useDataViewFilters({ initialFilters }));
10
+ expect(result.current.filters).toEqual(initialFilters);
11
+ });
12
+
13
+ it('should initialize with empty filters if no initialFilters provided', () => {
14
+ const { result } = renderHook(() => useDataViewFilters({}));
15
+ expect(result.current.filters).toEqual({});
16
+ });
17
+
18
+ it('should set filters correctly', () => {
19
+ const { result } = renderHook(() => useDataViewFilters({ initialFilters }));
20
+ const newFilters = { search: 'new search' };
21
+ act(() => result.current.onSetFilters(newFilters));
22
+
23
+ expect(result.current.filters).toEqual({ ...initialFilters, ...newFilters });
24
+ });
25
+
26
+ it('should delete specific filters without removing keys', () => {
27
+ const { result } = renderHook(() => useDataViewFilters({ initialFilters }));
28
+ const filtersToDelete = { search: 'test' };
29
+ act(() => result.current.onDeleteFilters(filtersToDelete));
30
+
31
+ expect(result.current.filters).toEqual({ search: '', tags: [ 'tag1', 'tag2' ] });
32
+ });
33
+
34
+ it('should clear all filters', () => {
35
+ const { result } = renderHook(() => useDataViewFilters({ initialFilters }));
36
+ act(() => result.current.clearAllFilters());
37
+
38
+ expect(result.current.filters).toEqual({ search: '', tags: [] });
39
+ });
40
+
41
+ it('should sync with URL search params if isUrlSyncEnabled', () => {
42
+ const searchParams = new URLSearchParams();
43
+ const setSearchParams = jest.fn();
44
+ const props: UseDataViewFiltersProps<typeof initialFilters> = {
45
+ initialFilters,
46
+ searchParams,
47
+ setSearchParams,
48
+ };
49
+
50
+ const { result } = renderHook(() => useDataViewFilters(props));
51
+ act(() => result.current.onSetFilters({ search: 'new search' }));
52
+
53
+ expect(setSearchParams).toHaveBeenCalled();
54
+ });
55
+
56
+ it('should sync with URL search params with non array value', () => {
57
+ const searchParams = new URLSearchParams();
58
+ searchParams.set('test', 'foo');
59
+ const setSearchParams = jest.fn();
60
+ const props: UseDataViewFiltersProps<{ test: string }> = {
61
+ initialFilters: { test: '' },
62
+ searchParams,
63
+ setSearchParams,
64
+ };
65
+ const { result } = renderHook(() => useDataViewFilters(props));
66
+ expect(result.current.filters).toEqual({ test: 'foo' });
67
+ })
68
+ it('should sync with URL search params with array value', () => {
69
+
70
+ const searchParams = new URLSearchParams();
71
+ searchParams.append('test', 'foo');
72
+ searchParams.append('test', 'bar');
73
+ const setSearchParams = jest.fn();
74
+ const props: UseDataViewFiltersProps<{ test: string[] }> = {
75
+ initialFilters: { test: [] },
76
+ searchParams,
77
+ setSearchParams,
78
+ };
79
+ const { result } = renderHook(() => useDataViewFilters(props));
80
+ expect(result.current.filters).toEqual({ test: [ 'foo', 'bar' ] });
81
+ })
82
+
83
+ it('should reset filters to default values when clearAllFilters is called', () => {
84
+ const { result } = renderHook(() => useDataViewFilters({ initialFilters }));
85
+ act(() => result.current.clearAllFilters());
86
+
87
+ expect(result.current.filters).toEqual({ search: '', tags: [] });
88
+ });
89
+ });