2016-09-12 19:44:28 +02:00
|
|
|
import React from 'react'
|
2016-09-13 20:30:03 +02:00
|
|
|
import inputStyle from './input.js'
|
2016-09-12 19:44:28 +02:00
|
|
|
|
|
|
|
/*** Number fields with support for min, max and units and documentation*/
|
|
|
|
class NumberField extends React.Component {
|
|
|
|
static propTypes = {
|
2016-09-12 20:10:49 +02:00
|
|
|
onChange: React.PropTypes.func.isRequired,
|
2016-09-12 19:44:28 +02:00
|
|
|
name: React.PropTypes.string.isRequired,
|
2016-09-12 19:47:28 +02:00
|
|
|
value: React.PropTypes.number,
|
2016-09-12 19:44:28 +02:00
|
|
|
default: React.PropTypes.number,
|
|
|
|
unit: React.PropTypes.string,
|
|
|
|
min: React.PropTypes.number,
|
|
|
|
max: React.PropTypes.number,
|
|
|
|
doc: React.PropTypes.string,
|
|
|
|
}
|
|
|
|
|
2016-09-12 20:29:53 +02:00
|
|
|
onChange(e) {
|
2016-09-19 15:06:34 +02:00
|
|
|
const value = parseFloat(e.target.value)
|
|
|
|
/*TODO: we can do range validation already here?
|
|
|
|
if(this.props.min && value < this.props.min) return
|
|
|
|
if(this.props.max && value > this.props.max) return
|
|
|
|
*/
|
|
|
|
this.props.onChange(value)
|
2016-09-12 20:29:53 +02:00
|
|
|
}
|
|
|
|
|
2016-09-12 19:44:28 +02:00
|
|
|
render() {
|
2016-09-13 20:30:03 +02:00
|
|
|
return <div style={inputStyle.property}>
|
|
|
|
<label style={inputStyle.label}>{this.props.name}</label>
|
2016-09-13 19:46:44 +02:00
|
|
|
<input
|
2016-09-13 20:30:03 +02:00
|
|
|
style={inputStyle.input}
|
2016-09-13 19:46:44 +02:00
|
|
|
type="number"
|
|
|
|
name={this.props.name}
|
|
|
|
placeholder={this.props.default}
|
|
|
|
value={this.props.value}
|
|
|
|
onChange={this.onChange.bind(this)}
|
|
|
|
/>
|
|
|
|
</div>
|
2016-09-12 19:44:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default NumberField
|