I have a customized MUI component that displays a circular badge in green.
const StyledGreenBadge = styled(Badge)(({ theme }) => ({
'& .MuiBadge-badge': {
backgroundColor: '#44b700',
color: '#44b700',
width: '15px',
height: '15px',
borderRadius: '100%',
boxShadow: `0 0 0 2px ${theme.palette.background.paper}`,
'&::after': {
position: 'absolute',
top: 0,
left: 0,
width: '100%',
height: '100%',
borderRadius: '50%',
animation: 'ripple 1.2s infinite ease-in-out',
border: '1px solid currentColor',
content: '""',
},
},
'@keyframes ripple': {
'0%': {
transform: 'scale(.8)',
opacity: 1,
},
'100%': {
transform: 'scale(2.4)',
opacity: 0,
},
},
}));
Now, I am looking to refactor my code to avoid repetition by creating a StyledYellowBadge.
All I want to do is change the color
property of StyledGreenBadge dynamically.
However, after spending several hours attempting various methods, I still couldn't find a solution.
I attempted something like this:
color: { desiredColor === 'yellow' ? 'yellow' : #44b700'},
where desiredColor comes as a second argument after
{ theme }
Can someone guide me on how to accomplish this?