|
| 1 | +import React from 'react' |
| 2 | +import PropTypes from 'prop-types' |
| 3 | +import classnames from 'classnames' |
| 4 | + |
| 5 | +const getButtonClassName = ({ className, color, inverse, loading }) => ( |
| 6 | + classnames(className, 'button', { |
| 7 | + 'button--is-inverse': inverse, |
| 8 | + 'button--is-loading': loading, |
| 9 | + [`button--is-${color}`]: color |
| 10 | + }) |
| 11 | +) |
| 12 | + |
| 13 | +export const Button = ({ |
| 14 | + children, onClick, className, type, color, inverse, loading |
| 15 | +}) => ( |
| 16 | + <button |
| 17 | + type={type} |
| 18 | + className={getButtonClassName({ className, color, inverse, loading })} |
| 19 | + onClick={onClick} |
| 20 | + > |
| 21 | + {children} |
| 22 | + </button> |
| 23 | +) |
| 24 | + |
| 25 | +Button.propTypes = { |
| 26 | + children: PropTypes.oneOfType([ |
| 27 | + PropTypes.node, |
| 28 | + PropTypes.element, |
| 29 | + PropTypes.elementType, |
| 30 | + PropTypes.func |
| 31 | + ]).isRequired, |
| 32 | + onClick: PropTypes.func, |
| 33 | + className: PropTypes.string, |
| 34 | + type: PropTypes.string, |
| 35 | + color: PropTypes.oneOf([ |
| 36 | + 'primary', 'yellow', 'red', 'blue', 'green', 'grey', 'white', 'black' |
| 37 | + ]), |
| 38 | + inverse: PropTypes.bool, |
| 39 | + loading: PropTypes.bool |
| 40 | +} |
| 41 | + |
| 42 | +Button.defaultProps = { |
| 43 | + inverse: false, |
| 44 | + loading: false |
| 45 | +} |
0 commit comments