2019-07-25 14:29:50 +00:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import RadioButton from './radio-button';
|
|
|
|
import styled from 'styled-components';
|
|
|
|
|
|
|
|
const StyledDiv = styled.div`
|
|
|
|
display: flex;
|
|
|
|
`;
|
|
|
|
|
|
|
|
class RadioButtonGroup extends React.Component {
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
selectedOption: this.props.selected
|
|
|
|
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
handleOptionChange = changeEvent => {
|
|
|
|
this.setState({
|
|
|
|
selectedOption: changeEvent.target.value
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const options = this.props.options;
|
|
|
|
return (
|
|
|
|
<StyledDiv>
|
|
|
|
{options.map(option => {
|
|
|
|
return (
|
|
|
|
<RadioButton
|
|
|
|
name={this.props.name}
|
|
|
|
value={option.value}
|
|
|
|
checked={this.state.selectedOption === option.value}
|
|
|
|
onChange={this.handleOptionChange}
|
|
|
|
disabled={option.disabled}
|
|
|
|
label={option.label}
|
2019-07-25 15:39:25 +00:00
|
|
|
spaceBtwnElems={this.props.spaceBtwnElems}
|
2019-07-25 14:29:50 +00:00
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
</StyledDiv>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
RadioButtonGroup.propTypes = {
|
|
|
|
name: PropTypes.string.isRequired,
|
|
|
|
options: PropTypes.arrayOf(PropTypes.shape({
|
|
|
|
value: PropTypes.string.isRequired,
|
|
|
|
label: PropTypes.string,
|
|
|
|
disabled: PropTypes.bool
|
|
|
|
})).isRequired,
|
2019-07-25 15:39:25 +00:00
|
|
|
selected: PropTypes.string.isRequired,
|
|
|
|
spaceBtwnElems: PropTypes.number
|
2019-07-25 14:29:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RadioButtonGroup.defaultProps = {
|
2019-07-25 15:39:25 +00:00
|
|
|
selected: undefined,
|
|
|
|
spaceBtwnElems: '33'
|
2019-07-25 14:29:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default RadioButtonGroup;
|