@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.
@@ -49,3 +49,8 @@ By not passing `itemCount` and passing `toggleTemplate` you can customize the to
49
49
 
50
50
  ```ts isFullscreen file="./PaginationSticky.tsx"
51
51
  ```
52
+
53
+ ### Inset
54
+
55
+ ```ts file="./PaginationInset.tsx" isBeta
56
+ ```
@@ -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(20);
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
- return (
27
- <div>
28
- {isTopSticky && (
29
- <React.Fragment>
30
- <Pagination
31
- perPageComponent="button"
32
- itemCount={523}
33
- perPage={perPage}
34
- page={page}
35
- onSetPage={onSetPage}
36
- widgetId="sticky-example"
37
- onPerPageSelect={onPerPageSelect}
38
- isSticky
39
- >
40
- <button onClick={onToggleSticky}>Toggle to bottom position</button>
41
- </Pagination>
42
- <Gallery hasGutter>
43
- {Array.apply(0, Array(40)).map((x, i) => (
44
- <GalleryItem key={i}>
45
- <Card>
46
- <CardBody>This is a card</CardBody>
47
- </Card>
48
- </GalleryItem>
49
- ))}
50
- </Gallery>
51
- </React.Fragment>
52
- )}
53
- {!isTopSticky && (
54
- <React.Fragment>
55
- <Gallery hasGutter>
56
- {Array.apply(0, Array(40)).map((x, i) => (
57
- <GalleryItem key={i}>
58
- <Card>
59
- <CardBody>This is a card</CardBody>
60
- </Card>
61
- </GalleryItem>
62
- ))}
63
- </Gallery>
64
- <Pagination
65
- perPageComponent="button"
66
- itemCount={523}
67
- perPage={perPage}
68
- page={page}
69
- onSetPage={onSetPage}
70
- widgetId="pagination-options-menu-top"
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
  };