here is link of docs of how to customize theme
The above link has Object that we can configure the theme object. But default it take primary-main color, what if i want to access primary-dark . how to access primary dark ?
Make a class that specifies the colour you want and provide the hex colour code as the background colour. (also not ideal). Make a JSX class using makeStyles that takes the app's theme as an argument and provide the primary. light colour directly from your theme.
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 .
If you want to use a custom color, put it in the main property of an object. MUI will use that color to calculate the dark, light and contrastText values besides the main one. dark , light : a darker and lighter versions of the main color. contrastText : the color of the text if the background color is the main color.
Picking colors The Material Design team has also built an awesome palette configuration tool: material.io/resources/color/. This can help you create a color palette for your UI, as well as measure the accessibility level of any color combination.
You could set the dark theme to default like this:
// ... imports ...
const theme = createMuiTheme({
palette: {
type: 'dark',
}
});
ReactDOM.render(
<MuiThemeProvider theme={theme}>
<App />
</MuiThemeProvider>,
document.getElementById('root')
);
For each theme you have primary and secondary colors. For primary e.g. primary.light
, primary.main
and primary.dark
.
In your component, you can access the theme variables like this:
// ... imports ...
const styles = theme => ({
darkColor: {
color: theme.palette.primary.dark // or theme.palette.primary.main
}
})
const StatelessMyComponent = ({ classes }) =>
<div className={classes.darkColor}>Look at my dark color! :)</div>;
export withStyles(styles)(StatelessMyComponent);
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