maputnik/src/components/inputs/InputBlock.jsx

61 lines
1.3 KiB
React
Raw Normal View History

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'
/** 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,
children: React.PropTypes.element.isRequired,
2016-12-24 17:24:24 +01:00
style: React.PropTypes.object,
}
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%',
}
})
})
}
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()}
</div>
}
}
export default InputBlock