-
Notifications
You must be signed in to change notification settings - Fork 2
/
ColorChip.tsx
57 lines (49 loc) · 1.04 KB
/
ColorChip.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
import React from 'react';
import makeStyles from '@mui/styles/makeStyles';
import {darken} from '@mui/material/styles';
import classNames from 'classnames';
import Chip, {ChipProps} from '@mui/material/Chip';
import {colord} from 'colord';
const styles = {
chip({color}) {
const backgroundColor = color;
const foregroundColor = color
? colord(color).isLight()
? '#111'
: '#ddd'
: undefined;
return {
backgroundColor,
color: foregroundColor,
'&:hover, &:focus': {
backgroundColor: backgroundColor && darken(backgroundColor, 0.1),
},
};
},
};
const useStyles = makeStyles(styles);
interface ColorChipExtraProps {
color?: string;
}
const ColorChip = React.forwardRef(
(
{
color,
className,
component,
...rest
}: ColorChipExtraProps & Omit<ChipProps<typeof component>, 'color'>,
ref,
) => {
const classes = useStyles({color});
return (
<Chip
ref={ref}
component={component}
className={classNames(classes.chip, className)}
{...rest}
/>
);
},
);
export default ColorChip;