summaryrefslogtreecommitdiff
path: root/src/components/Button.tsx
blob: bf98755bd433badeb5ce3dbce383af53af7930c9 (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 type Props = Partial<{
  onClick: () => void;
  route: string;
  variant: 'contained' | 'outlined';
  size: 'sm' | 'md' | 'lg';
  children: string;
}>


const variants = {
  contained: 'bg-black text-white',
  outlined: '',
};

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 border-2 border-black ${variants[variant]} ${sizes[size]}`}
    >
      {children}
    </button>
  );
};

export default Button;