Skip to content

Commit 19e9664

Browse files
committed
feat: add react button components
1 parent 9f48cf2 commit 19e9664

4 files changed

Lines changed: 67 additions & 0 deletions

File tree

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { Button } from './button'
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React from 'react'
2+
import classnames from 'classnames'
3+
4+
import { Button } from '../button'
5+
6+
const getFormButtonClassName = ({ className }) => (
7+
classnames('form__button', className)
8+
)
9+
10+
export const FormButton = ({ ...props }) => (
11+
<Button
12+
{...props}
13+
type="submit"
14+
className={getFormButtonClassName({ ...props })}
15+
/>
16+
)
17+
18+
FormButton.propTypes = {
19+
...Button.propTypes
20+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { FormButton } from './form-button'

0 commit comments

Comments
 (0)