1
0
mirror of https://github.com/ascribe/onion.git synced 2024-06-30 13:41:57 +02:00
onion/js/components/ascribe_pagination/pagination_button.js

70 lines
1.8 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
2015-10-16 13:00:19 +02:00
import Glyphicon from 'react-bootstrap/lib/Glyphicon';
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>
2015-10-16 13:00:19 +02:00
<span aria-hidden="true"><Glyphicon glyph='chevron-left'/></span> {getLangText('Previous')}
2015-05-22 12:58:06 +02:00
</span>
);
} else {
page += 1;
directionDisplay = (
<span>
2015-10-16 13:00:19 +02:00
{getLangText('Next')} <span aria-hidden="true"><Glyphicon glyph='chevron-right'/></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;