2016-12-21 14:36:09 +01:00
|
|
|
import React from 'react'
|
2017-01-11 13:34:38 +01:00
|
|
|
import classnames from 'classnames'
|
2017-01-09 16:45:59 +01:00
|
|
|
import DocLabel from '../fields/DocLabel'
|
2016-12-21 14:36:09 +01:00
|
|
|
|
|
|
|
/** Wrap a component with a label */
|
|
|
|
class InputBlock extends React.Component {
|
|
|
|
static propTypes = {
|
2017-01-11 13:34:38 +01:00
|
|
|
label: React.PropTypes.oneOfType([
|
|
|
|
React.PropTypes.string,
|
|
|
|
React.PropTypes.element,
|
|
|
|
]).isRequired,
|
2017-01-09 16:45:59 +01:00
|
|
|
doc: React.PropTypes.string,
|
2017-01-11 13:34:38 +01:00
|
|
|
action: React.PropTypes.element,
|
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)
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2017-01-11 11:35:33 +01:00
|
|
|
return <div style={this.props.style}
|
2017-01-11 13:34:38 +01:00
|
|
|
className={classnames({
|
|
|
|
"maputnik-input-block": true,
|
|
|
|
"maputnik-action-block": this.props.action
|
|
|
|
})}
|
2017-01-10 21:28:30 +01:00
|
|
|
>
|
2017-01-09 16:45:59 +01:00
|
|
|
{this.props.doc &&
|
2017-01-11 13:34:38 +01:00
|
|
|
<div className="maputnik-input-block-label">
|
|
|
|
<DocLabel
|
|
|
|
label={this.props.label}
|
|
|
|
doc={this.props.doc}
|
|
|
|
/>
|
|
|
|
</div>
|
2017-01-09 16:45:59 +01:00
|
|
|
}
|
|
|
|
{!this.props.doc &&
|
2017-01-11 11:35:33 +01:00
|
|
|
<label className="maputnik-input-block-label">
|
2016-12-31 12:17:02 +01:00
|
|
|
{this.props.label}
|
|
|
|
</label>
|
2017-01-09 16:45:59 +01:00
|
|
|
}
|
2017-01-11 13:34:38 +01:00
|
|
|
{this.props.action &&
|
|
|
|
<div className="maputnik-input-block-action">
|
|
|
|
{this.props.action}
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
<div className="maputnik-input-block-content">
|
|
|
|
{this.props.children}
|
|
|
|
</div>
|
2016-12-21 14:36:09 +01:00
|
|
|
</div>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default InputBlock
|