1
0
mirror of https://github.com/ascribe/onion.git synced 2024-11-15 09:35:10 +01:00
onion/js/components/pagination_button.js

51 lines
1.3 KiB
JavaScript
Raw Normal View History

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']),
goToPage: React.PropTypes.func.isRequired,
currentPage: React.PropTypes.number.isRequired
2015-05-22 12:58:06 +02:00
},
render() {
let page = parseInt(this.props.currentPage, 10);
2015-05-22 12:58:06 +02:00
let directionDisplay;
let isDisabled = '';
2015-05-22 12:58:06 +02:00
if(this.props.direction === 'previous') {
page -= 1;
directionDisplay = (
<span>
<span aria-hidden="true">&larr;</span> Previous
</span>
);
} else {
page += 1;
directionDisplay = (
<span>
Next <span aria-hidden="true">&rarr;</span>
</span>
);
}
if(page === 0) {
isDisabled += ' disabled';
}
2015-05-22 12:58:06 +02:00
return (
<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;