Skip to content

Commit b6fc536

Browse files
Merge pull request #7263 from kishore08-07/pagination
Added responsive Previous/Next pagination to Resources page
2 parents fd05f30 + abcba37 commit b6fc536

File tree

2 files changed

+43
-32
lines changed

2 files changed

+43
-32
lines changed

src/sections/Resources/Resources-grid/paginate.js

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,30 @@
11
import React from "react";
22
import { ResourcePageWrapper } from "./resourceGrid.style";
3+
import Button from "../../../reusecore/Button";
34

45
const Pagination = ({ postsPerPage, totalPosts, paginate, currentPage }) => {
5-
const pageNumbers = [];
6-
7-
for (let i = 1; i <= Math.ceil(totalPosts / postsPerPage); i++) {
8-
pageNumbers.push(i);
9-
}
6+
const totalPages = Math.ceil(totalPosts / postsPerPage);
107

118
return (
129
<ResourcePageWrapper>
1310
<div className="btn-container">
14-
{pageNumbers.map(number => (
15-
<button key={number} onClick={() => paginate(number)} className={(number === currentPage) ? "btn active-btn" : "btn page-btn"}>
16-
{number}
17-
</button>
18-
))}
11+
<Button
12+
$secondary
13+
onClick={() => paginate(currentPage - 1)}
14+
className="nav-btn"
15+
disabled={currentPage === 1}
16+
>
17+
&larr; Previous
18+
</Button>
19+
20+
<Button
21+
$primary
22+
onClick={() => paginate(currentPage + 1)}
23+
className="nav-btn"
24+
disabled={currentPage === totalPages}
25+
>
26+
Next &rarr;
27+
</Button>
1928
</div>
2029
</ResourcePageWrapper>
2130
);

src/sections/Resources/Resources-grid/resourceGrid.style.js

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,31 +36,33 @@ export const ResourcePageWrapper = styled.div`
3636
.btn-container {
3737
display: flex;
3838
justify-content: center;
39-
flex-wrap: wrap;
40-
margin: 0 auto 2rem;
41-
}
42-
.btn {
43-
width: 2rem;
44-
height: 2rem;
45-
border-radius: 5px;
46-
cursor: pointer;
47-
margin: 0.5rem;
48-
transition: all 0.3s linear;
49-
:hover {
50-
box-shadow: 0px 1px 5px 1px rgba(0, 179, 159, 0.5);
39+
align-items: center;
40+
gap: 1rem;
41+
margin: 3rem auto 4rem;
42+
43+
@media screen and (max-width: 768px) {
44+
flex-direction: column;
45+
gap: 1rem;
46+
margin: 2rem auto 3rem;
5147
}
5248
}
53-
.page-btn {
54-
background: ${props => props.theme.grey212121ToWhite};
55-
border: solid 2px;
56-
border-color: ${props => props.theme.secondaryColor};
57-
color: ${props => props.theme.whiteEightToBlack};
49+
50+
.nav-btn {
51+
min-width: 130px;
52+
padding: 0.75rem 1.5rem;
53+
font-size: 1rem;
54+
transition: all 0.3s ease;
55+
56+
&:disabled {
57+
opacity: 0.5;
58+
cursor: not-allowed;
59+
}
60+
61+
@media screen and (max-width: 768px) {
62+
min-width: 160px;
63+
padding: 0.75rem 1.75rem;
64+
}
5865
}
59-
.active-btn {
60-
background: ${props => props.theme.secondaryColor};
61-
border-color: transparent;
62-
color: #fff;
63-
}
6466
6567
@media only screen and (max-width: 575px) {
6668
.resource-grid-wrapper{

0 commit comments

Comments
 (0)