Skip to content

Commit

Permalink
v1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ZYMoridae committed Jun 17, 2019
1 parent 9548029 commit e698ea7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
24 changes: 19 additions & 5 deletions src/PaginationComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

/**
Expand All @@ -38,7 +40,13 @@ const PageNumbers = ({ pageNumbersArray, onPageChanged, page, count }: {
paginationArray = pageNumbersArray;
} else if (count >= 5) {
if (page <= 5) {
let firstFivePageNumbers: Array<any> = [...Array(page + 2).keys()].map(item => ++item);
let ceilPage = count;

if(page + 2 <= 5) {
ceilPage = page + 2;
}

let firstFivePageNumbers: Array<any> = [...Array(ceilPage).keys()].map(item => ++item);
firstFivePageNumbers.push('...');
paginationArray = firstFivePageNumbers;
} else {
Expand All @@ -62,6 +70,9 @@ const PageNumbers = ({ pageNumbersArray, onPageChanged, page, count }: {
)
}

/**
* Before navigation icon
*/
const NavigateBeforeRoundedIcon = () => {
return (
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
Expand All @@ -71,6 +82,9 @@ const NavigateBeforeRoundedIcon = () => {
)
}

/**
* Next navigation icon
*/
const NavigateNextRoundedIcon = () => {
return (
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
Expand Down Expand Up @@ -151,7 +165,7 @@ class PaginationComponent extends React.Component<PaginationComponentProps, Pagi
}

render() {
const { count } = this.props;
const { count, nextIcon, previousIcon } = this.props;

let pageNumbersArray: Array<number> = [...Array(count).keys()].map(item => ++item);

Expand All @@ -160,13 +174,13 @@ class PaginationComponent extends React.Component<PaginationComponentProps, Pagi
<ul className='pagination-container'>

<li className='pagination-block previousBtn' onClick={this.previousBtnClick}>
<NavigateBeforeRoundedIcon />
{previousIcon ? previousIcon : <NavigateBeforeRoundedIcon />}
</li>

{<PageNumbers pageNumbersArray={pageNumbersArray} onPageChanged={this.pageChanged} page={this.state.page} count={count} />}

<li className='pagination-block nextBtn' onClick={this.nextBtnClick}>
<NavigateNextRoundedIcon />
{nextIcon ? nextIcon : <NavigateNextRoundedIcon />}
</li>

<li className='pagination-info'>
Expand Down

0 comments on commit e698ea7

Please sign in to comment.