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

[material-ui][mui-system] Stabilize Grid v2 and deprecate Grid v1 #43054

Merged
merged 16 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion benchmark/browser/scenarios/grid-system/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import Grid from '@mui/system/Unstable_Grid';
import Grid from '@mui/system/Grid';

export default function GridSystem() {
return (
Expand Down
4 changes: 4 additions & 0 deletions docs/data/material/components/grid/grid.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ Material Design's responsive UI is based on a 12-column grid layout.
The `Grid` component shouldn't be confused with a data grid; it is closer to a layout grid. For a data grid head to [the `DataGrid` component](/x/react-data-grid/).
:::

:::warning
The `Grid` component has been deprecated. Please use the [Grid v2](/material-ui/react-grid2/) instead. See how to migrate in the [Grid v2 migration guide](/material-ui/migration/migration-grid-v2/) and [Material UI v6 migration guide](/material-ui/migration/migrating-to-v6/).
:::

## How it works

The grid system is implemented with the `Grid` component:
Expand Down
2 changes: 1 addition & 1 deletion docs/data/material/components/grid2/AutoGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react';
import { styled } from '@mui/material/styles';
import Box from '@mui/material/Box';
import Paper from '@mui/material/Paper';
import Grid from '@mui/material/Unstable_Grid2';
import Grid from '@mui/material/Grid2';

const Item = styled(Paper)(({ theme }) => ({
backgroundColor: '#fff',
Expand Down
2 changes: 1 addition & 1 deletion docs/data/material/components/grid2/AutoGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react';
import { styled } from '@mui/material/styles';
import Box from '@mui/material/Box';
import Paper from '@mui/material/Paper';
import Grid from '@mui/material/Unstable_Grid2';
import Grid from '@mui/material/Grid2';

const Item = styled(Paper)(({ theme }) => ({
backgroundColor: '#fff',
Expand Down
2 changes: 1 addition & 1 deletion docs/data/material/components/grid2/BasicGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react';
import { styled } from '@mui/material/styles';
import Box from '@mui/material/Box';
import Paper from '@mui/material/Paper';
import Grid from '@mui/material/Unstable_Grid2';
import Grid from '@mui/material/Grid2';

const Item = styled(Paper)(({ theme }) => ({
backgroundColor: '#fff',
Expand Down
2 changes: 1 addition & 1 deletion docs/data/material/components/grid2/BasicGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react';
import { styled } from '@mui/material/styles';
import Box from '@mui/material/Box';
import Paper from '@mui/material/Paper';
import Grid from '@mui/material/Unstable_Grid2';
import Grid from '@mui/material/Grid2';

const Item = styled(Paper)(({ theme }) => ({
backgroundColor: '#fff',
Expand Down
2 changes: 1 addition & 1 deletion docs/data/material/components/grid2/CenteredElementGrid.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import Avatar from '@mui/material/Avatar';
import Box from '@mui/material/Box';
import Grid from '@mui/material/Unstable_Grid2';
import Grid from '@mui/material/Grid2';

export default function CenteredElementGrid() {
return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import Avatar from '@mui/material/Avatar';
import Box from '@mui/material/Box';
import Grid from '@mui/material/Unstable_Grid2';
import Grid from '@mui/material/Grid2';
Copy link
Member

@siriwatknp siriwatknp Jul 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not related to this PR but I still see deprecated system props used in this demo. I found that there is no Unstable_Grid2 in the list of removeSystemProps codemod, it should be added along with Grid2 to the list.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll open a separate PR for this after we merge this one 👌🏼

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR: #43302


export default function CenteredElementGrid() {
return (
Expand Down
2 changes: 1 addition & 1 deletion docs/data/material/components/grid2/ColumnsGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react';
import { styled } from '@mui/material/styles';
import Box from '@mui/material/Box';
import Paper from '@mui/material/Paper';
import Grid from '@mui/material/Unstable_Grid2';
import Grid from '@mui/material/Grid2';

const Item = styled(Paper)(({ theme }) => ({
backgroundColor: '#fff',
Expand Down
2 changes: 1 addition & 1 deletion docs/data/material/components/grid2/ColumnsGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react';
import { styled } from '@mui/material/styles';
import Box from '@mui/material/Box';
import Paper from '@mui/material/Paper';
import Grid from '@mui/material/Unstable_Grid2';
import Grid from '@mui/material/Grid2';

const Item = styled(Paper)(({ theme }) => ({
backgroundColor: '#fff',
Expand Down
2 changes: 1 addition & 1 deletion docs/data/material/components/grid2/FullBorderedGrid.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import Box from '@mui/material/Box';
import Grid from '@mui/material/Unstable_Grid2';
import Grid from '@mui/material/Grid2';

export default function FullBorderedGrid() {
return (
Expand Down
2 changes: 1 addition & 1 deletion docs/data/material/components/grid2/FullBorderedGrid.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import Box from '@mui/material/Box';
import Grid from '@mui/material/Unstable_Grid2';
import Grid from '@mui/material/Grid2';

export default function FullBorderedGrid() {
return (
Expand Down
2 changes: 1 addition & 1 deletion docs/data/material/components/grid2/FullWidthGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react';
import { styled } from '@mui/material/styles';
import Box from '@mui/material/Box';
import Paper from '@mui/material/Paper';
import Grid from '@mui/material/Unstable_Grid2';
import Grid from '@mui/material/Grid2';

const Item = styled(Paper)(({ theme }) => ({
backgroundColor: '#fff',
Expand Down
2 changes: 1 addition & 1 deletion docs/data/material/components/grid2/FullWidthGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react';
import { styled } from '@mui/material/styles';
import Box from '@mui/material/Box';
import Paper from '@mui/material/Paper';
import Grid from '@mui/material/Unstable_Grid2';
import Grid from '@mui/material/Grid2';

const Item = styled(Paper)(({ theme }) => ({
backgroundColor: '#fff',
Expand Down
2 changes: 1 addition & 1 deletion docs/data/material/components/grid2/HalfBorderedGrid.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import Box from '@mui/material/Box';
import Grid from '@mui/material/Unstable_Grid2';
import Grid from '@mui/material/Grid2';

export default function HalfBorderedGrid() {
const colWidth = { xs: 12, sm: 6, md: 4, lg: 3 };
Expand Down
2 changes: 1 addition & 1 deletion docs/data/material/components/grid2/HalfBorderedGrid.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import Box from '@mui/material/Box';
import Grid from '@mui/material/Unstable_Grid2';
import Grid from '@mui/material/Grid2';

export default function HalfBorderedGrid() {
const colWidth = { xs: 12, sm: 6, md: 4, lg: 3 } as const;
Expand Down
2 changes: 1 addition & 1 deletion docs/data/material/components/grid2/NestedGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react';
import { styled } from '@mui/material/styles';
import Box from '@mui/material/Box';
import Paper from '@mui/material/Paper';
import Grid from '@mui/material/Unstable_Grid2';
import Grid from '@mui/material/Grid2';

const Item = styled(Paper)(({ theme }) => ({
backgroundColor: '#fff',
Expand Down
2 changes: 1 addition & 1 deletion docs/data/material/components/grid2/NestedGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react';
import { styled } from '@mui/material/styles';
import Box from '@mui/material/Box';
import Paper from '@mui/material/Paper';
import Grid from '@mui/material/Unstable_Grid2';
import Grid from '@mui/material/Grid2';

const Item = styled(Paper)(({ theme }) => ({
backgroundColor: '#fff',
Expand Down
2 changes: 1 addition & 1 deletion docs/data/material/components/grid2/NestedGridColumns.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react';
import { styled } from '@mui/material/styles';
import Box from '@mui/material/Box';
import Paper from '@mui/material/Paper';
import Grid from '@mui/material/Unstable_Grid2';
import Grid from '@mui/material/Grid2';

const Item = styled(Paper)(({ theme }) => ({
backgroundColor: '#fff',
Expand Down
2 changes: 1 addition & 1 deletion docs/data/material/components/grid2/NestedGridColumns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react';
import { styled } from '@mui/material/styles';
import Box from '@mui/material/Box';
import Paper from '@mui/material/Paper';
import Grid from '@mui/material/Unstable_Grid2';
import Grid from '@mui/material/Grid2';

const Item = styled(Paper)(({ theme }) => ({
backgroundColor: '#fff',
Expand Down
2 changes: 1 addition & 1 deletion docs/data/material/components/grid2/OffsetGrid.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import { styled } from '@mui/material/styles';
import Paper from '@mui/material/Paper';
import Grid from '@mui/material/Unstable_Grid2';
import Grid from '@mui/material/Grid2';

const Item = styled(Paper)(({ theme }) => ({
backgroundColor: '#fff',
Expand Down
2 changes: 1 addition & 1 deletion docs/data/material/components/grid2/OffsetGrid.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import { styled } from '@mui/material/styles';
import Paper from '@mui/material/Paper';
import Grid from '@mui/material/Unstable_Grid2';
import Grid from '@mui/material/Grid2';

const Item = styled(Paper)(({ theme }) => ({
backgroundColor: '#fff',
Expand Down
2 changes: 1 addition & 1 deletion docs/data/material/components/grid2/ResponsiveGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react';
import { experimentalStyled as styled } from '@mui/material/styles';
import Box from '@mui/material/Box';
import Paper from '@mui/material/Paper';
import Grid from '@mui/material/Unstable_Grid2';
import Grid from '@mui/material/Grid2';

const Item = styled(Paper)(({ theme }) => ({
backgroundColor: '#fff',
Expand Down
2 changes: 1 addition & 1 deletion docs/data/material/components/grid2/ResponsiveGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react';
import { experimentalStyled as styled } from '@mui/material/styles';
import Box from '@mui/material/Box';
import Paper from '@mui/material/Paper';
import Grid from '@mui/material/Unstable_Grid2';
import Grid from '@mui/material/Grid2';

const Item = styled(Paper)(({ theme }) => ({
backgroundColor: '#fff',
Expand Down
2 changes: 1 addition & 1 deletion docs/data/material/components/grid2/RowAndColumnSpacing.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import { styled } from '@mui/material/styles';
import Grid from '@mui/material/Unstable_Grid2';
import Grid from '@mui/material/Grid2';
import Paper from '@mui/material/Paper';
import Box from '@mui/material/Box';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import { styled } from '@mui/material/styles';
import Grid from '@mui/material/Unstable_Grid2';
import Grid from '@mui/material/Grid2';
import Paper from '@mui/material/Paper';
import Box from '@mui/material/Box';

Expand Down
2 changes: 1 addition & 1 deletion docs/data/material/components/grid2/SpacingGrid.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import Box from '@mui/material/Box';
import Grid from '@mui/material/Unstable_Grid2';
import Grid from '@mui/material/Grid2';
import FormLabel from '@mui/material/FormLabel';
import FormControl from '@mui/material/FormControl';
import FormControlLabel from '@mui/material/FormControlLabel';
Expand Down
2 changes: 1 addition & 1 deletion docs/data/material/components/grid2/SpacingGrid.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import Box from '@mui/material/Box';
import Grid from '@mui/material/Unstable_Grid2';
import Grid from '@mui/material/Grid2';
import FormLabel from '@mui/material/FormLabel';
import FormControl from '@mui/material/FormControl';
import FormControlLabel from '@mui/material/FormControlLabel';
Expand Down
2 changes: 1 addition & 1 deletion docs/data/material/components/grid2/VariableWidthGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react';
import { styled } from '@mui/material/styles';
import Box from '@mui/material/Box';
import Paper from '@mui/material/Paper';
import Grid from '@mui/material/Unstable_Grid2';
import Grid from '@mui/material/Grid2';

const Item = styled(Paper)(({ theme }) => ({
backgroundColor: '#fff',
Expand Down
2 changes: 1 addition & 1 deletion docs/data/material/components/grid2/VariableWidthGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react';
import { styled } from '@mui/material/styles';
import Box from '@mui/material/Box';
import Paper from '@mui/material/Paper';
import Grid from '@mui/material/Unstable_Grid2';
import Grid from '@mui/material/Grid2';

const Item = styled(Paper)(({ theme }) => ({
backgroundColor: '#fff',
Expand Down
25 changes: 1 addition & 24 deletions docs/data/material/components/grid2/grid2.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
productId: material-ui
title: React Grid component
components: PigmentGrid
components: PigmentGrid, Grid2
githubLabel: 'component: Grid'
materialDesign: https://m2.material.io/design/layout/understanding-layout.html
---
Expand All @@ -15,29 +15,6 @@ The columns can be configured with multiple breakpoints to specify the column sp

{{"component": "@mui/docs/ComponentLinkHeader", "design": false}}

## What's changed

We built the `Grid` component from scratch in order to:

- Fix [known issues](https://github.com/mui/material-ui/pull/32746) introduced in Material UI v5.
- Simplify the logic with CSS variables, removing the unnecessary `item` prop and reducing CSS specificity.
- Introduce a proper fix for [preventing a scrollbar](#prevent-scrollbar) by switching between negative margin approaches.
- Set negative margins of equal size on all sides of the grid container by default.

Since the new implementation is considered a breaking change, we introduced it as `Unstable_Grid2` to gather feedbacks from the community before making it stable in the next major release of Material UI.

We encourage everyone to try the new version of the `Grid` by visiting the [Grid v2 migration guide](/material-ui/migration/migration-grid-v2/).

:::info
From now on, the `Grid` v1 and `Grid` v2 refer to the import as:

```js
import Grid from '@mui/material/Grid'; // Grid version 1
import Grid from '@mui/material/Unstable_Grid2'; // Grid version 2
```

:::

## How it works

The grid system is implemented with the `Grid` component:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import Grid from '@mui/material/Unstable_Grid2';
import Grid from '@mui/material/Grid2';
import Box from '@mui/material/Box';
import Stack from '@mui/material/Stack';
import Typography from '@mui/material/Typography';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import Grid from '@mui/material/Unstable_Grid2';
import Grid from '@mui/material/Grid2';
import Box from '@mui/material/Box';
import Stack from '@mui/material/Stack';
import Typography from '@mui/material/Typography';
Expand Down
20 changes: 19 additions & 1 deletion docs/data/material/migration/migrating-to-v6/migrating-to-v6.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,27 @@ The `children` passed to the Loading Button component is now wrapped in a `<span

### Grid v2 (Unstable_Grid)

The `Grid` v2 component was updated to match the API of the new `PigmentGrid` component, to allow interoperability between the two:
The `Grid` v2 component was stabilized and updated to match the API of the new `PigmentGrid` component, to allow interoperability between the two:

- The previous size and offset props were replaced with the `size` and `offset` props
- The spacing mechanism was reworked to use the `gap` CSS property.

This brings some breaking changes described in the following sections.

#### Stabilized API

The `Grid` v2 component API was stabilized, so its import no longer contains the `Unstable_` prefix:

```diff
- import { Unstable_Grid2 as Grid2 } from '@mui/material';
+ import { Grid2 } from '@mui/material';
Comment on lines +182 to +183
Copy link
Member

@oliviertassinari oliviertassinari Aug 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra line break

Suggested change
- import { Unstable_Grid2 as Grid2 } from '@mui/material';
+ import { Grid2 } from '@mui/material';
-import { Unstable_Grid2 as Grid2 } from '@mui/material';
+import { Grid2 } from '@mui/material';

Handled in: #43021

```

```diff
- import Grid from '@mui/material/Unstable_Grid2';
+ import Grid from '@mui/material/Grid2';
```

#### Size and offset props

Previously, the size and offset props were named corresponding to the theme's breakpoints.
Expand Down Expand Up @@ -215,6 +229,10 @@ Use this codemod to migrate your project to the new size and offset props:
npx @mui/codemod@next v6.0.0/grid-v2-props <path/to/folder>
```

:::warning
You need to modify the import from `@mui/material/Unstable_Grid2` to `@mui/material/Grid2` before running the codemod.
:::

If you have custom breakpoints, the change is the same:

```diff
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import Box from '@mui/material/Box';
import Grid2 from '@mui/material/Unstable_Grid2';
import Grid2 from '@mui/material/Grid2';
import Typography from '@mui/material/Typography';

export default function GridDisableEqualOverflow() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import Box from '@mui/material/Box';
import Grid from '@mui/material/Grid';
import Grid2 from '@mui/material/Unstable_Grid2';
import Grid2 from '@mui/material/Grid2';
import Typography from '@mui/material/Typography';

export default function GridsDiff() {
Expand Down
Loading
Loading