-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathButton.tsx
88 lines (82 loc) · 2.38 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import { FC, ButtonHTMLAttributes } from "react";
import Link from "next/link";
type Props = ButtonHTMLAttributes<HTMLButtonElement> & {
readonly size?: "md" | "lg";
readonly variant?: "primary" | "secondary";
/** Whether to invert the background and text/border colors, use depending on surrounding elements */
readonly invert?: boolean;
readonly href?: string;
};
/** Button component */
const Button: FC<Props> = ({
children,
className,
size = "lg",
variant = "primary",
invert = false,
href,
...props
}: Props) => {
// Classnames for border, background, text styles
let classes: string;
if (invert) {
switch (variant) {
case "primary":
// White border, white background, blue text
classes = `border-white bg-white text-blue hover:border-transparent hover:bg-sky-200 hover:text-blue-100`;
break;
case "secondary":
// White border, blue background, white text
classes = `border-white bg-blue text-white hover:border-transparent hover:bg-sky-200 hover:text-blue-100`;
break;
}
} else {
switch (variant) {
case "primary":
// Blue border, blue background, white text
classes = `border-blue bg-blue text-white hover:border-transparent hover:bg-sky-400 `;
break;
case "secondary":
// Blue border, white background, blue text
classes = `border-blue bg-white text-blue hover:border-sky-500 hover:text-sky-500 hover:bg-sky-100`;
break;
}
}
const buttonClasses = `
${classes}
${
size === "lg"
? "h-auto py-2.5 text-sm md:text-base font-semibold"
: "h-auto py-2.5 text-sm font-normal"
}
font-poppins transition-all px-8 border-2 border-solid rounded-full text-base
${className}
`;
return href ? (
href.startsWith("http") ? (
<a
href={href}
target="_blank"
rel="noopener noreferrer"
className="hover:opacity-100"
>
<button className={buttonClasses} tabIndex={-1} {...props}>
{children}
</button>
</a>
) : (
<Link href={href}>
<a className="hover:opacity-100">
<button className={buttonClasses} tabIndex={-1} {...props}>
{children}
</button>
</a>
</Link>
)
) : (
<button className={buttonClasses} {...props}>
{children}
</button>
);
};
export default Button;