UNPKG

react-toolbox-build4server

Version:

Builds react-toolbox in such a way that it's components can be required and used in node - most likely for server-side rendered webapps - without having to depend on webpack to build your entire server-side project

49 lines (42 loc) 1.19 kB
import React from 'react'; import RadioButton from './RadioButton'; 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 }; handleChange = (value) => { if (this.props.onChange) this.props.onChange(value); }; 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 () { return ( <div data-react-toolbox='radio-group' className={this.props.className}> {this.renderRadioButtons()} </div> ); } } export default RadioGroup;