playbook_ui 13.34.1.pre.alpha.pbntr258paginationkitforreact3411 → 13.34.1.pre.alpha.pbntr258paginationkitforreact3413
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/pb_kits/playbook/pb_pagination/_pagination.tsx +36 -33
- data/app/pb_kits/playbook/pb_pagination/docs/_pagination_default.jsx +8 -8
- data/app/pb_kits/playbook/pb_pagination/docs/_pagination_page_change.jsx +62 -0
- data/app/pb_kits/playbook/pb_pagination/docs/_pagination_page_change_react.md +1 -0
- data/app/pb_kits/playbook/pb_pagination/docs/data.js +23 -0
- data/app/pb_kits/playbook/pb_pagination/docs/example.yml +1 -0
- data/app/pb_kits/playbook/pb_pagination/docs/index.js +1 -0
- data/dist/chunks/{_weekday_stacked-D9CcK1cg.js → _weekday_stacked-Im-AfPJB.js} +1 -1
- data/dist/chunks/vendor.js +1 -1
- data/dist/playbook-doc.js +1 -1
- data/lib/playbook/version.rb +1 -1
- metadata +6 -3
- /data/app/pb_kits/playbook/pb_pagination/docs/{_pagination_default.md → _pagination_default_rails.md} +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2bea719eca117b3ff8e23aba95b5710c602ce62098e30fbd550fd2d0ff3dc5c1
|
4
|
+
data.tar.gz: 4a2a8910650f8f3ed883b567f1020554ec90060ebd5d7ddb5450867e6d5547e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 15144042ed78f1e9f87afc63a8c05e7ea9d3518156b0ec4fa254d1d002abc94c1cc070ac1dc70660bee5a3ebee8fac9e12b817525b3072e2d92b89ec3f6d7025
|
7
|
+
data.tar.gz: 9d195fbb90dfd2da29c1a7691bda478df7dfd4b25c0bf56b18a7be729c3ca19627381a56a020476ee641660b4c912e4450082259901e5cfe5ea79ab6968d6574
|
@@ -2,40 +2,42 @@ import React, { useState } from "react";
|
|
2
2
|
import Icon from '../pb_icon/_icon';
|
3
3
|
|
4
4
|
type PaginationProps = {
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
current?: number;
|
6
|
+
onChange?: (pageNumber: number) => void;
|
7
|
+
range?: number;
|
8
|
+
total?: number;
|
9
9
|
};
|
10
10
|
|
11
11
|
const Pagination = ({
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
current = 1,
|
13
|
+
onChange,
|
14
|
+
range = 5,
|
15
|
+
total = 1,
|
16
16
|
}: PaginationProps) => {
|
17
|
-
const [currentPage, setCurrentPage] = useState(
|
17
|
+
const [currentPage, setCurrentPage] = useState(current);
|
18
18
|
|
19
19
|
const handlePageChange = (pageNumber: number) => {
|
20
|
-
if (pageNumber >= 1 && pageNumber <=
|
20
|
+
if (pageNumber >= 1 && pageNumber <= total) {
|
21
21
|
setCurrentPage(pageNumber);
|
22
|
-
|
22
|
+
if (onChange) {
|
23
|
+
onChange(pageNumber);
|
24
|
+
}
|
23
25
|
}
|
24
26
|
};
|
25
27
|
|
26
|
-
const renderPageButtons = () => {
|
27
|
-
const buttons = [];
|
28
|
-
|
28
|
+
const renderPageButtons = (): JSX.Element[] => {
|
29
|
+
const buttons: JSX.Element[] = [];
|
30
|
+
|
29
31
|
// Calculate pagination range with let
|
30
|
-
let rangeStart = Math.max(1, currentPage - Math.floor(
|
31
|
-
let rangeEnd = Math.min(
|
32
|
-
|
33
|
-
// Adjust range if it's too short to fit the
|
34
|
-
if (rangeEnd - rangeStart + 1 <
|
32
|
+
let rangeStart = Math.max(1, currentPage - Math.floor(range / 2));
|
33
|
+
let rangeEnd = Math.min(total, rangeStart + range - 1);
|
34
|
+
|
35
|
+
// Adjust range if it's too short to fit the range
|
36
|
+
if (rangeEnd - rangeStart + 1 < range) {
|
35
37
|
if (rangeStart > 1) {
|
36
|
-
rangeStart = Math.max(1, rangeEnd -
|
38
|
+
rangeStart = Math.max(1, rangeEnd - range + 1);
|
37
39
|
} else {
|
38
|
-
rangeEnd = Math.min(
|
40
|
+
rangeEnd = Math.min(total, rangeStart + range - 1);
|
39
41
|
}
|
40
42
|
}
|
41
43
|
|
@@ -51,7 +53,7 @@ const Pagination = ({
|
|
51
53
|
</button>
|
52
54
|
);
|
53
55
|
}
|
54
|
-
|
56
|
+
|
55
57
|
// Always display the second page button
|
56
58
|
if (rangeStart > 2) {
|
57
59
|
buttons.push(
|
@@ -79,33 +81,34 @@ const Pagination = ({
|
|
79
81
|
}
|
80
82
|
|
81
83
|
// Always display the second-to-last page button
|
82
|
-
if (rangeEnd <
|
84
|
+
if (rangeEnd < total - 1) {
|
83
85
|
buttons.push(
|
84
86
|
<button
|
85
|
-
className={`pagination-number ${
|
86
|
-
key={
|
87
|
-
onClick={() => handlePageChange(
|
87
|
+
className={`pagination-number ${total - 1 === currentPage ? "active" : ""}`}
|
88
|
+
key={total - 1}
|
89
|
+
onClick={() => handlePageChange(total - 1)}
|
88
90
|
>
|
89
|
-
{
|
91
|
+
{total - 1}
|
90
92
|
</button>
|
91
93
|
);
|
92
94
|
}
|
93
95
|
|
94
96
|
// Always display the last page button
|
95
|
-
if (rangeEnd <
|
97
|
+
if (rangeEnd < total) {
|
96
98
|
buttons.push(
|
97
99
|
<button
|
98
|
-
className={`pagination-number ${
|
99
|
-
key={
|
100
|
-
onClick={() => handlePageChange(
|
100
|
+
className={`pagination-number ${total === currentPage ? "active" : ""}`}
|
101
|
+
key={total}
|
102
|
+
onClick={() => handlePageChange(total)}
|
101
103
|
>
|
102
|
-
{
|
104
|
+
{total}
|
103
105
|
</button>
|
104
106
|
);
|
105
107
|
}
|
106
108
|
|
107
109
|
return buttons;
|
108
110
|
};
|
111
|
+
|
109
112
|
|
110
113
|
return (
|
111
114
|
<div className="pb_pagination">
|
@@ -119,7 +122,7 @@ const Pagination = ({
|
|
119
122
|
{renderPageButtons()}
|
120
123
|
<button
|
121
124
|
className="pagination-right"
|
122
|
-
disabled={currentPage ===
|
125
|
+
disabled={currentPage === total}
|
123
126
|
onClick={() => handlePageChange(currentPage + 1)}
|
124
127
|
>
|
125
128
|
<Icon icon="chevron-right" />
|
@@ -5,14 +5,14 @@ import Pagination from '../_pagination'
|
|
5
5
|
const PaginationDefault = (props) => {
|
6
6
|
|
7
7
|
return (
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
8
|
+
<>
|
9
|
+
<Pagination
|
10
|
+
current={1}
|
11
|
+
range={5}
|
12
|
+
total={10}
|
13
|
+
{...props}
|
14
|
+
/>
|
15
|
+
</>
|
16
16
|
)
|
17
17
|
}
|
18
18
|
|
@@ -0,0 +1,62 @@
|
|
1
|
+
import React, { useState } from "react";
|
2
|
+
import { Table, Pagination } from 'playbook-ui'
|
3
|
+
|
4
|
+
|
5
|
+
import { data } from "./data";
|
6
|
+
|
7
|
+
const PaginationPageChange = (props) => {
|
8
|
+
|
9
|
+
const [activePage, setActivePage] = useState(1);
|
10
|
+
const rowsPerPage = 3;
|
11
|
+
const totalPages = Math.ceil(data.length / rowsPerPage);
|
12
|
+
|
13
|
+
const onPageChange = (pageNumber) => {
|
14
|
+
setActivePage(pageNumber);
|
15
|
+
};
|
16
|
+
|
17
|
+
const currentData = data.slice(
|
18
|
+
(activePage - 1) * rowsPerPage,
|
19
|
+
activePage * rowsPerPage
|
20
|
+
);
|
21
|
+
|
22
|
+
|
23
|
+
return (
|
24
|
+
<div className="App">
|
25
|
+
<Table
|
26
|
+
marginBottom="xs"
|
27
|
+
responsive="none"
|
28
|
+
size="sm"
|
29
|
+
{...props}
|
30
|
+
>
|
31
|
+
<Table.Head>
|
32
|
+
<Table.Row>
|
33
|
+
<Table.Header>{"Column 1"}</Table.Header>
|
34
|
+
<Table.Header>{"Column 2"}</Table.Header>
|
35
|
+
<Table.Header>{"Column 3"}</Table.Header>
|
36
|
+
<Table.Header>{"Column 4"}</Table.Header>
|
37
|
+
<Table.Header>{"Column 5"}</Table.Header>
|
38
|
+
</Table.Row>
|
39
|
+
</Table.Head>
|
40
|
+
<Table.Body>
|
41
|
+
{currentData.map((row, index) => (
|
42
|
+
<Table.Row key={index}>
|
43
|
+
{row.map((cell, cellIndex) => (
|
44
|
+
<Table.Cell key={cellIndex}>{cell}</Table.Cell>
|
45
|
+
))}
|
46
|
+
</Table.Row>
|
47
|
+
))}
|
48
|
+
</Table.Body>
|
49
|
+
</Table>
|
50
|
+
|
51
|
+
<Pagination
|
52
|
+
current={1}
|
53
|
+
onChange={onPageChange}
|
54
|
+
range={5}
|
55
|
+
total={totalPages}
|
56
|
+
{...props}
|
57
|
+
/>
|
58
|
+
</div>
|
59
|
+
)
|
60
|
+
}
|
61
|
+
|
62
|
+
export default PaginationPageChange
|
@@ -0,0 +1 @@
|
|
1
|
+
You can use the `onPageChange` prop to control the data of your table. This prop is callback function that will allow you control the state.
|
@@ -0,0 +1,23 @@
|
|
1
|
+
export const data = [
|
2
|
+
["Value 1", "Value 2", "Value 3", "Value 4", "Value 5"],
|
3
|
+
["Value 6", "Value 7", "Value 8", "Value 9", "Value 10"],
|
4
|
+
["Value 11", "Value 12", "Value 13", "Value 14", "Value 15"],
|
5
|
+
["Value 16", "Value 17", "Value 18", "Value 19", "Value 20"],
|
6
|
+
["Value 21", "Value 22", "Value 23", "Value 24", "Value 25"],
|
7
|
+
["Value 26", "Value 27", "Value 28", "Value 29", "Value 30"],
|
8
|
+
["Value 31", "Value 32", "Value 33", "Value 34", "Value 35"],
|
9
|
+
["Value 36", "Value 37", "Value 38", "Value 39", "Value 40"],
|
10
|
+
["Value 41", "Value 42", "Value 43", "Value 44", "Value 45"],
|
11
|
+
["Value 46", "Value 47", "Value 48", "Value 49", "Value 50"],
|
12
|
+
["Value 51", "Value 52", "Value 53", "Value 54", "Value 55"],
|
13
|
+
["Value 56", "Value 57", "Value 58", "Value 59", "Value 60"],
|
14
|
+
["Value 61", "Value 62", "Value 63", "Value 64", "Value 65"],
|
15
|
+
["Value 66", "Value 67", "Value 68", "Value 69", "Value 70"],
|
16
|
+
["Value 71", "Value 72", "Value 73", "Value 74", "Value 75"],
|
17
|
+
["Value 76", "Value 77", "Value 78", "Value 79", "Value 80"],
|
18
|
+
["Value 81", "Value 82", "Value 83", "Value 84", "Value 85"],
|
19
|
+
["Value 86", "Value 87", "Value 88", "Value 89", "Value 90"],
|
20
|
+
["Value 91", "Value 92", "Value 93", "Value 94", "Value 95"],
|
21
|
+
["Value 96", "Value 97", "Value 98", "Value 99", "Value 100"],
|
22
|
+
];
|
23
|
+
|