2015-05-22 12:58:06 +02:00
|
|
|
import React from 'react';
|
|
|
|
import Router from 'react-router';
|
|
|
|
|
|
|
|
let Link = Router.Link;
|
|
|
|
|
|
|
|
let PaginationButton = React.createClass({
|
|
|
|
propTypes: {
|
|
|
|
direction: React.PropTypes.oneOf(['previous', 'next']),
|
2015-05-22 13:43:53 +02:00
|
|
|
goToPage: React.PropTypes.func.isRequired,
|
|
|
|
currentPage: React.PropTypes.number.isRequired
|
2015-05-22 12:58:06 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
render() {
|
2015-05-22 13:43:53 +02:00
|
|
|
let page = parseInt(this.props.currentPage, 10);
|
2015-05-22 12:58:06 +02:00
|
|
|
let directionDisplay;
|
|
|
|
|
2015-05-22 13:43:53 +02:00
|
|
|
let isDisabled = '';
|
|
|
|
|
2015-05-22 12:58:06 +02:00
|
|
|
if(this.props.direction === 'previous') {
|
|
|
|
page -= 1;
|
|
|
|
directionDisplay = (
|
|
|
|
<span>
|
|
|
|
<span aria-hidden="true">←</span> Previous
|
|
|
|
</span>
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
page += 1;
|
|
|
|
directionDisplay = (
|
|
|
|
<span>
|
|
|
|
Next <span aria-hidden="true">→</span>
|
|
|
|
</span>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-05-22 13:43:53 +02:00
|
|
|
if(page === 0) {
|
|
|
|
isDisabled += ' disabled';
|
|
|
|
}
|
|
|
|
|
2015-05-22 12:58:06 +02:00
|
|
|
return (
|
2015-05-22 13:43:53 +02:00
|
|
|
<li className={this.props.direction + isDisabled }>
|
2015-05-22 12:58:06 +02:00
|
|
|
<Link to="pieces"
|
|
|
|
query={{page}}
|
|
|
|
onClick={this.props.goToPage(page)}>
|
|
|
|
{directionDisplay}
|
|
|
|
</Link>
|
|
|
|
</li>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
export default PaginationButton;
|