-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #242 from dabapps/pagination
Pagination
- Loading branch information
Showing
15 changed files
with
878 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
|
||
.pagination { | ||
|
||
.button { | ||
color: @pagination-button-color; | ||
background-color: @pagination-button-background; | ||
} | ||
|
||
.selected { | ||
color: @pagination-selected-color; | ||
background-color: @pagination-selected-background; | ||
} | ||
|
||
.next, | ||
.prev { | ||
color: @pagination-indicator-color; | ||
background-color: @pagination-indicator-background; | ||
} | ||
|
||
.dots { | ||
display: inline-block; | ||
height: auto; | ||
padding: @padding-small @padding-base; | ||
text-decoration: none; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import * as classNames from 'classnames'; | ||
import * as React from 'react'; | ||
import { PureComponent } from 'react'; | ||
import { ComponentProps } from '../../types'; | ||
|
||
export interface PaginationDisplayProps extends ComponentProps { | ||
/** | ||
* className | ||
*/ | ||
className?: string; | ||
/** | ||
* items count per page | ||
*/ | ||
pageSize: number; | ||
/** | ||
* current page number (1 indexed) | ||
*/ | ||
currentPageNumber: number; | ||
/** | ||
* total number of items to display | ||
*/ | ||
itemCount: number; | ||
} | ||
|
||
export class PaginationDisplay extends PureComponent< | ||
PaginationDisplayProps, | ||
{} | ||
> { | ||
public render() { | ||
const { | ||
className, | ||
itemCount, | ||
pageSize, | ||
currentPageNumber, | ||
...remainingProps | ||
} = this.props; | ||
|
||
return ( | ||
<p | ||
{...remainingProps} | ||
className={classNames('pagination-display', className)} | ||
> | ||
Showing {this.showingLowerCount()}-{this.showingUpperCount()} of{' '} | ||
{itemCount} | ||
</p> | ||
); | ||
} | ||
|
||
private showingLowerCount = () => { | ||
const { currentPageNumber, pageSize } = this.props; | ||
return (currentPageNumber - 1) * pageSize || 1; | ||
}; | ||
|
||
private showingUpperCount = () => { | ||
const { pageSize, currentPageNumber, itemCount } = this.props; | ||
return pageSize * currentPageNumber > itemCount | ||
? itemCount | ||
: pageSize * currentPageNumber; | ||
}; | ||
} | ||
|
||
export default PaginationDisplay; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#### Pagination example: | ||
|
||
```js | ||
class PaginationExample extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
|
||
this.state = { | ||
page: 1, | ||
}; | ||
|
||
this.changePage = this.changePage.bind(this); | ||
} | ||
|
||
changePage(value) { | ||
this.setState({ page: value }); | ||
} | ||
|
||
render() { | ||
const ITEM_COUNT = 22; | ||
const PAGE_SIZE = 3; | ||
const { page } = this.state; | ||
|
||
return ( | ||
<div> | ||
<Row> | ||
<Column xs={4}> | ||
<PaginationDisplay | ||
pageSize={PAGE_SIZE} | ||
currentPageNumber={page} | ||
itemCount={ITEM_COUNT} | ||
/> | ||
</Column> | ||
<Column xs={8}> | ||
<Pagination | ||
className="float-right margin-top-base" | ||
pageSize={PAGE_SIZE} | ||
changePage={this.changePage} | ||
currentPageNumber={page} | ||
itemCount={ITEM_COUNT} | ||
/> | ||
</Column> | ||
</Row> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
<PaginationExample />; | ||
``` | ||
|
||
#### Less variables | ||
|
||
```less | ||
@pagination-button-color: @grey-dark; | ||
@pagination-button-background: @grey-lighter; | ||
@pagination-selected-color: @white; | ||
@pagination-selected-background: @primary; | ||
@pagination-indicator-color: @grey-dark; | ||
@pagination-indicator-background: @grey-lighter; | ||
``` |
Oops, something went wrong.