Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Customizing variant styles through theme file #51

Closed
yTakkar opened this issue Jan 19, 2019 · 4 comments
Closed

Customizing variant styles through theme file #51

yTakkar opened this issue Jan 19, 2019 · 4 comments

Comments

@yTakkar
Copy link

yTakkar commented Jan 19, 2019

Is there any way I can customize variant styles through Material UI's theme file.

You know something like this..

SnackbarItem: {
  variantError: {
    backgroundColor: 'red'
  },
  variantWarning: {
    backgroundColor: 'orange'
  }   
},

Have a good day :)

@yTakkar yTakkar changed the title Customizing variant style through Material theme Customizing variant styles through theme file Jan 19, 2019
@yTakkar yTakkar closed this as completed Jan 24, 2019
@butchmarshall
Copy link
Contributor

butchmarshall commented Feb 12, 2019

I did something like this. I'd like to know if you found a better solution!

const snackbarClasses = Object.keys(classes).filter(key => key.match(/^MuiSnackbarContent_/)).reduce(
    (result, key, index) => {
        result[key.replace(/^MuiSnackbarContent_/, '')] = classes[key];
        return result;
    },
    {}
);
<SnackbarProvider
    classes={snackbarClasses}
/>
const themeStyles = (theme) => {
	const {
		overrides = {}
	} = theme,
	{
		MuiSnackbarContent = {}
	} = overrides;

	return Object.keys(MuiSnackbarContent).reduce(
		(result, key, index) => {
			result["MuiSnackbarContent_"+key] = MuiSnackbarContent[key];

			return result;
		},
		{}
	);
};
export default connect(
	mapStateToProps,
	mapDispatchToProps
)(withStyles(themeStyles)(App));

@xtgrant
Copy link

xtgrant commented May 3, 2019

@yTakkar
Did you ever end up finding a solution? I am currently looking to them my snackbars as well. Would love to hear what you have found out!
Thanks.

@JalDEV
Copy link

JalDEV commented Oct 11, 2019

<ThemeProvider theme={theme}>
  <SnackbarProvider classes={theme.overrides.MuiSnackbarContent} maxSnack={3}>
     {children}
  </SnackbarProvider>
</ThemeProvider>

@JonKrone
Copy link

JonKrone commented Jan 22, 2020

For others looking back at this, there's another approach in your theme.overrides:

overrides: {
    MuiSnackbarContent: {
      root: {
        '&[class*="variantInfo"]': {
          backgroundColor: <Your color here>
        },
        // .. and etc for the other variants
      }
    },
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants