@@ -3,40 +3,32 @@ import React from 'react'
3
3
interface ButtonProps {
4
4
children : any ,
5
5
className ?: string ,
6
- link ?: string | undefined ,
6
+ link ?: string | null ,
7
7
variant ?: string ,
8
8
disabled ?: boolean
9
9
}
10
10
11
- const variants = [
12
- {
13
- 'primary' : {
14
- 'background' : 'bg-light-gray' ,
15
- 'border' : 'border-2 border-light-gray' ,
16
- 'color' : 'text-primary'
17
- }
11
+ const variants = {
12
+ 'primary' : {
13
+ 'background' : 'bg-light-gray' ,
14
+ 'border' : 'border-2 border-light-gray' ,
15
+ 'color' : 'text-primary'
18
16
} ,
19
- {
20
- 'secondary' : {
21
- 'background' : 'bg-solid-white' ,
22
- 'border' : 'border-2 border-primary' ,
23
- 'color' : 'text-primary'
24
- }
25
- } ,
26
- {
27
- 'tertiary' : {
28
- 'background' : 'bg-primary' ,
29
- 'border' : '' ,
30
- 'color' : 'text-solid-white'
31
- }
17
+ 'secondary' : {
18
+ 'background' : 'bg-solid-white' ,
19
+ 'border' : 'border-2 border-primary' ,
20
+ 'color' : 'text-primary'
32
21
} ,
33
- {
34
- 'dark' : {
35
- 'background' : 'bg-solid-black' ,
36
- 'color' : 'text-solid-white'
37
- }
22
+ 'tertiary' : {
23
+ 'background' : 'bg-primary' ,
24
+ 'border' : '' ,
25
+ 'color' : 'text-solid-white'
26
+ } ,
27
+ 'dark' : {
28
+ 'background' : 'bg-solid-black' ,
29
+ 'color' : 'text-solid-white'
38
30
}
39
- ]
31
+ }
40
32
41
33
const Button = ( {
42
34
children,
@@ -46,7 +38,32 @@ const Button = ({
46
38
className
47
39
} : ButtonProps ) => {
48
40
49
- const styleProps : any = Object . values ( variants . filter ( v => Object . keys ( v ) [ 0 ] == variant ) [ 0 ] ) [ 0 ]
41
+ const styleProps = variants [ variant || 'primary' ] ;
42
+
43
+ const buttonContent = (
44
+ < >
45
+ { children }
46
+ </ >
47
+ ) ;
48
+
49
+ if ( link ) {
50
+ return (
51
+ < a
52
+ href = { link }
53
+ className = { `
54
+ Button
55
+ rounded-full
56
+ py-4
57
+ ${ disabled ? 'bg-light-gray' : styleProps . background }
58
+ ${ styleProps . border }
59
+ ${ styleProps . color }
60
+ ${ className }
61
+ ` }
62
+ >
63
+ { buttonContent }
64
+ </ a >
65
+ )
66
+ }
50
67
51
68
return (
52
69
< button
@@ -62,9 +79,7 @@ const Button = ({
62
79
type = 'button'
63
80
disabled = { disabled }
64
81
>
65
- < a href = { link } >
66
- { children }
67
- </ a >
82
+ { buttonContent }
68
83
</ button >
69
84
)
70
85
}
@@ -76,4 +91,5 @@ Button.defaultProps = {
76
91
className : ''
77
92
}
78
93
79
- export default Button
94
+ export default Button
95
+
0 commit comments