-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathpagination.js
More file actions
40 lines (31 loc) · 1.19 KB
/
pagination.js
File metadata and controls
40 lines (31 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import React from 'react'
import { getStyleProperties } from './utils/styleHelper';
class Pagination extends React.Component {
constructor(props, context) {
super(props, context);
this._handleChange = this._handleChange.bind(this);
}
render() {
const { style, className } = getStyleProperties(this.props, 'pagination');
const { hasPrevious, hasNext, events } = this.props;
const { getPreviousPage, getNextPage } = events;
return (<div className={className} style={style}>
{hasPrevious ? <button onClick={getPreviousPage}>Previous</button> : null }
{this._getSelect()}
{hasNext ? <button onClick={getNextPage}>Next</button> : null }
</div>);
}
_handleChange(e) {
this.props.events.getPage(parseInt(e.target.value));
}
_getSelect() {
if( !this.props.pageProperties || !this.props.pageProperties.maxPage ) { return; }
//Make this nicer
var options = [];
for(var i = 1; i <= this.props.pageProperties.maxPage; i++) {
options.push(<option value={i} key={i}>{i}</option>)
}
return <select onChange={this._handleChange} value={this.props.pageProperties.currentPage}>{options}</select>
}
}
export default Pagination;