mirror of
https://github.com/strapi/strapi.git
synced 2025-09-20 14:00:48 +00:00
Clean LimitSelect component
This commit is contained in:
parent
f67b536645
commit
0a7ed38d3f
@ -5,10 +5,16 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import _ from 'lodash';
|
||||||
|
|
||||||
import styles from './styles.scss';
|
import styles from './styles.scss';
|
||||||
|
|
||||||
class LimitSelect extends React.Component { // eslint-disable-line react/prefer-stateless-function
|
class LimitSelect extends React.Component { // eslint-disable-line react/prefer-stateless-function
|
||||||
|
componentWillMount() {
|
||||||
|
const id = _.uniqueId();
|
||||||
|
this.setState({ id });
|
||||||
|
}
|
||||||
|
|
||||||
getOptionsValues() {
|
getOptionsValues() {
|
||||||
return [{
|
return [{
|
||||||
value: 10,
|
value: 10,
|
||||||
@ -30,16 +36,20 @@ class LimitSelect extends React.Component { // eslint-disable-line react/prefer-
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
// Generate options
|
||||||
const options = this.getOptionsValues().map((optionValue) => (
|
const options = this.getOptionsValues().map((optionValue) => (
|
||||||
<option value={optionValue.value} key={optionValue.value}>{optionValue.label}</option>
|
<option value={optionValue.value} key={optionValue.value}>{optionValue.label}</option>
|
||||||
));
|
));
|
||||||
|
|
||||||
|
// Get id in order to link the `label` and the `select` elements
|
||||||
|
const id = this.state.id;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<form className="form-inline">
|
<form className="form-inline">
|
||||||
<div className="form-group">
|
<div className="form-group">
|
||||||
<label className={styles.label} for="sel1">Items per page:</label>
|
<label className={styles.label} htmlFor={id}>Items per page:</label>
|
||||||
<div className={styles.selectWrapper}>
|
<div className={styles.selectWrapper}>
|
||||||
<select onChange={this.props.onLimitChange} className={`form-control ${styles.select}`} id="sel1">
|
<select onChange={this.props.onLimitChange} className={`form-control ${styles.select}`} id={id}>
|
||||||
{options}
|
{options}
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user