Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | 34x 153x 153x 153x 153x 153x 3290x 153x 153x 153x 153x 153x 34x | import React from "react";
import GivePagination from "@shared/Table/GivePagination";
import { PaginationItem as PaginationItemType } from "@shared/Table/GiveTable.types";
import { styled } from "@theme/v2/Provider";
import { Box } from "@mui/material";
type Props = {
numberOfPages: number;
page: number;
setPageDispatcher: React.Dispatch<React.SetStateAction<number>>;
};
const TablePagination = ({ numberOfPages, page, setPageDispatcher }: Props) => {
const onNextPage = () => {
page !== numberOfPages && setPageDispatcher((p: number) => p + 1);
};
const onPreviousPage = () => {
page !== 1 && setPageDispatcher((p: number) => p - 1);
};
const isStart = page < 5;
const isEnd = page > numberOfPages - 4;
const fewPages = Array.from(
{ length: numberOfPages },
(_, index) => index + 1,
);
const startPages = [1, 2, 3, 4, 5, "space", numberOfPages];
const endPages = [
1,
"space",
numberOfPages - 4,
numberOfPages - 3,
numberOfPages - 2,
numberOfPages - 1,
numberOfPages,
];
const middlePages = [
1,
"space",
page - 1,
page,
page + 1,
"space",
numberOfPages,
];
const pages =
numberOfPages < 8
? fewPages
: isStart
? startPages
: isEnd
? endPages
: middlePages;
return (
<Container>
<GivePagination
currentPage={page}
onClick={setPageDispatcher}
pages={pages as PaginationItemType[]}
previousDisabled={page === 1}
nextDisabled={page === numberOfPages}
onClickNext={onNextPage}
onClickPrevious={onPreviousPage}
/>
</Container>
);
};
export default TablePagination;
const Container = styled(Box)({
padding: "20px 0",
});
|