-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathindex.js
More file actions
65 lines (60 loc) · 1.82 KB
/
Copy pathindex.js
File metadata and controls
65 lines (60 loc) · 1.82 KB
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
import React from 'react'
import { IconButton as MuiButton, CircularProgress } from '@mui/material'
import { styled } from '@mui/material/styles'
const baseStyles = () => {
return {
boxSizing: 'border-box',
boxShadow: 'none',
'&:focus': {
boxShadow: 'none',
},
outline: 'none',
}
}
const variantStyles = (theme, variant, color) => {
const colorPalette = theme.palette[color]
switch (variant) {
case 'roundedBlack':
return {
backgroundColor: 'black',
color: colorPalette.main,
border: `2px solid ${colorPalette.main}`,
borderRadius: '50%',
'&:hover': {
color: 'black',
background: colorPalette.dark,
border: `2px solid ${colorPalette.dark}`,
},
'&.Mui-disabled': {
backgroundColor: colorPalette.dark,
color: colorPalette.contrastText,
opacity: 0.5,
},
}
default:
return {
borderRadius: 0,
color: colorPalette.main,
}
}
}
const IconButton = ({
color = 'primary',
strong = false,
loading = false,
...props
}) => {
const CustomIconButton = styled(MuiButton, {
// MUI IconButtons don't have variants so no point in forwarding them
shouldForwardProp: prop => prop !== 'variant',
})(({ theme }) => ({
...baseStyles(),
...variantStyles(theme, props.variant, color),
}))
return (
<CustomIconButton {...props} disabled={loading || props.disabled}>
{loading ? <CircularProgress size={20} /> : props.children}
</CustomIconButton>
)
}
export default IconButton