react-toolbox/components/radio/RadioGroup.js

49 lines
1.2 KiB
JavaScript
Raw Normal View History

import React from 'react';
import RadioButton from './RadioButton';
2015-10-22 02:31:17 +03:00
class RadioGroup extends React.Component {
static propTypes = {
children: React.PropTypes.node,
className: React.PropTypes.string,
disabled: React.PropTypes.bool,
name: React.PropTypes.string,
onChange: React.PropTypes.func,
value: React.PropTypes.any
};
static defaultProps = {
className: '',
disabled: false
};
2015-11-12 03:07:30 +03:00
handleChange = (value) => {
if (this.props.onChange) this.props.onChange(value);
2015-10-22 02:31:17 +03:00
};
renderRadioButtons () {
return React.Children.map(this.props.children, (radio, idx) => {
return (
<RadioButton
{...radio.props}
2015-11-12 03:07:30 +03:00
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 () {
return (
2016-02-08 21:42:00 +03:00
<div data-react-toolbox='radio-group' className={this.props.className}>
{this.renderRadioButtons()}
</div>
);
}
2015-10-21 13:25:07 +03:00
}
2015-10-22 02:31:17 +03:00
export default RadioGroup;