From e698ea73428f97c7899b2703151fdd2ac4b5827b Mon Sep 17 00:00:00 2001 From: Joe Date: Mon, 17 Jun 2019 20:31:46 +1000 Subject: [PATCH] v1.0 --- README.md | 11 +++++------ src/PaginationComponent.tsx | 24 +++++++++++++++++++----- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 6b2a01b..e084ae3 100644 --- a/README.md +++ b/README.md @@ -15,9 +15,8 @@ import PaginationComponent from "@josephzhou/ms-pagination"; **Parameters** -| Parameters | Type | Description | | | -|---------------|----------------------------------------------------------|--------------------------------------------------------------------|---|---| -| count | number | Total pages | | | -| initialPage | number | The page indicated when component initialized (default value is 1) | | | -| onPageChanged | (page: number, perPage: number, orderBy: string) => void | This function will be called when page number changed | | | - +| Parameters | Type | Description | +|---------------|----------------------------------------------------------|--------------------------------------------------------------------| +| count | number | Total pages | +| initialPage | number | The page indicated when component initialized (default value is 1) | +| onPageChanged | (page: number, perPage: number, orderBy: string) => void | This function will be called when page number changed | \ No newline at end of file diff --git a/src/PaginationComponent.tsx b/src/PaginationComponent.tsx index 65ef63d..310fb79 100644 --- a/src/PaginationComponent.tsx +++ b/src/PaginationComponent.tsx @@ -11,7 +11,9 @@ type PaginationComponentState = { type PaginationComponentProps = { onPageChanged: (page: number, perPage: number, orderBy: string) => void, count: number, - initialPage: number + initialPage: number, + nextIcon?: React.ReactDOM, + previousIcon?: React.ReactDOM }; /** @@ -38,7 +40,13 @@ const PageNumbers = ({ pageNumbersArray, onPageChanged, page, count }: { paginationArray = pageNumbersArray; } else if (count >= 5) { if (page <= 5) { - let firstFivePageNumbers: Array = [...Array(page + 2).keys()].map(item => ++item); + let ceilPage = count; + + if(page + 2 <= 5) { + ceilPage = page + 2; + } + + let firstFivePageNumbers: Array = [...Array(ceilPage).keys()].map(item => ++item); firstFivePageNumbers.push('...'); paginationArray = firstFivePageNumbers; } else { @@ -62,6 +70,9 @@ const PageNumbers = ({ pageNumbersArray, onPageChanged, page, count }: { ) } +/** + * Before navigation icon + */ const NavigateBeforeRoundedIcon = () => { return ( @@ -71,6 +82,9 @@ const NavigateBeforeRoundedIcon = () => { ) } +/** + * Next navigation icon + */ const NavigateNextRoundedIcon = () => { return ( @@ -151,7 +165,7 @@ class PaginationComponent extends React.Component = [...Array(count).keys()].map(item => ++item); @@ -160,13 +174,13 @@ class PaginationComponent extends React.Component
  • - + {previousIcon ? previousIcon : }
  • {}
  • - + {nextIcon ? nextIcon : }