maputnik/src/fields/number.jsx

38 lines
941 B
React
Raw Normal View History

2016-09-12 19:44:28 +02:00
import React from 'react'
2016-09-13 19:46:44 +02:00
import { Label, Input } from 'rebass'
import {inputBase} from '../theme'
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 = {
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) {
return this.props.onChange(parseFloat(e.target.value))
}
2016-09-12 19:44:28 +02:00
render() {
2016-09-13 19:46:44 +02:00
return <div>
<Label htmlFor={this.props.name} children={this.props.name} />
<input
style={inputBase}
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