Number editor return number. (#541)
Adding support for `min`, `max`, `step` on the input element and adding `valueType` for specifying the return type, so the `NumberControl` can return actual numbers.
This commit is contained in:
parent
ac8df98407
commit
5dfc0f0f24
@ -1,17 +1,41 @@
|
||||
import React, { PropTypes } from 'react';
|
||||
|
||||
export default class StringControl extends React.Component {
|
||||
export default class NumberControl extends React.Component {
|
||||
handleChange = (e) => {
|
||||
this.props.onChange(e.target.value);
|
||||
const valueType = this.props.field.get('valueType');
|
||||
const { onChange } = this.props;
|
||||
if(valueType === 'int') {
|
||||
onChange(parseInt(e.target.value, 10));
|
||||
} else if(valueType === 'float') {
|
||||
onChange(parseFloat(e.target.value));
|
||||
} else {
|
||||
onChange(e.target.value);
|
||||
}
|
||||
};
|
||||
|
||||
render() {
|
||||
return <input type="number" id={this.props.forID} value={this.props.value || ''} onChange={this.handleChange} />;
|
||||
const { field, value, forID } = this.props;
|
||||
const min = field.get('min', '');
|
||||
const max = field.get('max', '');
|
||||
const step = field.get('step', field.get('valueType') === 'int' ? 1 : '');
|
||||
return <input
|
||||
type="number"
|
||||
id={forID}
|
||||
value={value || ''}
|
||||
step={step}
|
||||
min={min}
|
||||
max={max}
|
||||
onChange={this.handleChange}
|
||||
/>;
|
||||
}
|
||||
}
|
||||
|
||||
StringControl.propTypes = {
|
||||
NumberControl.propTypes = {
|
||||
onChange: PropTypes.func.isRequired,
|
||||
value: PropTypes.node,
|
||||
forID: PropTypes.string,
|
||||
valueType: PropTypes.string,
|
||||
step: PropTypes.number,
|
||||
min: PropTypes.number,
|
||||
max: PropTypes.number,
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user