Skip to content

Commit 8dac5b4

Browse files
authored
Merge pull request #273 from setlife-network/ol/fix-button-only
fixes #270
2 parents 4b6ecf1 + c8540e4 commit 8dac5b4

File tree

1 file changed

+48
-32
lines changed

1 file changed

+48
-32
lines changed

components/Button.tsx

+48-32
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,32 @@ import React from 'react'
33
interface ButtonProps {
44
children: any,
55
className?: string,
6-
link?: string | undefined,
6+
link?: string | null,
77
variant?: string,
88
disabled?: boolean
99
}
1010

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'
1816
},
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'
3221
},
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'
3830
}
39-
]
31+
}
4032

4133
const Button = ({
4234
children,
@@ -46,7 +38,32 @@ const Button = ({
4638
className
4739
}: ButtonProps) => {
4840

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

5168
return (
5269
<button
@@ -62,9 +79,7 @@ const Button = ({
6279
type='button'
6380
disabled={disabled}
6481
>
65-
<a href={link}>
66-
{ children }
67-
</a>
82+
{buttonContent}
6883
</button>
6984
)
7085
}
@@ -76,4 +91,5 @@ Button.defaultProps = {
7691
className: ''
7792
}
7893

79-
export default Button
94+
export default Button
95+

0 commit comments

Comments
 (0)