blob: 56915d49c3798c7a032791c94a0a51e7e67c6da7 (
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';
export interface Props extends React.ButtonHTMLAttributes<HTMLButtonElement> {
onClick?: () => void;
route?: string;
variant?: 'contained' | 'outlined';
size?: 'sm' | 'md' | 'lg';
children?: string;
}
const variants = {
contained: 'bg-black text-white hover:underline ring-gray-400',
outlined: 'hover:shadow border border-gray-300 ring-gray-200',
};
const sizes = {
lg: 'p-5',
md: 'p-4',
sm: 'p-3',
};
const style = 'm-3 rounded-sm font-semibold focus:outline-none active:ring-2';
const Button: React.FC<Props> = ({ onClick, route, variant = 'contained', size = 'md', type = 'button', ...props }) => {
const history = useHistory();
const navigateRoute = useCallback(() => history.push(route || '/'), [route, history]);
return (
<button
type={type}
onClick={route ? navigateRoute : onClick}
className={`${style} ${variants[variant]} ${sizes[size]}`}
{...props}
/>
);
};
export default Button;
|