maputnik/src/fields/string.jsx

34 lines
868 B
React
Raw Normal View History

2016-09-12 19:54:02 +02:00
import React from 'react'
import inputStyle from './input.js'
2016-09-12 19:54:02 +02:00
/*** Number fields with support for min, max and units and documentation*/
class StringField extends React.Component {
static propTypes = {
onChange: React.PropTypes.func.isRequired,
2016-09-12 19:54:02 +02:00
name: React.PropTypes.string.isRequired,
2016-09-12 20:29:53 +02:00
value: React.PropTypes.string,
2016-09-12 19:54:02 +02:00
default: 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 = e.target.value
return this.props.onChange(value === "" ? null: value)
2016-09-12 20:29:53 +02:00
}
render() {
return <div style={inputStyle.property}>
<label style={inputStyle.label}>{this.props.name}</label>
2016-09-13 19:46:44 +02:00
<input
style={inputStyle.input}
2016-09-13 19:46:44 +02:00
name={this.props.name}
placeholder={this.props.default}
2016-09-15 18:51:49 +02:00
value={this.props.value ? this.props.value : ""}
2016-09-13 19:46:44 +02:00
onChange={this.onChange.bind(this)}
/>
</div>
2016-09-12 19:54:02 +02:00
}
}
export default StringField