-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
6 changed files
with
219 additions
and
8 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
.paginationContainer { | ||
display: flex; | ||
justify-content: center; | ||
} | ||
|
||
.pagination { | ||
display: flex; | ||
flex-wrap: wrap; | ||
justify-content: center; | ||
margin-top: var(--spacer); | ||
margin-bottom: var(--spacer); | ||
padding-left: 0; | ||
font-size: var(--font-size-small); | ||
} | ||
|
||
.number { | ||
font-weight: var(--font-weight-bold); | ||
margin-left: -1px; | ||
margin-top: -1px; | ||
display: block; | ||
cursor: pointer; | ||
min-width: 3rem; | ||
height: 100%; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
color: var(--color-secondary); | ||
} | ||
|
||
li:first-child .number, | ||
:global(li.selected):nth-child(2) .number { | ||
border-top-left-radius: var(--border-radius); | ||
border-bottom-left-radius: var(--border-radius); | ||
} | ||
|
||
li:last-child .number { | ||
border-top-right-radius: var(--border-radius); | ||
border-bottom-right-radius: var(--border-radius); | ||
} | ||
|
||
.number, | ||
.number:hover, | ||
.number:focus, | ||
.number:active { | ||
transform: none; | ||
outline: 0; | ||
} | ||
|
||
.number:hover { | ||
color: var(--brand-pink); | ||
} | ||
|
||
.current, | ||
.prev, | ||
.next, | ||
.break { | ||
composes: number; | ||
} | ||
|
||
.current { | ||
cursor: default; | ||
pointer-events: none; | ||
} | ||
|
||
.current > a, | ||
.current:hover, | ||
.current:focus, | ||
.current:active { | ||
color: var(--brand-pink) !important; | ||
} | ||
|
||
.next { | ||
text-align: right; | ||
} | ||
|
||
.prevNextDisabled { | ||
opacity: 0; | ||
} | ||
|
||
.arrow { | ||
width: 1rem; | ||
height: 1rem; | ||
fill: currentColor; | ||
} | ||
|
||
.arrow.previous { | ||
transform: rotate(180deg); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import React, { useState } from 'react'; | ||
import styles from './pagination.module.css'; | ||
|
||
interface PaginationProps { | ||
totalPages: number; | ||
currentPage: number; | ||
onPageChange: (page: number) => void; | ||
} | ||
|
||
const Pagination = ({ totalPages, currentPage, onPageChange }: PaginationProps) => { | ||
// Define the number of pages to show at the beginning and end | ||
const pagesToShow = 3; | ||
|
||
// Calculate the start and end range of pages to display | ||
let startPage = Math.max(1, currentPage - pagesToShow); | ||
let endPage = Math.min(totalPages, currentPage + pagesToShow); | ||
|
||
// If we have less than the required number of pages to show at the beginning, | ||
// adjust the endPage to display enough pages. | ||
if (currentPage <= pagesToShow) { | ||
endPage = Math.min(currentPage + pagesToShow + (pagesToShow - currentPage), totalPages); | ||
} | ||
|
||
// If we have less than the required number of pages to show at the end, | ||
// adjust the startPage to display enough pages. | ||
if (currentPage >= totalPages - pagesToShow) { | ||
startPage = Math.max(currentPage - pagesToShow - (pagesToShow - (totalPages - currentPage - 1)), 1); | ||
} | ||
|
||
// Generate the pageNumbers array based on the calculated startPage and endPage | ||
const pageNumbers = []; | ||
if (startPage > 1) { | ||
pageNumbers.push(1); | ||
if (startPage > 2) { | ||
pageNumbers.push('...'); | ||
} | ||
} | ||
for (let i = startPage; i <= endPage; i++) { | ||
pageNumbers.push(i); | ||
} | ||
if (endPage < totalPages) { | ||
if (endPage < totalPages - 1) { | ||
pageNumbers.push('...'); | ||
} | ||
pageNumbers.push(totalPages); | ||
} | ||
|
||
const handlePageChange = (page: number) => { | ||
if (page < 1 || page > totalPages) return; | ||
onPageChange(page); | ||
}; | ||
|
||
return ( | ||
<div className={styles.paginationContainer}> | ||
<ul className={styles.pagination}> | ||
<li | ||
className={`${currentPage === 1 ? styles.prevNextDisabled : ''}`} | ||
> | ||
<a | ||
className={`${styles.prev}`} | ||
onClick={() => handlePageChange(currentPage - 1)} | ||
> | ||
Previous | ||
</a> | ||
</li> | ||
|
||
{pageNumbers.map((page) => ( | ||
<li | ||
key={page} | ||
className={`${currentPage === page ? styles.current : ''}`} | ||
> | ||
<a | ||
className={`${styles.number}`} | ||
onClick={() => { if (typeof page === 'number') handlePageChange(page) }} | ||
> | ||
{page} | ||
</a> | ||
</li> | ||
))} | ||
|
||
<li | ||
className={`${ | ||
currentPage === totalPages ? styles.prevNextDisabled : '' | ||
}${styles.next}`} | ||
> | ||
<a | ||
className={`${styles.next}`} | ||
onClick={() => handlePageChange(currentPage + 1)} | ||
> | ||
Next | ||
</a> | ||
</li> | ||
</ul> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Pagination; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters