-
Notifications
You must be signed in to change notification settings - Fork 32
/
Button.tsx
55 lines (50 loc) · 1.17 KB
/
Button.tsx
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
import React, { FormEvent } from 'react'
import classNames from 'classnames'
export interface ButtonProps extends ComponentWithClass {
children?: string
color?: 'danger'
disabled?: boolean
icon?: React.ReactNode
onClick?: (event: FormEvent<HTMLButtonElement>) => void
size?: 'small' | 'regular' | 'large' | 'xlarge'
type?: 'button' | 'submit'
variant?: 'primary' | 'secondary' | 'tertiary'
}
export const Button: React.FC<ButtonProps> = ({
children,
className = '',
color,
disabled,
icon,
onClick,
size = 'regular',
type = 'button',
variant,
...rest
}) => {
const classes = classNames('rn-btn', className, {
'rn-btn--disabled': disabled,
[`rn-btn--${variant}`]: variant,
[`rn-btn--${color}`]: color,
[`rn-btn--${size}`]: size,
})
return (
<button
className={classes}
disabled={disabled}
data-testid="rn-button"
type={type}
onClick={e => {
e.currentTarget.blur()
if (onClick) {
onClick(e)
}
}}
{...rest}
>
<span>{children}</span>
{icon && <span className="rn-btn__icon">{icon}</span>}
</button>
)
}
Button.displayName = 'Button'