From a44250537215d8824495b6b089db940ec45b3955 Mon Sep 17 00:00:00 2001 From: renrizzolo Date: Mon, 24 Oct 2022 09:15:05 +1100 Subject: [PATCH] refactor: pagination --- src/components/Pagination/index.d.ts | 8 + src/components/Pagination/index.jsx | 239 +++++++++++------------ src/components/Pagination/index.spec.jsx | 111 +++++------ src/components/Pagination/styles.css | 58 +++--- www/containers/props.json | 22 +++ 5 files changed, 232 insertions(+), 206 deletions(-) diff --git a/src/components/Pagination/index.d.ts b/src/components/Pagination/index.d.ts index dfc7328ff..ae1076c90 100644 --- a/src/components/Pagination/index.d.ts +++ b/src/components/Pagination/index.d.ts @@ -10,6 +10,14 @@ export interface PaginationProps { * The max page count */ pageCount: number; + /** + * The number of pages to show on either side of the current page + */ + siblingCount?: number; + /** + * separator for truncated pages + */ + separator?: React.ReactNode; /** * A callback function for when clicking on previous, next and pagination items */ diff --git a/src/components/Pagination/index.jsx b/src/components/Pagination/index.jsx index 58bbe5475..1637d564e 100644 --- a/src/components/Pagination/index.jsx +++ b/src/components/Pagination/index.jsx @@ -1,136 +1,115 @@ import React from 'react'; +import _ from 'lodash'; import PropTypes from 'prop-types'; import classnames from 'classnames'; import Button from '../Button'; import './styles.css'; -const Pagination = ({ className, activePage, pageCount, onSelect, prev, next }) => ( -
- {activePage !== 1 && prev && ( - - )} - - - - {activePage > 3 && pageCount !== 4 && pageCount !== 5 && ( -
- ... -
- )} - - {activePage === 5 && pageCount === 5 && ( - - )} - - {((activePage === pageCount && pageCount > 3) || (activePage === 4 && pageCount === 5)) && ( - - )} - - {activePage > 2 && ( - - )} - - {activePage !== 1 && activePage !== pageCount && ( - - )} - - {activePage < pageCount - 1 && ( - - )} - - {((activePage === 1 && pageCount > 3) || (activePage === 2 && pageCount === 5)) && ( - - )} - - {activePage === 1 && pageCount === 5 && ( - - )} - - {activePage < pageCount - 2 && pageCount !== 4 && pageCount !== 5 && ( -
- ... -
- )} - - {pageCount !== 1 && ( - - )} - - {activePage !== pageCount && next && ( - - )} -
-); + + {next && ( +