Skip to content

Commit

Permalink
[material-ui][mui-system] Stabilize Grid v2 and deprecate Grid v1 (#4…
Browse files Browse the repository at this point in the history
  • Loading branch information
DiegoAndai authored Jul 30, 2024
1 parent f160039 commit 08dce48
Show file tree
Hide file tree
Showing 153 changed files with 608 additions and 295 deletions.
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';

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
22 changes: 20 additions & 2 deletions docs/data/material/migration/migrating-to-v6/migrating-to-v6.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,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 `Grid2` was updated and stabilized:

- The previous size and offset props were replaced with the `size` and `offset` props
- The previous size (`xs`, `sm`, `md`, ...) and offset (`xsOffset`, `smOffset`, `mdOffset`, ...) props, which were named after the theme's breakpoints, 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 `Grid2` 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';
```

```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 @@ -239,6 +253,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

This file was deleted.

Loading

0 comments on commit 08dce48

Please sign in to comment.