-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
[Core] There should be a more sophisticated styling solution #4066
Comments
Some further questions: |
@chrismcv My personal opinion is that we definitely need to leverage the solution to remove these super specific props we're seeing proposed: [TextField] add floatingLabelFocusStyle prop #4043 Before we know it, people are going to be asking for props for subcomponent styles for every possible focus/active/hover/whatever state. I see so many issues that are "how to style XXXX", "can't style XXX inside YYYY", "add |
@chrismcv in 6. regarding the more general |
@chrismcv I think that |
@nathanmarks Thanks for bootstrapping the conversation. That's definitely one of the major issues we need to address for the next releases 💯 .
For me, that's one of the main concern I have with the solution we will choose. |
I am playing around with a couple of the JS style solutions at the moment. It's interesting but clear that it is still "early days" so to speak. One thing I was thinking -- outside of dynamic style properties (for eg, if the component has a It seems as though with the JS style libs, to get maximum performance you should use their Even though the stylesheet selectors get cached in the sense that they are written only once to the DOM (and in some libs only written to the DOM when needed for the |
Hmmm... I left a comment here yesterday (Sunday). Did it get deleted? |
@rvbyron I remember it clearly. I certainly didn't delete it though. |
@rvbyron I do remember it too. I have no idea what happened. |
@rvbyron - had it in my email, so back here in quoted form!
|
@chrismcv Thanks dude! I think that what @rvbyron has to say is important because in some ways, JS styling is very much a paradigm shift from regular CSS. Most people are not using JS styling in their day job and it requires a different way of thinking + makes it harder for designers who may usually contribute to projects that aren't so proficient in JS. It's important to consider all the angles here. One thing I realised about Hijacking the Thoughts? |
Thanks for finding the email and placing it into the commentary! |
Best of both worlds behavior approach?What about a "behavior" concept of importing the styling technique that best suits your needs. An import of "StyleTheme" or "ClassTheme" could be used to select the behavior. StyleTheme could refer to the muiTheme object material-ui has today and make the component centric styling developers happy. Or, ClassTheme that would use an SCSS file that is built from the muiTheme.js object (synced) making the CSS centric developers happy. That would mean that all components would then need to accommodate {...theme.ComponentName} in the render elements. To offer a very simplified example, a RoundButton component would have the render method like:
For the StyleTheme behavior, theme.RoundButton would contain:
For the ClassTheme behavior, theme.RoundButton would contain:
A combination of the two could be retrieved as ClassStyleTheme behavior, theme.RoundButton would contain both:
The mui-theme.scss file would be generated from the muiTheme.js file and reflect in SCSS the exact properties the JS file contains. The camel casing of the JS names would be converted to more standard class names:
Any CSS customization to the MUI components would simply be identical classes loaded after the mui-theme.scss file was loaded, thereby overriding the mui-theme properties. |
I think that using something like My main problem with the JS styling situation is it feels like all of the solutions are still a work in progress. There are not a lot of real world performance evaluations out there to look at, the libs we are looking at are unproven and I feel as though we are spending a lot of our time trying to figure out how to do styles in JS properly. The main goal of this lib is to implement the material design spec and I can't help but feel that this is hamstringing us at the moment. (we def need to sort the perf impact issues) |
I think we have different concerns regarding this.
All seem good when you're writing an application, no one outside your code needs to change anything. But with libraries things are different, all the above concerns are there, plus the following:
What we have right now somehow handles all those concerns with these caveats:
If we change our styling approach we'll have to do it all over again. If it comes to that we should be sure to answer all those before starting migration. In my humble opinion, I think CSS and what ever that compiles to it are not parts of the future. I think we all agree that inline-styles made our lives a lot easier. Honestly, the only limitation I see with inline-styles is We can solve those issues with doing a bit of design.
My point is, we already address a huge number of concerns with our current styling approach. It has limitations because we don't follow all the patterns around inline-styles. if we start breaking down our components and make them a lot more composable then we don't really have to worry about anything. take So instead of changing our approach and solving all these issues again let's invest the time improving what we already have. we don't need to support media queries, we can change our components in a way that's easy for others to implement responsiveness upon them. Hard to debug? if we break down our components then the inlined styles will be smaller and easier to read. debatable though! I mean all you need is a break point to see what participates in That's of course my own opinion I'm very open to discussion. |
You raise some great points. Thanks. I'm wondering if some sort of hybrid solution is a possibility. Seems that no matter what angle we take there are a bunch of issues 😆 I have time to work on this next week -- let's have a chat and see if we can come up with a clever idea. I agree with trying to minimize the amount of change and having to re-solve already solved issues. There's 2 important goals here in my mind:
Need to think about this more 😄 but as long as we manage to solve those 2 points I'll be happy with our solution. |
Another random note -- it would be great if we had an automated way to enforce certain code conventions and design patterns for inline/jsstyle/whatever across the lib. |
@nathanmarks I'm not 100% opposed to use SCSS (I'm using it at work). But from my point of view, it's a dead-end. I completely agree with @alitaheri. We could start with those two steps:
|
@oliviertassinari I agree with the dead-end conclusion -- it's not the future. I brought it up largely to stimulate the conversation about how to make JS styles work for us. I knew some people around here had some good ideas surrounding the issues 😄 Wish FB were a tiny bit further along with their experiments! I actually think the Next week I'm on vacation and I'm going to experiment with a solution to our current problems while keeping all styles JS based. |
Just read this post on Lessons Learned At React Amsterdam (https://medium.com/@kitze/lessons-learned-at-react-amsterdam-51f2006c4a59#.o12h794or) and one of presentations was about solutions for styling in React: http://slides.com/kof/javascript-style-sheets#/ A timely presentation for this discussion. |
One requirement that I keep thinking about and that I haven't seen explicitly stated (at least that I recall) is the need to support web-only vs. web and react native. If the intent is web-only (i.e. react native isn't a requirement) then solutions that leverage what browsers already efficiently and robustly support and people are very familiar would be a good thing. If supporting react native is a must then that opens up a different set of needs & requirements. Just something to think about and keep in mind as the technology choices, compromises, etc. are evaluated. |
Thanks for sharing that presentation! We may want to look at the lib mentioned in that presentation (here's a demo). It could save us a lot of work. I was looking at it previously but there were a few things I didn't like (such as the requirement of wrapping every single component in a proprietary HoC). However, there is some discussion about some of that happening here . He mentions that implementing changes like this would allow for HoC-free use. I do prefer that method/design for the sheet writing (also seen in Alternatively, we could always create our own react bindings for The lib author also said this, which falls in line with my own thoughts on the matter 👍 :
|
@nathanmarks The implementation is rather very small and very easy to mixout 😁 |
For myself, I appreciate the way Material-UI does the styling as opposed to something like react-toolbox, and here's why: In one of our projects, we have the ability for the user to select dynamic themes: Because the user might select a color pair we cannot determine ahead of time, whatever theming scheme we use must be highly dynamic. With , changes to the theme can happen live, b/c all the styles are generated inline: all I have to do is give it primary/accent colors. In react-toolbox et. al., this seems to be more of a chore from what I can see. |
@jrop yeah in this very special case you need dynamic JSS but for many applications that's not an important requirement and the current story of customizing (not even speaking about UI testing) material-ui is simply not acceptable. We are building a highly visual and designed app that cannot just use the default material-ui look, as we mostly need/want the behavior parts of it. |
@DominikGuzei you can customize Folks, I feel like we are beating a dead horse here. The @nathanmarks, since this decision has been made (as far as I can tell, and works quite well 👍 ), I suggest you write a summary and close/lock this issue so those that find it understand the way forward. |
@fgarcia I have given a presentation at a local event in Paris earlier this week regarding the evolution of the styling approach used by Material-UI. You might be interested having a look at the slides and the notes: A Journey toward better style. I focus on the Challenges, Problems and Solutions.
The static style generation aspect of CSS-Modules has quite some consequences.
|
@oliviertassinari That is awesome to hear. I may have a non-standard point-of-view regarding CSS modules, but I don't think they are worth all the fuss. I was excited to hear of JSS through material-ui for this reason. It seems much more inline with the philosophy of JavaScript than CSS modules. |
@oliviertassinari thanks for the summary of benefits. It's definitely interesting when you look at these aspects. The downside of JSS and it's ecosystem (also postcss) at the moment is that all that is bleeding edge and you cannot rely on the well established tool chain and knowledge base like with simple css-modules + SASS. But that's the price you pay for innovation, it just depends if you have certain requirements / are willing to pay the price of bugs and the less documented path. |
JSS has been created prior to css-modules. CSS-modules has become popular faster because it solved a problem for a majority users without changing the syntax too radically. |
That being said, you are using react, which is also kinda "new" technology. If you want SASS, maybe you should also pick vanilajs or backbonejs) |
@kof React is a very different story as it is used by hundreds of thousands of devs and is managed by Facebook (it won't go away over night), so it might be "new" but very solid (haven't run into many issues with it so far). SASS is one of the most established css preprocessor and can be used in any project – it's very solid and brings a lot of value to the table. So i would only choose something like JSS if absolutely necessary (e.g: because of dynamic themes) but dislike to throw out years of experience / frameworks / knowledge base etc. in a commercial software project with several devs. So i would even consider building only the dynamic theme aspect in JSS and the rest with sass / css-modules. |
I understand this way of thinking, but also I consider it as contra-productive and blame it for slowing down innovation and the industry. |
Why u just don't support both? Styles written in JavaScript AND styles written in css-modules? If i have a look at https://github.com/callemall/material-ui/blob/next/src/Button/Button.js for example, it would be quite easy to use class-names passed in by a prop (https://github.com/javivelasco/react-css-themr) instead of using:
Isn't it? It doesn't look like the discussion about using JSS or CSS is finding an end (yet?). To me it looks like a fifty/fifty thing at the moment. |
Regarding SASS, react-toolbox are currently migrating away from it in favor of a full postCSS solution, I personally think postCSS (with sassLike plugins) is a better pick, more powerful without build deps. |
Styling in all JS, and in React in particular, is obviously still in a rapid state of evolution. So whatever you do, I'd try to avoid being opinionated - just fit well with with a broad set of current usage. Consider just adding a *className prop wherever there's a *style prop. Period. Full disclosure: I'm a happy Aphrodite user. |
Adding a |
@ligaz Of course, you're right. Aphrodite adds |
@ligaz @estaub - The styling paradigm setup on the This horse is dead. Let's stop beating it. @oliviertassinari I suggest you close and lock this issue with a statement of direction on |
Hi @rosskevin - can you point me at any examples at all of how this is working in next? I'm currently looking at frameworks for a new project, I'd love to use Material UI but we'd need the changes that you've mentioned are in next. I've added the next branch to a test project and added a simple component and I'm seeing an inspector full of inline styles, so I'm guessing I'm doing something wrong? Any further details would be really helpful! Thanks |
@giuseppepaul I am publishing my own private version of next (so I can control the updates) and am using this in a soon to be production application. |
That horse isn't fully dead. But definitely in a tight spot 🔫 . A big thanks to @nathanmarks for his hard work on that story 👏 ! |
Hello, |
@NitroBAY This thread is over. Please ask you question on the right channel.if you notice a bug or want the documentation to be improved, open an issue. Otherwise you can use StackOverflow of gitter.im. |
@callemall/material-ui please leave some input here when you can 👍
We need to decide on a styling solution for
0.16.0
that will help address long standing issues. Outside of performance issues, there are hacks and props all over the place to make up for the fact that we are missing out on some of the powerful features in CSS that cannot be used with inline styles -- pseudo classes, media queries (without matchmedia), etc.From what I understand, the general consensus is that we want a JS style solution that has the capability to write styles to an actual stylesheet in the DOM.
Here are a few of the maintained solutions that do this:
https://github.com/rofrischmann/react-look
https://github.com/Khan/aphrodite
https://github.com/jsstyles/react-jss
Here are some points we need to consider when implementing the new solution (IMO):
If using a library as large asI realized that 9kb of that is https://github.com/rofrischmann/inline-style-prefixer which we already use... 😄react-look
, try and see how we can import modules for a minimal build size. The full build size is 16kb gzipped which is fairly large. It would be great if we can minimize the impact on build size.The text was updated successfully, but these errors were encountered: