@patternfly/react-core 4.266.1 → 4.266.2
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/CHANGELOG.md +11 -0
- package/dist/esm/components/Pagination/Pagination.d.ts +12 -2
- package/dist/esm/components/Pagination/Pagination.d.ts.map +1 -1
- package/dist/esm/components/Pagination/Pagination.js +3 -2
- package/dist/esm/components/Pagination/Pagination.js.map +1 -1
- package/dist/js/components/Pagination/Pagination.d.ts +12 -2
- package/dist/js/components/Pagination/Pagination.d.ts.map +1 -1
- package/dist/js/components/Pagination/Pagination.js +3 -2
- package/dist/js/components/Pagination/Pagination.js.map +1 -1
- package/dist/umd/react-core.min.js +1 -1
- package/package.json +2 -2
- package/src/components/Pagination/Pagination.tsx +17 -2
- package/src/components/Pagination/__tests__/Pagination.test.tsx +21 -0
- package/src/components/Pagination/__tests__/__snapshots__/Pagination.test.tsx.snap +1266 -0
- package/src/components/Pagination/examples/Pagination.md +5 -0
- package/src/components/Pagination/examples/PaginationInset.tsx +37 -0
- package/src/components/Pagination/examples/PaginationSticky.tsx +47 -55
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Pagination } from '@patternfly/react-core';
|
|
3
|
+
|
|
4
|
+
export const PaginationInset: React.FunctionComponent = () => {
|
|
5
|
+
const [page, setPage] = React.useState(1);
|
|
6
|
+
const [perPage, setPerPage] = React.useState(20);
|
|
7
|
+
|
|
8
|
+
const onSetPage = (_event: React.MouseEvent | React.KeyboardEvent | MouseEvent, newPage: number) => {
|
|
9
|
+
setPage(newPage);
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const onPerPageSelect = (
|
|
13
|
+
_event: React.MouseEvent | React.KeyboardEvent | MouseEvent,
|
|
14
|
+
newPerPage: number,
|
|
15
|
+
newPage: number
|
|
16
|
+
) => {
|
|
17
|
+
setPerPage(newPerPage);
|
|
18
|
+
setPage(newPage);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
return (
|
|
22
|
+
<Pagination
|
|
23
|
+
perPageComponent="button"
|
|
24
|
+
itemCount={523}
|
|
25
|
+
perPage={perPage}
|
|
26
|
+
page={page}
|
|
27
|
+
onSetPage={onSetPage}
|
|
28
|
+
widgetId="inset-example"
|
|
29
|
+
onPerPageSelect={onPerPageSelect}
|
|
30
|
+
inset={{
|
|
31
|
+
default: 'insetNone',
|
|
32
|
+
md: 'insetMd',
|
|
33
|
+
lg: 'inset2xl'
|
|
34
|
+
}}
|
|
35
|
+
/>
|
|
36
|
+
);
|
|
37
|
+
};
|
|
@@ -3,8 +3,9 @@ import { Pagination, PaginationVariant, Gallery, GalleryItem, Card, CardBody } f
|
|
|
3
3
|
|
|
4
4
|
export const PaginationSticky: React.FunctionComponent = () => {
|
|
5
5
|
const [page, setPage] = React.useState(1);
|
|
6
|
-
const [perPage, setPerPage] = React.useState(
|
|
6
|
+
const [perPage, setPerPage] = React.useState(100);
|
|
7
7
|
const [isTopSticky, setIsTopSticky] = React.useState(true);
|
|
8
|
+
const itemCount = 523;
|
|
8
9
|
|
|
9
10
|
const onToggleSticky = () => {
|
|
10
11
|
setIsTopSticky(prev => !prev);
|
|
@@ -23,59 +24,50 @@ export const PaginationSticky: React.FunctionComponent = () => {
|
|
|
23
24
|
setPage(newPage);
|
|
24
25
|
};
|
|
25
26
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
)}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
onPerPageSelect={onPerPageSelect}
|
|
72
|
-
isSticky
|
|
73
|
-
variant={PaginationVariant.bottom}
|
|
74
|
-
>
|
|
75
|
-
<button onClick={onToggleSticky}>Toggle to top position</button>
|
|
76
|
-
</Pagination>
|
|
77
|
-
</React.Fragment>
|
|
78
|
-
)}
|
|
79
|
-
</div>
|
|
27
|
+
const buildCards = () => {
|
|
28
|
+
const numberOfCards = (page - 1) * perPage + perPage - 1 >= itemCount ? itemCount - (page - 1) * perPage : perPage;
|
|
29
|
+
|
|
30
|
+
return Array.apply(0, Array(numberOfCards)).map((x, i) => (
|
|
31
|
+
<GalleryItem key={i}>
|
|
32
|
+
<Card>
|
|
33
|
+
<CardBody>This is a card</CardBody>
|
|
34
|
+
</Card>
|
|
35
|
+
</GalleryItem>
|
|
36
|
+
));
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
return isTopSticky ? (
|
|
40
|
+
<React.Fragment>
|
|
41
|
+
<Pagination
|
|
42
|
+
perPageComponent="button"
|
|
43
|
+
itemCount={itemCount}
|
|
44
|
+
perPage={perPage}
|
|
45
|
+
page={page}
|
|
46
|
+
onSetPage={onSetPage}
|
|
47
|
+
widgetId="pagination-options-menu-top"
|
|
48
|
+
onPerPageSelect={onPerPageSelect}
|
|
49
|
+
isSticky
|
|
50
|
+
>
|
|
51
|
+
<button onClick={onToggleSticky}>Toggle to bottom position</button>
|
|
52
|
+
</Pagination>
|
|
53
|
+
<Gallery hasGutter>{buildCards()}</Gallery>
|
|
54
|
+
</React.Fragment>
|
|
55
|
+
) : (
|
|
56
|
+
<React.Fragment>
|
|
57
|
+
<Gallery hasGutter>{buildCards()}</Gallery>
|
|
58
|
+
<Pagination
|
|
59
|
+
perPageComponent="button"
|
|
60
|
+
itemCount={itemCount}
|
|
61
|
+
perPage={perPage}
|
|
62
|
+
page={page}
|
|
63
|
+
onSetPage={onSetPage}
|
|
64
|
+
widgetId="pagination-options-menu-top"
|
|
65
|
+
onPerPageSelect={onPerPageSelect}
|
|
66
|
+
isSticky
|
|
67
|
+
variant={PaginationVariant.bottom}
|
|
68
|
+
>
|
|
69
|
+
<button onClick={onToggleSticky}>Toggle to top position</button>
|
|
70
|
+
</Pagination>
|
|
71
|
+
</React.Fragment>
|
|
80
72
|
);
|
|
81
73
|
};
|