I have found a number of posts regarding overriding styles but nothing quite like the issue I am having. I am creating styled material-ui components and importing them into different parts of my application. I want to be able to override some of my styling from the various parent components.
I have a button component:
import React from "react";
import { makeStyles } from "@material-ui/styles";
const useStyles = makeStyles({
buttonBlue: {
background: "#09a1e2",
border: "1px solid #09a1e2",
borderRadius: "5px",
color: "#ffffff",
cursor: "pointer",
fontSize: "1.25rem",
padding: ".75rem 1.25rem .75rem 1.25rem",
"&:hover": {
backgroundColor: "#ffffff",
color: "#09a1e2"
}
},
buttonWhite: {
background: "#ffffff",
border: "1px solid #666666",
borderRadius: "5px",
cursor: "pointer",
fontSize: "1rem",
padding: ".5rem",
width: "6rem",
"&:hover": {
backgroundColor: "#666666",
color: "#ffffff"
}
}
});
const MediumButton = props => {
const color = props.color;
const classes = useStyles();
return (
<div>
{color === "blue" ? (
<button className={classes.buttonBlue}>{props.buttonText}</button>
) : (
<button className={classes.buttonWhite}>{props.buttonText}</button>
)}
</div>
);
};
export default MediumButton;
which I will be importing into another component. I want to override some of these styles on my new component but I can't quite figure out how.
Here is what I am trying:
import React from "react";
import { makeStyles } from "@material-ui/core/styles";
import { withContext } from "../../context/AppContext";
import MediumButton from "../components/MediumButton";
const useStyles = makeStyles({
root : {
display: "flex",
},
homeButton: {
background: "white",
border: "1px solid #09a1e2",
borderRadius: "5px",
color: "#09a1e2",
cursor: "pointer",
fontSize: "1.25rem",
padding: ".5rem 3.25rem .5rem 3.25rem",
textDecoration: 'none',
"&:hover": {
backgroundColor: "#ffffff",
color: "#09a1e2"
}
}
});
const PageNotFound = () => {
const classes = useStyles();
return (
<div className={classes.root}>
<MediumButton className={classes.homeButton} />
</div>
);
};
export default withContext(PageNotFound);
I'm not sure what I need to call to override the styles I set on my MediumButton component.