Skip to content

Commit 4018ee2

Browse files
kyledurandjjgali
andauthored
[Layout foundations] Deprecate grid component (#8418)
Closes: #7741 --------- Co-authored-by: jjgali <77791660+jjgali@users.noreply.github.com>
1 parent 4799b65 commit 4018ee2

File tree

11 files changed

+1449
-1425
lines changed

11 files changed

+1449
-1425
lines changed

.changeset/stale-maps-ring.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@shopify/polaris': minor
3+
'polaris.shopify.com': patch
4+
---
5+
6+
Deprecated Grid component
7+
Update documentation for deprecated components

polaris-react/src/components/Grid/Grid.tsx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import React from 'react';
1+
import React, {useEffect} from 'react';
22

3+
// eslint-disable-next-line import/no-deprecated
34
import {Cell} from './components';
45
import styles from './Grid.scss';
56

@@ -26,12 +27,9 @@ export interface GridProps {
2627
gap?: Gap;
2728
children?: React.ReactNode;
2829
}
29-
/** **Experimental!**
30-
* This component is in alpha. Use with caution.
31-
* 6 column default for xs, sm, and md breakpoints.
32-
* 12 columns for lg, and xl.
33-
*/
30+
/** @deprecated Use `Columns` instead or a combination of layout primitives (`Columns`, `Inline`, and `AlphaStack`) */
3431
export const Grid: React.FunctionComponent<GridProps> & {
32+
// eslint-disable-next-line import/no-deprecated
3533
Cell: typeof Cell;
3634
} = function Grid({gap, areas, children, columns}: GridProps) {
3735
const style = {
@@ -52,6 +50,15 @@ export const Grid: React.FunctionComponent<GridProps> & {
5250
'--pc-grid-areas-xl': formatAreas(areas?.xl),
5351
} as React.CSSProperties;
5452

53+
useEffect(() => {
54+
if (process.env.NODE_ENV === 'development') {
55+
// eslint-disable-next-line no-console
56+
console.warn(
57+
'Deprecation: <Grid /> is deprecated. This component will be removed in a future major version of Polaris. Use <Columns /> instead or a combination of <Columns />, <Inline />, and <AlphaStack />',
58+
);
59+
}
60+
}, []);
61+
5562
return (
5663
<div className={styles.Grid} style={style}>
5764
{children}
@@ -64,4 +71,5 @@ export function formatAreas(areas?: string[]) {
6471
return `'${areas?.join(`' '`)}'`;
6572
}
6673

74+
// eslint-disable-next-line import/no-deprecated
6775
Grid.Cell = Cell;

polaris-react/src/components/Grid/components/Cell/Cell.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export interface CellProps {
3030
row?: Cell;
3131
children?: React.ReactNode;
3232
}
33-
33+
/** @deprecated Use `Columns` instead or a combination of layout primitives (`Columns`, `Inline`, and `AlphaStack`) */
3434
export function Cell({
3535
area: gridArea,
3636
column,

polaris-react/src/components/Grid/components/Cell/tests/Cell.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
22
import {mountWithApp} from 'tests/utilities';
33

4+
// eslint-disable-next-line import/no-deprecated
45
import {Cell} from '../Cell';
56

67
describe('<Cell />', () => {

polaris-react/src/components/Grid/tests/Grid.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from 'react';
22
import {matchMedia, timer} from '@shopify/jest-dom-mocks';
33
import {mountWithApp} from 'tests/utilities';
44

5+
// eslint-disable-next-line import/no-deprecated
56
import {formatAreas, Grid} from '../Grid';
67

78
describe('<Grid />', () => {

polaris.shopify.com/content/components/layout-and-structure/grid.md renamed to polaris.shopify.com/content/components/deprecated/grid.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Grid
33
description: Create complex layouts based on [CSS Grid](https://developer.mozilla.org/en-US/docs/Web/CSS/grid).
4-
category: Layout and structure
4+
category: Deprecated
55
keywords:
66
- one column
77
- two column
@@ -14,8 +14,10 @@ keywords:
1414
- full width containers
1515
- css grid
1616
status:
17-
value: Alpha
18-
message: This component is slated to be deprecated in v11. Please consider using alternate layout primitive components such as Columns, Inline, or AlphaStack.
17+
value: Deprecated
18+
message: >-
19+
Grid was built prior to layout primitives like columns, inline, and alpha stack. Comparatively, grid is difficult to learn, document, and understand its usage in a codebase.
20+
The new layout primitives should be used in combination to achieve similar results to grid.
1921
examples:
2022
- fileName: grid-two-column.tsx
2123
title: Two column

polaris.shopify.com/content/components/deprecated/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22
title: Deprecated
33
expanded: true
44
order: 12
5+
description: >-
6+
Deprecated components will be removed in future major versions of Polaris. These components could be deprecated for a [number of reasons](https://polaris.shopify.com/getting-started/components-lifecycle#requirements-for-deprecation) and should be avoided. These components will show warnings in the component file and provide details for alternative usage. For more information, check out the [component lifecycle](https://polaris.shopify.com/getting-started/components-lifecycle#deprecated).
57
---

polaris.shopify.com/next.config.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,11 @@ const deprecated = [
196196
destination: '/components/deprecated/display-text',
197197
permanent: false,
198198
},
199+
{
200+
source: '/components/grid',
201+
destination: '/components/deprecated/grid',
202+
permanent: false,
203+
},
199204
{
200205
source: '/components/heading',
201206
destination: '/components/deprecated/heading',
@@ -360,11 +365,6 @@ const layoutAndStructure = [
360365
destination: '/components/layout-and-structure/form-layout',
361366
permanent: false,
362367
},
363-
{
364-
source: '/components/grid',
365-
destination: '/components/layout-and-structure/grid',
366-
permanent: false,
367-
},
368368
{
369369
source: '/components/inline',
370370
destination: '/components/layout-and-structure/inline',

polaris.shopify.com/pages/components/[group]/index.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,12 @@ export default function GroupPage({
127127
/>
128128
<AlphaStack gap="16">
129129
<AlphaStack gap="4">
130-
<Longform firstParagraphIsLede>
131-
<p>{frontMatter?.description}</p>
132-
</Longform>
130+
{frontMatter?.description && (
131+
<Longform firstParagraphIsLede>
132+
<Markdown>{frontMatter?.description}</Markdown>
133+
</Longform>
134+
)}
135+
133136
{groupsMarkup || componentsFromPaths}
134137
</AlphaStack>
135138
{relatedResourcesMarkup}

0 commit comments

Comments
 (0)