2016-12-21 14:36:09 +01:00
|
|
|
import React from 'react'
|
|
|
|
import input from '../../config/input'
|
2016-12-21 16:11:08 +01:00
|
|
|
import { margins } from '../../config/scales'
|
2016-12-21 14:36:09 +01:00
|
|
|
|
|
|
|
/** Wrap a component with a label */
|
|
|
|
class InputBlock extends React.Component {
|
|
|
|
static propTypes = {
|
|
|
|
label: React.PropTypes.string.isRequired,
|
|
|
|
children: React.PropTypes.element.isRequired,
|
2016-12-24 17:24:24 +01:00
|
|
|
style: React.PropTypes.object,
|
2016-12-21 14:36:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
onChange(e) {
|
|
|
|
const value = e.target.value
|
|
|
|
return this.props.onChange(value === "" ? null: value)
|
|
|
|
}
|
|
|
|
|
2016-12-31 12:17:02 +01:00
|
|
|
renderChildren() {
|
|
|
|
return React.Children.map(this.props.children, child => {
|
|
|
|
return React.cloneElement(child, {
|
|
|
|
style: {
|
|
|
|
...child.props.style,
|
|
|
|
width: '50%',
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-12-21 14:36:09 +01:00
|
|
|
render() {
|
|
|
|
return <div style={{
|
2016-12-31 12:17:02 +01:00
|
|
|
...input.property,
|
2016-12-24 17:24:24 +01:00
|
|
|
...this.props.style,
|
2016-12-21 14:36:09 +01:00
|
|
|
}}>
|
2016-12-31 12:17:02 +01:00
|
|
|
<label
|
|
|
|
style={{
|
|
|
|
...input.label,
|
|
|
|
width: '50%',
|
|
|
|
}}>
|
|
|
|
{this.props.label}
|
|
|
|
</label>
|
|
|
|
{this.renderChildren()}
|
2016-12-21 14:36:09 +01:00
|
|
|
</div>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default InputBlock
|