All files / components/button-group index.js

0% Statements 0/28
0% Branches 0/6
0% Functions 0/3
0% Lines 0/16
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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61                                                                                                                         
import React from 'react'
import PropTypes from 'prop-types'
import cx from 'classnames'
import ButtonGroupStyled from './button-group.styled'
 
const ButtonGroup = ({
  className,
  type,
  width,
  orientation,
  children,
  outline
}) => {
  let _children = []
  if (type) {
    children.forEach((component, i) => {
      const btn = React.cloneElement(component, { type: type, key: i })
      _children.push(btn)
    })
  } else {
    _children = children
  }
 
  return (
    <ButtonGroupStyled
      className={cx({
        'button-group-outline': outline,
        'button-group-horizontal': (orientation === 'horizontal'),
        'button-group-vertical': (orientation === 'vertical')
      }, className, type)}
      width={width}
      orientation={orientation}>
      {_children}
    </ButtonGroupStyled>
  )
}
 
ButtonGroup.propTypes = {
  className: PropTypes.string,
  type: PropTypes.oneOf([
    'primary',
    'secondary',
    'danger',
    'default',
    null
  ]),
  outline: PropTypes.bool,
  width: PropTypes.string,
  orientation: PropTypes.string,
  children: PropTypes.oneOfType([PropTypes.element, PropTypes.array])
}
 
ButtonGroup.defaultProps = {
  outline: false,
  type: null,
  width: '100%',
  orientation: 'horizontal'
}
 
export { ButtonGroup }