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

69 lines
1.7 KiB
JavaScript
Raw Normal View History

'use strict';
2015-05-22 12:58:06 +02:00
import React from 'react';
import { Link } from 'react-router';
2015-05-22 12:58:06 +02:00
import { getLangText } from '../../utils/lang_utils';
2015-05-22 12:58:06 +02:00
let PaginationButton = React.createClass({
propTypes: {
direction: React.PropTypes.oneOf(['previous', 'next']),
goToPage: React.PropTypes.func.isRequired,
2015-05-22 17:11:17 +02:00
currentPage: React.PropTypes.number.isRequired,
totalPages: React.PropTypes.number.isRequired
},
isInRange(page) {
return page > 0 && page <= this.props.totalPages;
2015-05-22 12:58:06 +02:00
},
render() {
let directionDisplay;
2015-05-22 17:11:17 +02:00
let page = this.props.currentPage;
let isDisabled = '';
2015-05-22 17:11:17 +02:00
let anchor;
2015-05-22 12:58:06 +02:00
if(this.props.direction === 'previous') {
page -= 1;
directionDisplay = (
<span>
<span aria-hidden="true">&larr;</span> {getLangText('Previous')}
2015-05-22 12:58:06 +02:00
</span>
);
} else {
page += 1;
directionDisplay = (
<span>
{getLangText('Next')} <span aria-hidden="true">&rarr;</span>
2015-05-22 12:58:06 +02:00
</span>
);
}
2015-05-22 17:11:17 +02:00
if (this.isInRange(page)) {
anchor = (
<Link to="/collection"
2015-05-22 12:58:06 +02:00
query={{page}}
onClick={this.props.goToPage(page)}>
{directionDisplay}
</Link>
2015-05-22 17:11:17 +02:00
);
} else {
isDisabled += ' disabled';
anchor = (
<a>
{directionDisplay}
</a>
);
}
return (
<li className={this.props.direction + isDisabled }>
{anchor}
2015-05-22 12:58:06 +02:00
</li>
);
}
});
2015-05-22 17:11:17 +02:00
export default PaginationButton;