Skip to content

Commit 13546e3

Browse files
authored
[Columns] Default to 6 columns (#7410)
We should be opinionated and apply smart defaults where we can. Also let's not worry about documenting children if we don't have to and use the `PropsWithChildren` type
1 parent 89fea23 commit 13546e3

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed

.changeset/kind-kings-promise.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@shopify/polaris': patch
3+
---
4+
5+
Apply default value to Columns

polaris-react/src/components/Columns/Columns.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default {
1010
export function BasicColumns() {
1111
return (
1212
<Page fullWidth>
13-
<Columns columns={{xs: 1, sm: 2, md: 3, lg: 6}} spacing={{xs: '2'}}>
13+
<Columns>
1414
<div style={{background: 'aquamarine'}}>one</div>
1515
<div style={{background: 'aquamarine'}}>two</div>
1616
<div style={{background: 'aquamarine'}}>three</div>

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React, {PropsWithChildren} from 'react';
22
import type {
33
BreakpointsAlias,
44
SpacingSpaceScale,
@@ -16,15 +16,18 @@ type Spacing = {
1616
[Breakpoint in BreakpointsAlias]?: SpacingSpaceScale;
1717
};
1818

19-
export interface ColumnsProps {
19+
export interface ColumnsProps extends PropsWithChildren {
20+
/** The space between columns */
2021
spacing?: Spacing;
22+
/** The number of columns to display
23+
* @default {xs: 6, sm: 6, md: 6, lg: 6, xl: 6}
24+
*/
2125
columns?: Columns;
22-
children?: React.ReactNode;
2326
}
2427

2528
export function Columns({columns, children, spacing}: ColumnsProps) {
2629
const style = {
27-
'--pc-columns-xs': formatColumns(columns?.xs),
30+
'--pc-columns-xs': formatColumns(columns?.xs || 6),
2831
'--pc-columns-sm': formatColumns(columns?.sm),
2932
'--pc-columns-md': formatColumns(columns?.md),
3033
'--pc-columns-lg': formatColumns(columns?.lg),

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,19 @@ describe('Columns', () => {
77
it('does not render custom properties by default', () => {
88
const columns = mountWithApp(<Columns />);
99

10-
expect(columns).toContainReactComponent('div', {style: undefined});
10+
expect(columns).toContainReactComponent('div', {
11+
style: {
12+
'--pc-columns-xs': 'repeat(6, minmax(0, 1fr))',
13+
} as React.CSSProperties,
14+
});
1115
});
1216

1317
it('only renders custom properties that match the properties passed in', () => {
1418
const columns = mountWithApp(<Columns spacing={{md: '1'}} />);
1519

1620
expect(columns).toContainReactComponent('div', {
1721
style: {
22+
'--pc-columns-xs': 'repeat(6, minmax(0, 1fr))',
1823
'--pc-columns-space-md': 'var(--p-space-1)',
1924
} as React.CSSProperties,
2025
});

0 commit comments

Comments
 (0)