2019-09-21 19:29:58 +03:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2020-04-04 00:00:57 +03:00
|
|
|
import classNames from 'classnames';
|
2019-09-21 19:29:58 +03:00
|
|
|
import { Pagination, PaginationItem, PaginationLink } from 'reactstrap';
|
2020-03-28 19:43:09 +03:00
|
|
|
import { isPageDisabled, keyForPage, progressivePagination } from '../utils/helpers/pagination';
|
2019-09-22 12:14:08 +03:00
|
|
|
import './SimplePaginator.scss';
|
2019-09-21 19:29:58 +03:00
|
|
|
|
|
|
|
const propTypes = {
|
|
|
|
pagesCount: PropTypes.number.isRequired,
|
|
|
|
currentPage: PropTypes.number.isRequired,
|
|
|
|
setCurrentPage: PropTypes.func.isRequired,
|
2020-04-04 00:00:57 +03:00
|
|
|
centered: PropTypes.bool,
|
2019-09-21 19:29:58 +03:00
|
|
|
};
|
|
|
|
|
2020-04-04 00:00:57 +03:00
|
|
|
const SimplePaginator = ({ pagesCount, currentPage, setCurrentPage, centered = true }) => {
|
2019-09-22 11:41:31 +03:00
|
|
|
if (pagesCount < 2) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
const onClick = (page) => () => setCurrentPage(page);
|
|
|
|
|
|
|
|
return (
|
2020-04-04 00:00:57 +03:00
|
|
|
<Pagination listClassName={classNames('flex-wrap mb-0 simple-paginator', { 'justify-content-center': centered })}>
|
2019-09-22 11:41:31 +03:00
|
|
|
<PaginationItem disabled={currentPage <= 1}>
|
|
|
|
<PaginationLink previous tag="span" onClick={onClick(currentPage - 1)} />
|
2019-09-21 19:29:58 +03:00
|
|
|
</PaginationItem>
|
2020-03-28 19:43:09 +03:00
|
|
|
{progressivePagination(currentPage, pagesCount).map((pageNumber, index) => (
|
2019-09-22 11:41:31 +03:00
|
|
|
<PaginationItem
|
2020-03-28 19:43:09 +03:00
|
|
|
key={keyForPage(pageNumber, index)}
|
|
|
|
disabled={isPageDisabled(pageNumber)}
|
|
|
|
active={currentPage === pageNumber}
|
2019-09-22 11:41:31 +03:00
|
|
|
>
|
2020-03-28 19:43:09 +03:00
|
|
|
<PaginationLink tag="span" onClick={onClick(pageNumber)}>{pageNumber}</PaginationLink>
|
2019-09-22 11:41:31 +03:00
|
|
|
</PaginationItem>
|
|
|
|
))}
|
|
|
|
<PaginationItem disabled={currentPage >= pagesCount}>
|
|
|
|
<PaginationLink next tag="span" onClick={onClick(currentPage + 1)} />
|
|
|
|
</PaginationItem>
|
|
|
|
</Pagination>
|
|
|
|
);
|
|
|
|
};
|
2019-09-21 19:29:58 +03:00
|
|
|
|
|
|
|
SimplePaginator.propTypes = propTypes;
|
|
|
|
|
|
|
|
export default SimplePaginator;
|