1
|
|
|
import React from 'react'; |
2
|
|
|
import PropTypes from 'prop-types'; |
3
|
|
|
import classNames from 'classnames'; |
4
|
|
|
import { Pagination, PaginationItem, PaginationLink } from 'reactstrap'; |
5
|
|
|
import { isPageDisabled, keyForPage, progressivePagination } from '../utils/helpers/pagination'; |
6
|
|
|
import './SimplePaginator.scss'; |
7
|
|
|
|
8
|
4 |
|
const propTypes = { |
9
|
|
|
pagesCount: PropTypes.number.isRequired, |
10
|
|
|
currentPage: PropTypes.number.isRequired, |
11
|
|
|
setCurrentPage: PropTypes.func.isRequired, |
12
|
|
|
centered: PropTypes.bool, |
13
|
|
|
}; |
14
|
|
|
|
15
|
4 |
|
const SimplePaginator = ({ pagesCount, currentPage, setCurrentPage, centered = true }) => { |
16
|
7 |
|
if (pagesCount < 2) { |
17
|
4 |
|
return null; |
18
|
|
|
} |
19
|
|
|
|
20
|
28 |
|
const onClick = (page) => () => setCurrentPage(page); |
21
|
|
|
|
22
|
3 |
|
return ( |
23
|
|
|
<Pagination listClassName={classNames('flex-wrap mb-0 simple-paginator', { 'justify-content-center': centered })}> |
24
|
|
|
<PaginationItem disabled={currentPage <= 1}> |
25
|
|
|
<PaginationLink previous tag="span" onClick={onClick(currentPage - 1)} /> |
26
|
|
|
</PaginationItem> |
27
|
|
|
{progressivePagination(currentPage, pagesCount).map((pageNumber, index) => ( |
28
|
22 |
|
<PaginationItem |
29
|
|
|
key={keyForPage(pageNumber, index)} |
30
|
|
|
disabled={isPageDisabled(pageNumber)} |
31
|
|
|
active={currentPage === pageNumber} |
32
|
|
|
> |
33
|
|
|
<PaginationLink tag="span" onClick={onClick(pageNumber)}>{pageNumber}</PaginationLink> |
34
|
|
|
</PaginationItem> |
35
|
|
|
))} |
36
|
|
|
<PaginationItem disabled={currentPage >= pagesCount}> |
37
|
|
|
<PaginationLink next tag="span" onClick={onClick(currentPage + 1)} /> |
38
|
|
|
</PaginationItem> |
39
|
|
|
</Pagination> |
40
|
|
|
); |
41
|
|
|
}; |
42
|
|
|
|
43
|
4 |
|
SimplePaginator.propTypes = propTypes; |
44
|
|
|
|
45
|
|
|
export default SimplePaginator; |
46
|
|
|
|