All files / components/input-radio/radio-group index.js

0% Statements 0/23
0% Branches 0/6
0% Functions 0/4
0% Lines 0/10
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34                                                                   
import React from 'react'
import PropTypes from 'prop-types'
import StyledRadioGroup from './styled-radio-group'
import cx from 'classnames'
 
const RadioGroup = ({ children, name, directionItems, onChange, label }) => {
  const radioButtons = React.Children.map(children, (radio, index) =>
    React.cloneElement(radio, {
      name,
      id: `${name}_${index}`,
      className: cx(radio.props.clasName, 'Input-Radio'),
      onChange: (e) => onChange(e, radio.props.value)
    })
  )
 
  return (
    <StyledRadioGroup directionItems={directionItems}>
      {label && <div className='Input-label'>{label}</div>}
      <div className='radioGroup-container'>
        { radioButtons }
      </div>
    </StyledRadioGroup>
  )
}
 
RadioGroup.propTypes = {
  children: PropTypes.arrayOf(PropTypes.object),
  name: PropTypes.string,
  directionItems: PropTypes.string,
  onChange: PropTypes.func.isRequired
}
 
export { RadioGroup }