forked from CougarCS/CougarCS-AdminPortal
-
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.
Refactor pagination control to component
- Loading branch information
Showing
2 changed files
with
58 additions
and
22 deletions.
There are no files selected for viewing
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,51 @@ | ||
import React from "react"; | ||
import { memberType } from "../types/types"; | ||
import { AiOutlineArrowLeft, AiOutlineArrowRight } from "react-icons/ai"; | ||
|
||
type paginationControlProps = { | ||
dataPage: number; | ||
setDataPage: React.Dispatch<React.SetStateAction<number>>; | ||
presentableData: memberType[][]; | ||
}; | ||
|
||
export const PaginationControl = ({ | ||
dataPage, | ||
setDataPage, | ||
presentableData, | ||
}: paginationControlProps) => { | ||
function decrementDataPage() { | ||
if (dataPage === 0) return; | ||
|
||
setDataPage((prev) => prev - 1); | ||
} | ||
|
||
function incrementDataPage() { | ||
if (dataPage === presentableData.length - 1) return; | ||
|
||
setDataPage((prev) => prev + 1); | ||
} | ||
|
||
return ( | ||
<div className="mt-3 flex items-center justify-end"> | ||
<button | ||
className="mr-3 rounded-md p-2 text-red-600 hover:bg-gray-500 hover:bg-opacity-30 disabled:text-gray-400 disabled:text-opacity-40 disabled:hover:bg-transparent" | ||
onClick={decrementDataPage} | ||
disabled={dataPage === 0 ? true : false} | ||
> | ||
<AiOutlineArrowLeft className="h-6 w-6" /> | ||
</button> | ||
|
||
<p className="flex w-fit justify-center font-medium"> | ||
Page {dataPage + 1} of {presentableData.length} | ||
</p> | ||
|
||
<button | ||
className="ml-3 rounded-md p-2 text-red-600 hover:bg-gray-500 hover:bg-opacity-30 disabled:text-gray-400 disabled:text-opacity-40 disabled:hover:bg-transparent" | ||
onClick={incrementDataPage} | ||
disabled={dataPage === presentableData.length - 1 ? true : false} | ||
> | ||
<AiOutlineArrowRight className="h-6 w-6" /> | ||
</button> | ||
</div> | ||
); | ||
}; |
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