Skip to content
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

Merged
merged 68 commits into from Jul 7, 2022
Merged

Conversation

siriwatknp
Copy link
Member

@siriwatknp siriwatknp commented May 12, 2022

Preview: https://deploy-preview-32746--material-ui.netlify.app/system/react-grid/

Motivations

What's new

  • Offset feature (next PR)
  • Full support nested grid
  • Able to switch between negative margin implementations (works with nested grid) (next PR)
  • Replace class selector with CSS variables (easier to customize via sx prop)
  • item and zeroMinWidth props are not needed (they are removed).

Implementation approach

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:

// some page
-import Grid from '@mui/material/Grid';
+import Grid from '@mui/material/GridV6';

<Grid container spacing={2}>
  <Grid
-   item
     md={6}
  > ... </Grid>
  ...
</Grid>

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 to Grid and write a code mod to transform:

-import GridV6 from '@mui/material/GridV6';
+import Grid from '@mui/material/Grid';

Option 3: export the new Grid from @mui/lab. For theme components type, it will be MuiGridV6 (to not overlap with existing Grid):

export interface LabComponents {
  // ...
  MuiGridV6?: {
    defaultProps?: ComponentsProps['MuiGridV6'];
    styleOverrides?: ComponentsOverrides<Theme>['MuiGridV6'];
    variants?: ComponentsVariants['MuiGridV6'];
  };
}

The usage will be like this:

import Grid from '@mui/lab/Grid';

@siriwatknp siriwatknp added component: Grid The React component. package: system Specific to @mui/system labels May 12, 2022
@mui-bot
Copy link

mui-bot commented May 12, 2022

Details of bundle changes

@mui/joy: parsed: +2.67% , gzip: +2.84%

Generated by 🚫 dangerJS against 906db8e

@siriwatknp siriwatknp marked this pull request as ready for review June 20, 2022 10:54
@oliviertassinari
Copy link
Member

oliviertassinari commented Jun 20, 2022

We would like to use this opportunity to fix the existing issues with the Grid implementation without breaking changes

@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.

docs/data/system/components/grid/ResponsiveGrid.tsx Outdated Show resolved Hide resolved
docs/data/system/components/grid/VariableWidthGrid.tsx Outdated Show resolved Hide resolved
docs/data/system/components/grid/grid.md Outdated Show resolved Hide resolved
docs/data/system/components/grid/grid.md Show resolved Hide resolved
docs/data/system/components/grid/grid.md Outdated Show resolved Hide resolved
packages/mui-joy/src/Grid/Grid.tsx Show resolved Hide resolved
@siriwatknp
Copy link
Member Author

We would like to use this opportunity to fix the existing issues with the Grid implementation without breaking changes

@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 offset feature and negative margin switching into separate PRs. cc @mnajdova What do you think?

@siriwatknp siriwatknp requested a review from mnajdova June 21, 2022 12:19
@mnajdova
Copy link
Member

mnajdova commented Jul 1, 2022

Sounds good. I can split offset feature and negative margin switching into separate PRs. cc @mnajdova What do you think?

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/*',
Copy link
Member Author

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;

@siriwatknp
Copy link
Member Author

Sounds good. I can split offset feature and negative margin switching into separate PRs. cc @mnajdova What do you think?

Sure 👍

Done! offset and disableEqualOverflow are removed.

Copy link
Member

@mnajdova mnajdova left a 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_ :)

@siriwatknp
Copy link
Member Author

siriwatknp commented Jul 7, 2022

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.

@siriwatknp siriwatknp merged commit dcb9db3 into mui:master Jul 7, 2022
@leonbloy
Copy link

leonbloy commented Sep 8, 2022

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.

@siriwatknp
Copy link
Member Author

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.

@oliviertassinari oliviertassinari added the new feature New feature or request label Nov 12, 2022
daniel-rabe pushed a commit to daniel-rabe/material-ui that referenced this pull request Nov 29, 2022
@mattste
Copy link

mattste commented Mar 27, 2024

@siriwatknp one thing that's not clear from the docs: can you mix GridV1 and GridV2 within the same component tree?

For example:

<GridV2 container>
  <GridV1 item></GridV1>
 <GridV1 item></GridV1>
</GridV2>

@siriwatknp
Copy link
Member Author

@siriwatknp one thing that's not clear from the docs: can you mix GridV1 and GridV2 within the same component tree?

For example:

<GridV2 container>
  <GridV1 item></GridV1>
 <GridV1 item></GridV1>
</GridV2>

You should not mix them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: Grid The React component. new feature New feature or request package: system Specific to @mui/system
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Grid] Extra width of container & scrollbar
7 participants