Closed mightym closed 3 months ago
@mightym I did not understand your issue. Could you provide a minimal reproduction? It helps us troubleshoot. A live example would be perfect. This StackBlitz sandbox template may be a good starting point.
hey @ZeeshanTamboli thanks for your reply!
Well this is less a technical question, more a conceptual question how to handle complex themes in MUI.
I try to rephrase in a single line:
What would you do if 2 different components A & B rely on primary
for the background color in your light theme but on the dark theme the background color for A is still primary
but on B its a slight variation of primary
?
What would you do if 2 different components A & B rely on
primary
for the background color in your light theme but on the dark theme the background color for A is stillprimary
but on B its a slight variation ofprimary
?
I would use theme.palette.mode
to check for dark mode and apply the slight variation of primary
which you have defined in your custom theme. I really don't understand your issue.
@ZeeshanTamboli see and thats why you will end up with something extremely complex like in my code example. Because in your approach you will end up with a lot of conditions based on the current theme. What you need is an intermediate level like my theme styles. But for sure you could write conditions in you components.
What you need is an intermediate level like my theme styles
Okay, so what's the problem with it? What issue is it causing? I see that you are saying the following:
But this has some downsides. Eg. using the color palette properties on components wouldn't reflect my theme anymore. And many others.
But I can't check with a reproduction. It would be better if you can provide a reproduction.
Since the issue is missing key information and has been inactive for 7 days, it has been automatically closed. If you wish to see the issue reopened, please provide the missing information.
Summary
I've been using MUI lately on a larger project. Compared to building a custom UI Lib from scratch it had tons of advantages. With one downside: the color palette of the project was so versatile that I couldn't handle most parts of it with MUI's theme approach.
Examples
An exaggerated example to explain the issue:
We had a
primary
colorred
that is used as a background color for button variants on our light theme. On our dark theme theprimary
color isblue
. But not all buttons should have a 1:1 theblue
color. They needed to have others shades or sometimes even different colors.We had this issue in so many places that I basically ended up creating themes where I defined the colors for every component like this:
Which I injected into the theme and then used in my component overrides like this:
But this has some downsides. Eg. using the color palette properties on components wouldn't reflect my theme anymore. And many others.
Motivation
My motivation is to find out are there any plans/considerations that something like this might also be handled with MUI? Or did you encounter similar issues in the past? Maybe there is another better way how this can be solved.
Search keywords: theme complex palette