-
-
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
[Box] Atomic CSS classes #15499
Comments
@Elfayer It's an excellent question. The current answer in v4 is to use the Box component: https://next.material-ui.com/utils/box/. Did you know about this existence? I have written a blog post about it.
We have a second helper when writing custom CSS: https://next.material-ui.com/customization/themes/#spacing. Does it help? Do you still prefer the global class name approach? We could consider generating them 🤔. |
I've seen the Box component, but since it's in alpha, I was expecting another approach to manage spacing in v3. So I guess I'll go for the Box approach. 😉 Material-UI makes me think of Vue's most popular library: Vuetify. It looks very similar to MUI, being material design and also the most popular in its own stack. They made the choice to use atomic classes instead though. If I understand correctly, in MUI, the styles objects (from I also wonder if the Box syntax approach might not be a bit verbose. It's going to add 2 lines in the templating each time we need styling, and adds an extra wrapping element on the output (default to Maybe I'm misunderstanding the whole thing. I like to learn new approaches and will definitely dig more into it. Thanks for the first feedbacks! 😃 |
@Elfayer I'm chatting from time to time with John from Vuetify. I closely follow what he's doing. I try to bring the good stuff in Material-UI. The main advantage of the Box approach is that the values are dynamic and can be accessed from the theme. <Box p={[1, 2]} color="success.main" />
You are right, it's slower than using pre-generated CSS values. If people start to notice slowness in their application, we should be able to work on them. I wouldn't worry too much about it. One of the possible approaches is to generate atomic class names, e.g. https://github.com/segmentio/ui-box.
The <Button m={1} /> What's the most important dimension for you? |
I had a similar thought recently. The more I think of the atomic CSS approach for the Box component, the more I like it. |
An exploration we have done in this direction: mnajdova#3 with @mnajdova. |
Closing for #21657. It's a performance concern. |
My question is based on the often used classes for Spacing for Margin and Padding such as:
m-0
:margin: 0;
pb-1
:padding-bottom: 0.25rem;
Is there anything similar in MUI? I've seen the System (alpha), is this the way to go?
What is the right way to handle Spacing in MUI v3?
I've noticed that most (all?) examples are based on
useStyles
. But it seems like it is creating new classes each time it is used. If I am right, I wouldn't think of it as a good go, as it'll make the project's CSS scale up over time while adding more style, as opposed to atomic CSS approach (as in TailwindCSS).Any suggestion for managing Spacing(Margin & Padding) in MUI?
The text was updated successfully, but these errors were encountered: