@patternfly/react-data-view 1.0.0-prerelease.3 → 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.
- package/dist/cjs/DataView/DataView.test.d.ts +1 -1
- package/dist/cjs/DataView/DataView.test.js +12 -6
- package/dist/cjs/DataViewToolbar/DataViewToolbar.d.ts +5 -3
- package/dist/cjs/DataViewToolbar/DataViewToolbar.js +3 -2
- package/dist/cjs/DataViewToolbar/DataViewToolbar.test.js +14 -0
- package/dist/cjs/Hooks/index.d.ts +2 -1
- package/dist/cjs/Hooks/index.js +2 -1
- package/dist/cjs/Hooks/pagination.d.ts +16 -0
- package/dist/cjs/Hooks/pagination.js +16 -0
- package/dist/cjs/Hooks/pagination.test.d.ts +1 -0
- package/dist/cjs/Hooks/pagination.test.js +49 -0
- package/dist/cjs/Hooks/selection.d.ts +11 -0
- package/dist/cjs/Hooks/selection.js +26 -0
- package/dist/cjs/Hooks/selection.test.d.ts +1 -0
- package/dist/cjs/Hooks/selection.test.js +55 -0
- package/dist/esm/DataView/DataView.test.d.ts +1 -1
- package/dist/esm/DataView/DataView.test.js +13 -7
- package/dist/esm/DataViewToolbar/DataViewToolbar.d.ts +5 -3
- package/dist/esm/DataViewToolbar/DataViewToolbar.js +3 -2
- package/dist/esm/DataViewToolbar/DataViewToolbar.test.d.ts +1 -0
- package/dist/esm/DataViewToolbar/DataViewToolbar.test.js +9 -0
- package/dist/esm/Hooks/index.d.ts +2 -1
- package/dist/esm/Hooks/index.js +2 -1
- package/dist/esm/Hooks/pagination.d.ts +16 -0
- package/dist/esm/Hooks/pagination.js +12 -0
- package/dist/esm/Hooks/pagination.test.d.ts +1 -0
- package/dist/esm/Hooks/pagination.test.js +47 -0
- package/dist/esm/Hooks/selection.d.ts +11 -0
- package/dist/esm/Hooks/selection.js +22 -0
- package/dist/esm/Hooks/selection.test.d.ts +1 -0
- package/dist/esm/Hooks/selection.test.js +53 -0
- package/generate-fed-package-json.js +7 -8
- package/generate-index.js +2 -2
- package/package.json +7 -6
- package/patternfly-docs/content/extensions/data-view/examples/{DataViewToolbar/DataViewToolbar.md → Components/Components.md} +9 -5
- package/patternfly-docs/content/extensions/data-view/examples/Components/DataViewToolbarExample.tsx +20 -0
- package/patternfly-docs/content/extensions/data-view/examples/Functionality/Functionality.md +77 -0
- package/patternfly-docs/content/extensions/data-view/examples/Functionality/PaginationExample.tsx +65 -0
- package/patternfly-docs/content/extensions/data-view/examples/Functionality/SelectionExample.tsx +88 -0
- package/patternfly-docs/content/extensions/data-view/examples/{DataView/DataView.md → Layout/Layout.md} +9 -6
- package/patternfly-docs/content/extensions/data-view/examples/Layout/PredefinedLayoutExample.tsx +120 -0
- package/src/DataView/DataView.test.tsx +16 -8
- package/src/DataView/__snapshots__/DataView.test.tsx.snap +134 -0
- package/src/DataViewToolbar/DataViewToolbar.test.tsx +11 -0
- package/src/DataViewToolbar/DataViewToolbar.tsx +12 -5
- package/src/DataViewToolbar/__snapshots__/DataViewToolbar.test.tsx.snap +538 -0
- package/src/Hooks/index.ts +2 -1
- package/src/Hooks/pagination.test.tsx +57 -0
- package/src/Hooks/pagination.ts +31 -0
- package/src/Hooks/selection.test.tsx +52 -0
- package/src/Hooks/selection.ts +32 -0
- package/dist/cjs/Hooks/useDataViewPagination.d.ts +0 -4
- package/dist/cjs/Hooks/useDataViewPagination.js +0 -2
- package/dist/esm/Hooks/useDataViewPagination.d.ts +0 -4
- package/patternfly-docs/content/extensions/data-view/examples/DataView/DataViewPredefinedLayoutExample.tsx +0 -24
- package/patternfly-docs/content/extensions/data-view/examples/DataViewToolbar/DataViewToolbarExample.tsx +0 -7
- package/patternfly-docs/content/extensions/data-view/examples/Hooks/Hooks.md +0 -23
- package/src/Hooks/useDataViewPagination.ts +0 -4
- /package/dist/{esm/Hooks/useDataViewPagination.js → cjs/DataViewToolbar/DataViewToolbar.test.d.ts} +0 -0
- /package/patternfly-docs/content/extensions/data-view/examples/{DataView/DataViewLayoutExample.tsx → Layout/AbstractLayoutExample.tsx} +0 -0
|
@@ -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,24 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { Pagination } from '@patternfly/react-core';
|
|
3
|
-
import DataView from '@patternfly/react-data-view/dist/dynamic/DataView';
|
|
4
|
-
import DataViewToolbar from '@patternfly/react-data-view/dist/dynamic/DataViewToolbar';
|
|
5
|
-
|
|
6
|
-
const layoutItemStyling = {
|
|
7
|
-
width: '100%',
|
|
8
|
-
height: '5rem',
|
|
9
|
-
padding: 'var(--pf-t--global--spacer--md)',
|
|
10
|
-
border: 'var(--pf-t--global--border--width--box--default) dashed var(--pf-t--global--border--color--default)'
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
const PAGINATION = {
|
|
14
|
-
page: 1,
|
|
15
|
-
perPage: 1
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export const BasicExample: React.FunctionComponent = () => (
|
|
19
|
-
<DataView>
|
|
20
|
-
<DataViewToolbar pagination={<Pagination {...PAGINATION} />} />
|
|
21
|
-
<div style={layoutItemStyling}>Data representation</div>
|
|
22
|
-
<DataViewToolbar pagination={<Pagination isCompact {...PAGINATION} ouiaId="DataViewFooter" />} />
|
|
23
|
-
</DataView>
|
|
24
|
-
)
|
|
@@ -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,23 +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 (`setPage`, `setPerPage`)
|
|
21
|
-
|
|
22
|
-
Coming soon...
|
|
23
|
-
|
/package/dist/{esm/Hooks/useDataViewPagination.js → cjs/DataViewToolbar/DataViewToolbar.test.d.ts}
RENAMED
|
File without changes
|