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
[system] Add new Grid
implementation
#32746
Conversation
@mui/joy: parsed: +2.67% , gzip: +2.84% |
@siriwatknp This sounds like a great idea, but I think that each problem should be solved in its own PR, one step at a time. It will help with the review. |
Sounds good. I can split |
Co-authored-by: Marija Najdova <mnajdova@gmail.com>
Sure 👍 |
@@ -69,7 +69,6 @@ module.exports = { | |||
// Allowing /icons as to reduce cold-start of dev builds significantly. | |||
// There's nothing to tree-shake when importing from /icons this way: | |||
// '@mui/icons-material/*/', | |||
'@mui/system/*', |
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.
Remove this to be able to import @mui/system/Grid
;
Done! |
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.
Generally looks good. Should we prefix it with Unstable_
:)
I think it makes sense when we reexport this new Grid from Material UI but maybe not for System. I am merging this and we can discuss this in a separate PR before the next release. |
The negative margins are still rather ... surprising, and a source of confusion for the unsuspecting user. Is this how it's supposed to work ? https://codesandbox.io/s/laughing-bush-30o2dk?file=/demo.tsx In this example, 5 containers are created (same spacing). Notice how the effect of the (top/bottom) negative margins results in a vertical asymetry in the spacings. Also, it's rather surprising/frustating that two containers with two items each (that fill 12 columns each) do not behave the same as a single container with for items that sum 24 columns. |
If you think this is a bug, please open a new issue. We can discuss further in the issue. |
@siriwatknp one thing that's not clear from the docs: can you mix GridV1 and GridV2 within the same component tree? For example:
|
You should not mix them. |
Preview: https://deploy-preview-32746--material-ui.netlify.app/system/react-grid/
Motivations
Grid
component so we decided to move layout components (container, grid, and stack) to the system package so that they can be reused on both Material UI and Joy UI.Grid
implementation without breaking changes.What's new
Offset feature(next PR)Able to switch between negative margin implementations (works with nested grid)(next PR)sx
prop)item
andzeroMinWidth
props are not needed (they are removed).Implementation approach
Use the
margin/padding
strategy similar tov4
by default.The strategy changes in v5 (margin, padding on top,left sides) aims to fix [Grid] Extra width of container & scrollbar #7466, but it creates more issues (see [Grid] Grid system spacing not creating proper gutters in v5 #31244, [Grid] spacing with full width Items / Layout shift #29266).
Introduce a new flag
disableEqualOverflow
to fix a specific issue about [Grid] Extra width of container & scrollbar #7466. When the flag is true, the negative margin is apply to top and left sides of the grid (similar to the current Grid v5)Simplify the logic by using CSS variables and reduce javascript calculation by using
calc()
gridClasses.item
item
prop (Grid
is always an item that follows flexbox)zeroMinWidth
prop is removed. It works by default.Material UI migration strategy (in a separate PR)
Since the new grid is rewritten, an adoption strategy is required to make sure that it covers all the edge cases. We can mark this new implementation as v6.
Option 1: export a new grid (
GridV6
) from@mui/material
. Developers can test it out per instance like this:Option 2: expose a prop in the existing
Grid
, eg.enableGridV6
. However, I think the option 1 is better because of less bundle size (if you don't use it) and better types inference.We can expose the new grid for 4-6 months and collect feedback, bug fixes. Once we are working on the v6, we can remove the old grid, switch
GridV6
toGrid
and write a code mod to transform:Option 3: export the new
Grid
from@mui/lab
. For theme components type, it will beMuiGridV6
(to not overlap with existing Grid):The usage will be like this: