I am trying to set on MUI Chip different opacity for label/icon and background.
My goal is to create Chip with: label & icon opacity = 1, background opacity = 0.0571.
Technologies in project: React, TS, MUI V5, Go.
My code:
export default function InvoiceItem({ data, func }: Props) {
return (
{data.map((invoice, index: number) => (
<Chip
label={capitalizeFirstLetter(invoice.status)}
color={func(invoice.status)}
sx={{
mr: 5,
width: 100,
typography: "h4",
}}
icon={<FiberManualRecordIcon />}
></Chip>
))}
);
}
I have tried already:
1.
<Chip
label={capitalizeFirstLetter(invoice.status)}
color={func(invoice.status)}
opacity= 0.057
sx={{
"& .MuiChip-label": {
opacity: 1},
}}
icon={<FiberManualRecordIcon />}
>
</Chip>
sx={{
"& .MuiChip-root”: {
opacity: 0.0571
},
"& .MuiChip-label": {
opacity: 1
},
}}
2
Answers
This won’t work because the parent element’s opacity affects the child. To achieve this in a different way rather do something like the following:
The RGB values would of course have to match your original color.
You can use the background color with rgba value.
This way you don’t need to define the color for both label and icon. You can also use the "backgroundColor" value with your "func(invoice.status)" but make that function returns rgba value.