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

[Layout foundations] Update Columns component docs and guidance #7527

Merged
merged 7 commits into from
Oct 28, 2022
5 changes: 5 additions & 0 deletions .changeset/rich-cooks-attend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'polaris.shopify.com': patch
---

Update `Columns` component docs
23 changes: 19 additions & 4 deletions polaris.shopify.com/content/components/columns.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Columns
description: Use to lay out a vertical row of components with equal spacing between and wrapping onto multiple lines.
description: Displays content horizontally in one or more columns with equal spacing between.
category: Structure
keywords:
- layout
Expand All @@ -10,8 +10,23 @@ status:
examples:
- fileName: columns-default.tsx
title: Default
description: >-
By default, there are 6 columns with 16px spacing between them.
- fileName: columns-with-varying-spacing.tsx
title: With varying spacing
- fileName: columns-with-free-and-fixed-widths.tsx
title: With free and fixed widths
title: Spacing
description: >-
Use the spacing prop to set the amount of space between columns.
- fileName: columns-with-fixed-widths.tsx
title: Column width
description: >-
Individual column width can be adjusted.
- fileName: columns-with-set-number.tsx
title: Number of columns
description: >-
Use the columns prop to set the number and width of columns across breakpoints.
---

## Related components

- For more control over padding and widths, [use the Box](https://polaris.shopify.com/components/box) component
- To lay out a set of smaller components horizontally, [use the Inline](https://polaris.shopify.com/components/inline) component
46 changes: 35 additions & 11 deletions polaris.shopify.com/pages/examples/columns-default.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,45 @@
import React from 'react';
import {Columns} from '@shopify/polaris';
import {Columns, Text, Inline} from '@shopify/polaris';

import {withPolarisExample} from '../../src/components/PolarisExampleWrapper';

function ColumnsExample() {
return (
<div style={{width: '100%'}}>
<Columns columns={{xs: 1, sm: 2, md: 3, lg: 6}} spacing={{xs: '2'}}>
<div style={{background: 'var(--p-surface-success)'}}>Column one</div>
<div style={{background: 'var(--p-surface-success)'}}>Column two</div>
<div style={{background: 'var(--p-surface-success)'}}>Column three</div>
<div style={{background: 'var(--p-surface-success)'}}>Column four</div>
<div style={{background: 'var(--p-surface-success)'}}>Column five</div>
<div style={{background: 'var(--p-surface-success)'}}>Column six</div>
</Columns>
</div>
<Columns>
<Placeholder height="320px" label="01" />
<Placeholder height="320px" label="02" />
<Placeholder height="320px" label="03" />
<Placeholder height="320px" label="04" />
<Placeholder height="320px" label="05" />
<Placeholder height="320px" label="06" />
</Columns>
);
}

const Placeholder = ({label = '', height = 'auto', width = 'auto'}) => {
return (
<div
style={{
display: 'inherit',
background: '#7B47F1',
height: height ?? undefined,
width: width ?? undefined,
}}
>
<Inline align={'center'} alignY={'center'}>
chazdean marked this conversation as resolved.
Show resolved Hide resolved
<div
style={{
color: '#FFFFFF',
width: width ?? undefined,
}}
>
<Text as="h2" variant="bodyMd" fontWeight="medium" alignment="center">
{label}
</Text>
</div>
</Inline>
</div>
);
};

export default withPolarisExample(ColumnsExample);
45 changes: 45 additions & 0 deletions polaris.shopify.com/pages/examples/columns-with-fixed-widths.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import React from 'react';
import {Columns, Text, Inline} from '@shopify/polaris';

import {withPolarisExample} from '../../src/components/PolarisExampleWrapper';

function ColumnsWithFreeAndFixedWidthsExample() {
return (
<Columns columns={{xs: '2.5fr 1fr 1fr 1fr 1fr 1fr'}}>
<Placeholder height="320px" label="01" />
<Placeholder height="320px" label="02" />
<Placeholder height="320px" label="03" />
<Placeholder height="320px" label="04" />
<Placeholder height="320px" label="05" />
<Placeholder height="320px" label="06" />
</Columns>
);
}

const Placeholder = ({label = '', height = 'auto', width = 'auto'}) => {
return (
<div
style={{
display: 'inherit',
background: '#7B47F1',
height: height ?? undefined,
width: width ?? undefined,
}}
>
<Inline align={'center'} alignY={'center'}>
chazdean marked this conversation as resolved.
Show resolved Hide resolved
<div
style={{
color: '#FFFFFF',
width: width ?? undefined,
}}
>
<Text as="h2" variant="bodyMd" fontWeight="medium" alignment="center">
{label}
</Text>
</div>
</Inline>
</div>
);
};

export default withPolarisExample(ColumnsWithFreeAndFixedWidthsExample);

This file was deleted.

67 changes: 67 additions & 0 deletions polaris.shopify.com/pages/examples/columns-with-set-number.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import React from 'react';
import {Columns, Text, Inline} from '@shopify/polaris';

import {withPolarisExample} from '../../src/components/PolarisExampleWrapper';

function ColumnsWithSetNumberExample() {
return (
<SpacingBackground>
<Columns
columns={{
xs: '3fr 3fr',
md: '4fr 2fr',
}}
spacing={{
xs: '4',
md: '2',
}}
>
<Placeholder height="320px" label="01" />
<Placeholder height="320px" label="02" />
</Columns>
</SpacingBackground>
);
}

const SpacingBackground = ({children, width = '100%'}) => {
return (
<div
style={{
background:
'repeating-linear-gradient(-45deg, #7B47F1, #7B47F1 1px, #E8D1FA 1px, #E8D1FA 7px)',
width: width ?? undefined,
height: 'auto',
}}
>
{children}
</div>
);
};

const Placeholder = ({label = '', height = 'auto', width = 'auto'}) => {
return (
<div
style={{
display: 'inherit',
background: '#7B47F1',
height: height ?? undefined,
width: width ?? undefined,
}}
>
<Inline align={'center'} alignY={'center'}>
chazdean marked this conversation as resolved.
Show resolved Hide resolved
<div
style={{
color: '#FFFFFF',
width: width ?? undefined,
}}
>
<Text as="h2" variant="bodyMd" fontWeight="medium" alignment="center">
{label}
</Text>
</div>
</Inline>
</div>
);
};

export default withPolarisExample(ColumnsWithSetNumberExample);
61 changes: 51 additions & 10 deletions polaris.shopify.com/pages/examples/columns-with-varying-spacing.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,62 @@
import React from 'react';
import {Columns} from '@shopify/polaris';
import {Columns, Text, Inline} from '@shopify/polaris';

import {withPolarisExample} from '../../src/components/PolarisExampleWrapper';

function ColumnsWithVaryingGapExample() {
return (
<div style={{width: '100%'}}>
<Columns
columns={{xs: 3}}
spacing={{xs: '025', sm: '05', md: '1', lg: '2', xl: '4'}}
>
<div style={{background: 'var(--p-surface-success)'}}>Column one</div>
<div style={{background: 'var(--p-surface-success)'}}>Column two</div>
<div style={{background: 'var(--p-surface-success)'}}>Column three</div>
<SpacingBackground>
<Columns spacing={{xs: '2'}}>
<Placeholder height="320px" label="01" />
<Placeholder height="320px" label="02" />
<Placeholder height="320px" label="03" />
<Placeholder height="320px" label="04" />
<Placeholder height="320px" label="05" />
<Placeholder height="320px" label="06" />
</Columns>
</div>
</SpacingBackground>
);
}

const SpacingBackground = ({children, width = '100%'}) => {
return (
<div
style={{
background:
'repeating-linear-gradient(-45deg, #7B47F1, #7B47F1 1px, #E8D1FA 1px, #E8D1FA 7px)',
width: width ?? undefined,
height: 'auto',
}}
>
{children}
</div>
);
};

const Placeholder = ({label = '', height = 'auto', width = 'auto'}) => {
return (
<div
style={{
display: 'inherit',
background: '#7B47F1',
height: height ?? undefined,
width: width ?? undefined,
}}
>
<Inline align={'center'} alignY={'center'}>
chazdean marked this conversation as resolved.
Show resolved Hide resolved
<div
style={{
color: '#FFFFFF',
width: width ?? undefined,
}}
>
<Text as="h2" variant="bodyMd" fontWeight="medium" alignment="center">
{label}
</Text>
</div>
</Inline>
</div>
);
};

export default withPolarisExample(ColumnsWithVaryingGapExample);