import React from 'react'; import PropTypes from 'prop-types'; import ls from './RadioButtons.less'; export default class RadioButtons extends React.Component { render() { return
{this.props.children}
} getChildContext() { return { radioButtonsGroupName: this.groupId, radioButtonsValue: this.props.value, radioButtonsOnChange: this.props.onChange } } groupId = 'group_' + GROUP_COUNTER++; } export function RadioButton({value, label}, {radioButtonsGroupName, radioButtonsValue, radioButtonsOnChange}) { const onChange = e => { radioButtonsOnChange(e.target.value) }; label = label || value; return } RadioButtons.childContextTypes = { radioButtonsGroupName: PropTypes.string.isRequired, radioButtonsValue: PropTypes.string.isRequired, radioButtonsOnChange: PropTypes.func.isRequired }; RadioButton.contextTypes = RadioButtons.childContextTypes; let GROUP_COUNTER = 0;