-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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
[Theme] Improve the current approach #3340
[Theme] Improve the current approach #3340
Conversation
@@ -6,16 +6,27 @@ import getMuiTheme from './styles/getMuiTheme'; | |||
import ContextPure from './mixins/context-pure'; | |||
import StyleResizable from './mixins/style-resizable'; | |||
|
|||
export function getStylesTheme(muiTheme) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think getThemeStyles
makes more sense.
I really like that idea. 👍 👍 I also have one concern. we should tell people that the values for each component will no longer be available on the theme object. If they relied on this. This can be pretty breaking on so many levels. And we never told people not to touch the theme. I guess this will piss some people off. But it's a must 😁 |
That's a very good point. |
This will be hard to memoize though -_- I'll try to come up with something. |
I like this, I think it's much simpler and what I was hoping to achieve with #2509.
I like putting these functions with the component. Out of curiosity, would components have to call this function themselves or would they get the result passed to them somehow?
Any way we can auto document customizations would be absolutely beautiful and is a must for this project in my opinion 😍 A few questions:
|
Me too 😍
I'm working on a way these can be passed down as themeStyles that can also be fed into the selectors ( of memoization that I'm working on) to maximize performance 🐎
They just provide a key on the theme object when calling getMuiTheme(...). see here Like:
Is that even possible? O.o maybe property getters? but only es5.1 and higher have them -_- |
Yeah that's my point, I don't think it is right now which sucks! ES proxies would be nice but I don't know if there's enough support for it. Unless we just pass the theme through some kind of validating function first in development to check for deprecations. Not sure. |
Hmmm interesting... I like that idea 👍 Like how |
@oliviertassinari Let's get this into the alpha before we document the current approach. We shouldn't do any documentation on the previous way if this is to be accepted ( in my book this is awesome 😍 ) Take a look at my comment. If everyone agrees we should merge this and migrate the components under an umbrella issue. |
Hey guys. Honestly, for some reason, I'm still not completely settled and happy with any of the theming approaches we've come up with so far (including my own 😆). That being said, I think this PR achieves at least the following:
I think this PR represents a step in the right direction and I wouldn't argue if we decided to merge and move forward with this. Note: Don't get me wrong, I like a lot of things about this. I just haven't shaken off that "I feel like we're missing something." feeling yet. |
Same for me. I'm kind of hesitating on merging this PR 😁. What do you think about removing 2. and updating the documentation before merging this PR? |
Ok guys. I think it's not bad to hold off this PR a day or 2 longer. I'll have free time for 2 days. I'll keep working on #3268 and get back to this 👍 |
Guys. What do think if we follow @newoga's approach and move this function into the muiThemeable? that way we'll only have one HOC for these concerns. |
@alitaheri Yeah, I love this idea, that's so simple 😍. It looks like @newoga dreams will become a reality 👍. |
Sounds good 👍 @newoga's approach was the best in my opinion. it only lacked a single Object.assign 😆 😆 |
That's so true. I'm glad that we had started looking for other solutions. We just failed 😁. |
Yeah let's finish this PR and get that one issue resolved! 👍
As long as it's something that we all considered, discussed, implemented, and corrected, I consider it our approach, not mine. 😄 Thanks guys! It sounds like we're getting close, however let's continue to move and evaluate carefully. 👍 |
I have done some aggressive changes to the documentation. That's ready to be reviewed 🎉. |
I'm loving this 😍 😍 I'd say let's go ahead and merge. This is the best approach I can think of. |
I'm good with the changes! 👍 |
[Theme] Improve the current approach
Yeah 🎉 |
Awesome 🎉 😍 |
TL;DR
I have seen two possible options:
MuiThemeProvider
and to make them callgetMuiTheme
from scratch each time they want to change itmuiTheme
. We can still auto document the keys in this case.The conversation started here #3336.
I have done this PR to illustrate how we could address this issue (and can be merged like this).
What we want
But what is this issue? Well, we want multiple things:
Snackbar
to look the same across the all UImuiTheme
on the fly and keeping it immutableMuiThemeProvider
What's hard
The hard part here is that we have a
baseTheme
that is used to computerawTheme
.Then we need to find a way to merge an old
muiTheme
with a new one. How do we know which keys of asnackbar
need to be recomputed from thebaseTheme
and which one the user wants to override?Have a looks at https://github.com/callemall/material-ui/pull/3340/files#diff-3fa66730c1762ffa59a9426f7ab24751R59.
How I'm solving it
The idea is to move the keys for each component out of the
muiTheme
. The first advantage is to make thegetMuiTheme
far simpler. People don't have to know what computations will be applied, all they have to know is how component use those keys. The implementation of thegetMuiTheme
will be as simple as:Then, each component needs a function that built an object of keys that can be customized. For instance with the snackbar:
What is awesome with this, is that we can autodocument the customizations point of the Snackbar by calling
getStylesTheme
withThis solution is backward compatible but will need some migration.
Regarding performances
We will end up with a bit more of CPU cycles used to compute the style.