2016-05-29 23:09:02 +03:00
|
|
|
import React, { Component, PropTypes } from 'react';
|
|
|
|
import { themr } from 'react-css-themr';
|
|
|
|
import { RADIO } from '../identifiers.js';
|
|
|
|
import InjectRadioButton from './RadioButton.js';
|
2015-10-06 22:18:39 +03:00
|
|
|
|
2016-05-29 23:09:02 +03:00
|
|
|
const factory = (RadioButton) => {
|
|
|
|
class RadioGroup extends Component {
|
|
|
|
static propTypes = {
|
|
|
|
children: PropTypes.node,
|
|
|
|
className: PropTypes.string,
|
|
|
|
disabled: PropTypes.bool,
|
|
|
|
name: PropTypes.string,
|
|
|
|
onChange: PropTypes.func,
|
|
|
|
value: PropTypes.any
|
|
|
|
};
|
2015-10-06 22:18:39 +03:00
|
|
|
|
2016-05-29 23:09:02 +03:00
|
|
|
static defaultProps = {
|
|
|
|
className: '',
|
|
|
|
disabled: false
|
|
|
|
};
|
2015-10-06 22:18:39 +03:00
|
|
|
|
2016-05-29 23:09:02 +03:00
|
|
|
handleChange = (value) => {
|
|
|
|
if (this.props.onChange) this.props.onChange(value);
|
|
|
|
};
|
2015-10-06 22:18:39 +03:00
|
|
|
|
2016-05-29 23:09:02 +03:00
|
|
|
renderRadioButtons () {
|
|
|
|
return React.Children.map(this.props.children, (radio, idx) => {
|
|
|
|
return (
|
|
|
|
<RadioButton
|
|
|
|
{...radio.props}
|
|
|
|
checked={radio.props.value === this.props.value}
|
|
|
|
disabled={this.props.disabled || radio.props.disabled}
|
|
|
|
key={idx}
|
|
|
|
label={radio.props.label}
|
|
|
|
onChange={this.handleChange.bind(this, radio.props.value)}
|
|
|
|
value={radio.props.value}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
2015-10-06 22:18:39 +03:00
|
|
|
return (
|
2016-05-29 23:09:02 +03:00
|
|
|
<div data-react-toolbox='radio-group' className={this.props.className}>
|
|
|
|
{this.renderRadioButtons()}
|
|
|
|
</div>
|
2015-10-06 22:18:39 +03:00
|
|
|
);
|
2016-05-29 23:09:02 +03:00
|
|
|
}
|
2015-10-20 08:40:51 +03:00
|
|
|
}
|
2015-10-06 22:18:39 +03:00
|
|
|
|
2016-05-29 23:09:02 +03:00
|
|
|
return RadioGroup;
|
|
|
|
};
|
2015-10-22 02:31:17 +03:00
|
|
|
|
2016-05-29 23:09:02 +03:00
|
|
|
const RadioGroup = factory(InjectRadioButton);
|
|
|
|
export default themr(RADIO)(RadioGroup);
|
|
|
|
export { factory as radioGroupFactory };
|
|
|
|
export { RadioGroup };
|