Assuming I am using a Material-UI palette as follows:
palette: {
primary: {
main: "#039be5",
light: "#63ccff",
dark: "#C218006db35B",
contrastText: "#fafafa"
},
secondary: {
main: "#f50057",
light: "#ff5983",
dark: "#bb002f",
contrastText: "#f9fbe7"
},
error: {
main: "#f50057",
light: "#ff5983",
dark: "#bb002f",
contrastText: "#f9fbe7"
}
},
And let's say that I am using a number of Material-UI components such as the <AppBar />
, <Button />
, etc. and each of them I want to give them different accents of the primary palette object - ex. <AppBar />
will be primary.main
and <Button />
will be primary.light
.
How can I do it?
Using something like <AppBar position="static" color="primary.light">
does not work, and throws an error.
const theme = createMuiTheme({ palette: { primary: { main: "#ff8f00" // This is an orange looking color }, secondary: { main: "#ffcc80" //Another orange-ish color } },fontFamily: font // as an aside, highly recommend importing roboto font for Material UI projects!
Adding <CssBaseline /> inside of the <ThemeProvider> component will also enable dark mode for the app's background. Note: setting the dark mode this way only works if you are using the default palette. If you have a custom palette, make sure that you have the correct values based on the mode .
primary - used to represent primary interface elements for a user. It's the color displayed most frequently across your app's screens and components. secondary - used to represent secondary interface elements for a user. It provides more ways to accent and distinguish your product.
Unfortunately the docs are unclear. Here is the only hacky work-around I found:
<AppBar position="static" className="primaryLight">
const styles = theme => ({
primaryLight: {
backgroundColor: theme.palette.primary.light
}
}
This library is convoluted... at least it's consistent with React!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With