forked from react-bootstrap/react-bootstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
12d6ddb
commit 5734ec3
Showing
11 changed files
with
402 additions
and
14 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -39,6 +39,7 @@ | |
"PageHeader", | ||
"PageItem", | ||
"Pager", | ||
"Pagination", | ||
"Panel", | ||
"PanelGroup", | ||
"Popover", | ||
|
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,30 @@ | ||
const PaginationAdvanced = React.createClass({ | ||
getInitialState() { | ||
return { | ||
activePage: 1 | ||
}; | ||
}, | ||
|
||
handleSelect(event, selectedEvent) { | ||
this.setState({ | ||
activePage: selectedEvent.eventKey | ||
}); | ||
}, | ||
|
||
render() { | ||
return ( | ||
<Pagination | ||
prev={true} | ||
next={true} | ||
first={true} | ||
last={true} | ||
ellipsis={true} | ||
items={20} | ||
maxButtons={5} | ||
activePage={this.state.activePage} | ||
onSelect={this.handleSelect} /> | ||
); | ||
} | ||
}); | ||
|
||
React.render(<PaginationAdvanced />, mountNode); |
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,41 @@ | ||
const PaginationBasic = React.createClass({ | ||
getInitialState() { | ||
return { | ||
activePage: 1 | ||
}; | ||
}, | ||
|
||
handleSelect(event, selectedEvent){ | ||
this.setState({ | ||
activePage: selectedEvent.eventKey | ||
}); | ||
}, | ||
|
||
render() { | ||
return ( | ||
<div> | ||
<Pagination | ||
bsSize='large' | ||
items={10} | ||
activePage={this.state.activePage} | ||
onSelect={this.handleSelect} /> | ||
<br /> | ||
|
||
<Pagination | ||
bsSize='medium' | ||
items={10} | ||
activePage={this.state.activePage} | ||
onSelect={this.handleSelect} /> | ||
<br /> | ||
|
||
<Pagination | ||
bsSize='small' | ||
items={10} | ||
activePage={this.state.activePage} | ||
onSelect={this.handleSelect} /> | ||
</div> | ||
); | ||
} | ||
}); | ||
|
||
React.render(<PaginationBasic />, mountNode); |
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
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,167 @@ | ||
import React from 'react'; | ||
import classNames from 'classnames'; | ||
import BootstrapMixin from './BootstrapMixin'; | ||
import PaginationButton from './PaginationButton'; | ||
|
||
const Pagination = React.createClass({ | ||
mixins: [BootstrapMixin], | ||
|
||
propTypes: { | ||
activePage: React.PropTypes.number, | ||
items: React.PropTypes.number, | ||
maxButtons: React.PropTypes.number, | ||
ellipsis: React.PropTypes.bool, | ||
first: React.PropTypes.bool, | ||
last: React.PropTypes.bool, | ||
prev: React.PropTypes.bool, | ||
next: React.PropTypes.bool, | ||
onSelect: React.PropTypes.func | ||
}, | ||
|
||
getDefaultProps() { | ||
return { | ||
activePage: 1, | ||
items: 1, | ||
maxButtons: 0, | ||
first: false, | ||
last: false, | ||
prev: false, | ||
next: false, | ||
ellipsis: true, | ||
bsClass: 'pagination' | ||
}; | ||
}, | ||
|
||
renderPageButtons() { | ||
let pageButtons = []; | ||
let startPage, endPage, hasHiddenPagesBefore, hasHiddenPagesAfter; | ||
let { | ||
maxButtons, | ||
activePage, | ||
items, | ||
onSelect, | ||
ellipsis | ||
} = this.props; | ||
|
||
if(maxButtons){ | ||
let hiddenPagesBefore = activePage - parseInt(maxButtons / 2); | ||
startPage = hiddenPagesBefore > 1 ? hiddenPagesBefore : 1; | ||
hasHiddenPagesAfter = startPage + maxButtons <= items; | ||
|
||
if(!hasHiddenPagesAfter){ | ||
endPage = items; | ||
startPage = items - maxButtons + 1; | ||
} else { | ||
endPage = startPage + maxButtons - 1; | ||
} | ||
} else { | ||
startPage = 1; | ||
endPage = items; | ||
} | ||
|
||
for(let pagenumber = startPage; pagenumber <= endPage; pagenumber++){ | ||
pageButtons.push( | ||
<PaginationButton | ||
key={pagenumber} | ||
eventKey={pagenumber} | ||
active={pagenumber === activePage} | ||
onSelect={onSelect}> | ||
{pagenumber} | ||
</PaginationButton> | ||
); | ||
} | ||
|
||
if(maxButtons && hasHiddenPagesAfter && ellipsis){ | ||
pageButtons.push( | ||
<PaginationButton | ||
key='ellipsis' | ||
disabled> | ||
<span aria-label='More'>...</span> | ||
</PaginationButton> | ||
); | ||
} | ||
|
||
return pageButtons; | ||
}, | ||
|
||
renderPrev() { | ||
if(!this.props.prev){ | ||
return null; | ||
} | ||
|
||
return ( | ||
<PaginationButton | ||
key='prev' | ||
eventKey={this.props.activePage - 1} | ||
disabled={this.props.activePage === 1} | ||
onSelect={this.props.onSelect}> | ||
<span aria-label='Previous'>‹</span> | ||
</PaginationButton> | ||
); | ||
}, | ||
|
||
renderNext() { | ||
if(!this.props.next){ | ||
return null; | ||
} | ||
|
||
return ( | ||
<PaginationButton | ||
key='next' | ||
eventKey={this.props.activePage + 1} | ||
disabled={this.props.activePage === this.props.items} | ||
onSelect={this.props.onSelect}> | ||
<span aria-label='Next'>›</span> | ||
</PaginationButton> | ||
); | ||
}, | ||
|
||
renderFirst() { | ||
if(!this.props.first){ | ||
return null; | ||
} | ||
|
||
return ( | ||
<PaginationButton | ||
key='first' | ||
eventKey={1} | ||
disabled={this.props.activePage === 1 } | ||
onSelect={this.props.onSelect}> | ||
<span aria-label='First'>«</span> | ||
</PaginationButton> | ||
); | ||
}, | ||
|
||
renderLast() { | ||
if(!this.props.last){ | ||
return null; | ||
} | ||
|
||
return ( | ||
<PaginationButton | ||
key='last' | ||
eventKey={this.props.items} | ||
disabled={this.props.activePage === this.props.items} | ||
onSelect={this.props.onSelect}> | ||
<span aria-label='Last'>»</span> | ||
</PaginationButton> | ||
); | ||
}, | ||
|
||
render() { | ||
let classes = this.getBsClassSet(); | ||
return ( | ||
<ul | ||
{...this.props} | ||
className={classNames(this.props.className, classes)}> | ||
{this.renderFirst()} | ||
{this.renderPrev()} | ||
{this.renderPageButtons()} | ||
{this.renderNext()} | ||
{this.renderLast()} | ||
</ul> | ||
); | ||
} | ||
}); | ||
|
||
export default Pagination; |
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,51 @@ | ||
import React from 'react'; | ||
import classNames from 'classnames'; | ||
import BootstrapMixin from './BootstrapMixin'; | ||
import createSelectedEvent from './utils/createSelectedEvent'; | ||
|
||
const PaginationButton = React.createClass({ | ||
mixins: [BootstrapMixin], | ||
|
||
propTypes: { | ||
className: React.PropTypes.string, | ||
eventKey: React.PropTypes.oneOfType([ | ||
React.PropTypes.string, | ||
React.PropTypes.number | ||
]), | ||
onSelect: React.PropTypes.func, | ||
disabled: React.PropTypes.bool, | ||
active: React.PropTypes.bool | ||
}, | ||
|
||
getDefaultProps() { | ||
return { | ||
active: false, | ||
disabled: false | ||
}; | ||
}, | ||
|
||
handleClick(event) { | ||
// This would go away once SafeAnchor is available | ||
event.preventDefault(); | ||
|
||
if (this.props.onSelect) { | ||
let selectedEvent = createSelectedEvent(this.props.eventKey); | ||
this.props.onSelect(event, selectedEvent); | ||
} | ||
}, | ||
|
||
render() { | ||
let classes = this.getBsClassSet(); | ||
|
||
classes.active = this.props.active; | ||
classes.disabled = this.props.disabled; | ||
|
||
return ( | ||
<li className={classNames(this.props.className, classes)}> | ||
<a href='#' onClick={this.handleClick}>{this.props.children}</a> | ||
</li> | ||
); | ||
} | ||
}); | ||
|
||
export default PaginationButton; |
Oops, something went wrong.