Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions .changeset/kind-kings-promise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/polaris': patch
---

Apply default value to Columns
2 changes: 1 addition & 1 deletion polaris-react/src/components/Columns/Columns.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default {
export function BasicColumns() {
return (
<Page fullWidth>
<Columns columns={{xs: 1, sm: 2, md: 3, lg: 6}} spacing={{xs: '2'}}>
<Columns>
<div style={{background: 'aquamarine'}}>one</div>
<div style={{background: 'aquamarine'}}>two</div>
<div style={{background: 'aquamarine'}}>three</div>
Expand Down
11 changes: 7 additions & 4 deletions polaris-react/src/components/Columns/Columns.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, {PropsWithChildren} from 'react';
import type {
BreakpointsAlias,
SpacingSpaceScale,
Expand All @@ -16,15 +16,18 @@ type Spacing = {
[Breakpoint in BreakpointsAlias]?: SpacingSpaceScale;
};

export interface ColumnsProps {
export interface ColumnsProps extends PropsWithChildren {
/** The space between columns */
spacing?: Spacing;
/** The number of columns to display
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is the default width of the column rather than the number? Because isn't the number based on the children?

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'm confused about this comment. I think the stories file best explains how this prop works but I also updated the default value to try and make it clearer

* @default {xs: 6, sm: 6, md: 6, lg: 6, xl: 6}
*/
columns?: Columns;
children?: React.ReactNode;
}

export function Columns({columns, children, spacing}: ColumnsProps) {
const style = {
'--pc-columns-xs': formatColumns(columns?.xs),
'--pc-columns-xs': formatColumns(columns?.xs || 6),
'--pc-columns-sm': formatColumns(columns?.sm),
'--pc-columns-md': formatColumns(columns?.md),
'--pc-columns-lg': formatColumns(columns?.lg),
Expand Down
7 changes: 6 additions & 1 deletion polaris-react/src/components/Columns/tests/Columns.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,19 @@ describe('Columns', () => {
it('does not render custom properties by default', () => {
const columns = mountWithApp(<Columns />);

expect(columns).toContainReactComponent('div', {style: undefined});
expect(columns).toContainReactComponent('div', {
style: {
'--pc-columns-xs': 'repeat(6, minmax(0, 1fr))',
} as React.CSSProperties,
});
});

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

expect(columns).toContainReactComponent('div', {
style: {
'--pc-columns-xs': 'repeat(6, minmax(0, 1fr))',
'--pc-columns-space-md': 'var(--p-space-1)',
} as React.CSSProperties,
});
Expand Down