-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathindex.tsx
79 lines (68 loc) · 1.84 KB
/
index.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
/*--------------------------------------------------------------------------
* Copyright (c) 2019-2021, Postgres.ai, Nikolay Samokhvalov nik@postgres.ai
* All Rights Reserved. Proprietary and confidential.
* Unauthorized copying of this file, via any medium is strictly prohibited
*--------------------------------------------------------------------------
*/
import React, { forwardRef } from 'react'
import { makeStyles } from '@material-ui/styles'
import { Button as ButtonBase, ButtonProps } from '@material-ui/core'
import clsx from 'clsx'
import { colors } from '@postgres.ai/shared/styles/colors'
type Props = Omit<
ButtonProps,
'variant' | 'color' | 'className' | 'disabled'
> & {
variant?: 'primary' | 'secondary'
className?: string
isDisabled?: boolean
}
const useStyles = makeStyles(
{
root: {
whiteSpace: 'nowrap',
'&.MuiButton-outlinedPrimary': {
background: colors.white,
'&:hover': {
background: '#f4f6f7',
},
},
'&:disabled': {
cursor: 'not-allowed',
pointerEvents: 'all',
'&.MuiButton-outlinedPrimary:hover': {
background: colors.white,
border: '1px solid rgba(0, 0, 0, 0.12)',
},
},
},
},
{ index: 1 },
)
const VARIANT_MAP = {
primary: 'contained' as const,
secondary: 'outlined' as const,
}
export const Button = forwardRef(
(props: Props, ref: React.Ref<HTMLButtonElement>) => {
const {
variant = 'secondary',
className,
isDisabled,
size = 'small',
...buttonProps
} = props
const classes = useStyles()
return (
<ButtonBase
{...buttonProps}
size={size}
ref={ref}
disabled={isDisabled}
className={clsx(classes.root, className)}
variant={VARIANT_MAP[variant]}
color="primary"
/>
)
},
)