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 }
|