blob: 5724b40b6a94d0987ed512d0f21cb1075a05095a (
plain)
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
|
import React, { useCallback } from 'react';
import { useHistory } from 'react-router-dom';
interface Props {
onClick?: () => void;
route?: string;
variant?: 'contained' | 'outlined';
size?: 'sm' | 'md' | 'lg';
children: string;
}
const variants = {
contained: 'bg-black text-white',
outlined: 'border-2 border-black',
};
const sizes = {
lg: 'p-5',
md: 'p-4',
sm: 'p-3',
};
const Button: React.FC<Props> = ({ onClick, route, variant = 'contained', size = 'md', children }) => {
const history = useHistory();
const navigateRoute = useCallback(() => history.push(route || '/'), [route, history]);
return (
<button
type="button"
onClick={route ? navigateRoute : onClick}
className={`m-3 font-bold tracking-wide hover:underline focus:outline-none ${variants[variant]} ${sizes[size]}`}
>
{children}
</button>
);
};
export default Button;
|