1
0
mirror of https://github.com/yldio/copilot.git synced 2025-01-09 18:40:12 +02:00
copilot/ui/src/components/form/group.js

73 lines
1.5 KiB
JavaScript
Raw Normal View History

import React, { Component } from 'react';
import { Broadcast } from 'react-broadcast';
import { Field } from 'redux-form';
import Fieldset from './fieldset';
import { Baseline } from '../../shared/composers';
import { rndId } from '../../shared/functions';
2017-02-20 18:15:36 +02:00
class FormGroup extends Component {
constructor(props) {
super(props);
this.renderGroup = this.renderGroup.bind(this);
}
renderGroup(inputProps) {
const {
className,
style,
children,
...rest
} = this.props;
const value = {
id: rndId(),
...rest,
...inputProps
};
return (
<Fieldset className={className} style={style}>
<Broadcast channel='input-group' value={value}>
<div>
{children}
</div>
</Broadcast>
</Fieldset>
);
}
render() {
const {
name = rndId(),
defaultValue,
normalize,
reduxForm = false
} = this.props;
if (!reduxForm) {
return this.renderGroup({});
}
return (
<Field
name={name}
defaultValue={defaultValue}
component={this.renderGroup}
normalize={normalize}
/>
);
}
}
FormGroup.propTypes = {
children: React.PropTypes.node,
className: React.PropTypes.string,
defaultValue: React.PropTypes.string,
name: React.PropTypes.string,
normalize: React.PropTypes.func,
reduxForm: React.PropTypes.bool,
style: React.PropTypes.object
};
export default Baseline(
2017-02-20 18:15:36 +02:00
FormGroup
);