-
-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathPagination.js
More file actions
44 lines (40 loc) · 1.17 KB
/
Pagination.js
File metadata and controls
44 lines (40 loc) · 1.17 KB
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
import React, { useState, useEffect } from 'react';
import { FiChevronsLeft, FiChevronsRight } from 'react-icons/fi';
import ButtonGroup from '@mui/material/ButtonGroup';
import { ToolBarButton } from './Buttons';
export default function Pagination({ total, pagesize, onChange }) {
const [current, setCurrent] = useState(1);
const [pageCount, setPageCount] = useState(0);
useEffect(() => {
setPageCount(Math.ceil(total / pagesize) || 1);
setCurrent(1);
}, [total]);
const onButtonClicked = (index) => {
setCurrent(index);
invokeChange(index);
};
const invokeChange = (index) => {
if (onChange) {
onChange(index);
}
};
return (
<div className='flex justify-center items-center'>
<ButtonGroup variant='text' aria-label='text button group'>
<ToolBarButton
handleOnClick={() => onButtonClicked(current - 1)}
disabled={current === 1}>
<FiChevronsLeft />
</ToolBarButton>
<div className='text-white'>
Page: {current} / {pageCount}
</div>
<ToolBarButton
handleOnClick={() => onButtonClicked(current + 1)}
disabled={current === pageCount}>
<FiChevronsRight />
</ToolBarButton>
</ButtonGroup>
</div>
);
}