-
Notifications
You must be signed in to change notification settings - Fork 3
/
LabelChip.tsx
50 lines (48 loc) · 1.52 KB
/
LabelChip.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
import { Chip, Tooltip, alpha, chipClasses, darken } from "@mui/material";
import DoneIcon from "@mui/icons-material/Done";
import { LabelChipProps } from "./LabelChip.types";
import NoWrapTypography from "../../NoWrapTypography";
import React from "react";
// component to display a chip with custom colors
export default function LabelChip({
clickable = false,
color = "#005FA8",
description = "",
label,
onClick,
selected = false,
size = "medium",
variant = "filled",
visible = true,
...props
}: LabelChipProps) {
// return the styled chip component
return (
<Tooltip title={description} placement="bottom-start">
<Chip
{...props}
className="label-chip"
clickable={clickable}
icon={selected ? <DoneIcon color="inherit" /> : undefined}
label={<NoWrapTypography variant="inherit">{label}</NoWrapTypography>}
onClick={clickable ? onClick : undefined}
sx={{
"&:hover": {
backgroundColor: clickable ? darken(color, 0.2) : color
},
backgroundColor: color,
color: theme => theme.palette.getContrastText(color),
[`& .${chipClasses.deleteIcon}`]: {
color: theme => alpha(theme.palette.getContrastText(color), 0.7)
},
[`& .${chipClasses.deleteIcon}:hover`]: {
color: theme => theme.palette.getContrastText(color)
},
visibility: visible ? "visible" : "hidden"
}}
size={size}
variant={variant}
/>
</Tooltip>
);
}