withStyles

Last updated
Was this helpful?
Was this helpful?
function MyComponent(props: { className?: string; colorSmall: string }) {
return (
<div className={props.className}>
The background color should be different when the screen is small.
</div>
);
}
const MyComponentStyled = withStyles(
MyComponent,
(theme, props) => ({
"root": {
"backgroundColor": theme.palette.primary.main,
"height": 100
},
"@media (max-width: 960px)": {
"root": {
"backgroundColor": props.colorSmall
}
}
})
);import Button from "@mui/material/Button";
const MyStyledButton = withStyles(Button, {
"root": {
"backgroundColor": "grey"
}
"text": {
"color": "red"
},
"@media (max-width: 960px)": {
"text": {
"color": "blue"
}
}
});const MyAnchorStyled = withStyles("a", (theme, { href }) => ({
"root": {
"border": "1px solid black",
"backgroundColor": href?.startsWith("https")
? theme.palette.primary.main
: "red"
}
}));