2016-12-21 14:36:09 +01:00
|
|
|
import React from 'react'
|
|
|
|
import input from '../../config/input'
|
2017-01-09 16:45:59 +01:00
|
|
|
import DocLabel from '../fields/DocLabel'
|
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,
|
2017-01-09 16:45:59 +01:00
|
|
|
doc: React.PropTypes.string,
|
2016-12-21 14:36:09 +01:00
|
|
|
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-24 17:24:24 +01:00
|
|
|
...this.props.style,
|
2017-01-10 21:28:30 +01:00
|
|
|
}}
|
|
|
|
className="maputnik-input-block"
|
|
|
|
>
|
2017-01-09 16:45:59 +01:00
|
|
|
{this.props.doc &&
|
|
|
|
<DocLabel
|
|
|
|
label={this.props.label}
|
|
|
|
doc={this.props.doc}
|
|
|
|
style={{
|
|
|
|
width: '50%',
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
{!this.props.doc &&
|
2016-12-31 12:17:02 +01:00
|
|
|
<label
|
|
|
|
style={{
|
|
|
|
...input.label,
|
|
|
|
width: '50%',
|
|
|
|
}}>
|
|
|
|
{this.props.label}
|
|
|
|
</label>
|
2017-01-09 16:45:59 +01:00
|
|
|
}
|
2016-12-31 12:17:02 +01:00
|
|
|
{this.renderChildren()}
|
2016-12-21 14:36:09 +01:00
|
|
|
</div>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default InputBlock
|