61 lines
1.3 KiB
JavaScript
Raw Normal View History

2017-04-11 17:35:40 +02:00
/**
*
* LimitSelect
*
*/
import React from 'react';
2017-04-11 18:30:57 +02:00
import _ from 'lodash';
2017-04-11 17:35:40 +02:00
import styles from './styles.scss';
class LimitSelect extends React.Component { // eslint-disable-line react/prefer-stateless-function
2017-04-11 18:30:57 +02:00
componentWillMount() {
const id = _.uniqueId();
this.setState({ id });
}
2017-04-11 18:37:09 +02:00
/**
* Return the list of default values to populate the select options
*
* @returns {number[]}
*/
2017-04-11 17:35:40 +02:00
getOptionsValues() {
2017-04-11 18:37:09 +02:00
return [10, 20, 50, 100];
2017-04-11 17:35:40 +02:00
}
shouldComponentUpdate() {
return false;
}
render() {
2017-04-11 18:30:57 +02:00
// Generate options
2017-04-11 17:35:40 +02:00
const options = this.getOptionsValues().map((optionValue) => (
2017-04-11 18:37:09 +02:00
<option value={optionValue} key={optionValue}>{optionValue}</option>
2017-04-11 17:35:40 +02:00
));
2017-04-11 18:30:57 +02:00
// Get id in order to link the `label` and the `select` elements
const id = this.state.id;
2017-04-11 17:35:40 +02:00
return (
<form className="form-inline">
<div className="form-group">
2017-04-11 18:30:57 +02:00
<label className={styles.label} htmlFor={id}>Items per page:</label>
2017-04-11 17:35:40 +02:00
<div className={styles.selectWrapper}>
2017-04-11 18:30:57 +02:00
<select onChange={this.props.onLimitChange} className={`form-control ${styles.select}`} id={id}>
2017-04-11 17:35:40 +02:00
{options}
</select>
</div>
</div>
</form>
);
}
}
2017-04-11 19:20:33 +02:00
LimitSelect.propTypes = {
limit: React.PropTypes.number,
onLimitChange: React.PropTypes.func,
};
2017-04-11 17:35:40 +02:00
export default LimitSelect;