Skip to content

Commit aee0c5c

Browse files
avelinelaurkim
andauthored
[Layout] Add responsive gap support to Inline (#7754)
### WHY are these changes introduced? Fixes #7739 ### WHAT is this pull request doing? `Inline` now accepts either a spacing token or object with breakpoint and spacing token for different spacing by breakpoint Co-authored-by: Lo Kim <lo.kim@shopify.com>
1 parent 6f12cad commit aee0c5c

File tree

5 files changed

+732
-680
lines changed

5 files changed

+732
-680
lines changed

.changeset/ten-peaches-exist.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@shopify/polaris': minor
3+
'polaris.shopify.com': minor
4+
---
5+
6+
Added support for responsive `gap` on `Inline`

polaris-react/src/components/Inline/Inline.scss

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
@import '../../styles/common';
2+
13
.Inline {
4+
@include responsive-props('inline', 'gap', 'gap');
25
display: flex;
3-
gap: var(--pc-inline-gap);
46
flex-wrap: var(--pc-inline-wrap);
57
align-items: var(--pc-inline-block-align);
68
justify-content: var(--pc-inline-align);

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

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import React from 'react';
22
import type {ComponentMeta} from '@storybook/react';
3-
import {Box, Badge, Icon, Inline, Thumbnail} from '@shopify/polaris';
3+
import {
4+
Box,
5+
Badge,
6+
Icon,
7+
Inline,
8+
Thumbnail,
9+
AlphaStack,
10+
} from '@shopify/polaris';
411
import {CapitalMajor, ImageMajor} from '@shopify/polaris-icons';
512

613
export default {
@@ -162,11 +169,33 @@ export function NonWrapping() {
162169

163170
export function Gap() {
164171
return (
165-
<Inline gap="8">
166-
<Badge>Paid</Badge>
167-
<Badge>Processing</Badge>
168-
<Badge>Fulfilled</Badge>
169-
<Badge>Completed</Badge>
170-
</Inline>
172+
<AlphaStack>
173+
<Inline gap="8">
174+
<Badge>Paid</Badge>
175+
<Badge>Processing</Badge>
176+
<Badge>Fulfilled</Badge>
177+
<Badge>Completed</Badge>
178+
</Inline>
179+
180+
<Inline gap={{xs: '2', md: '4'}}>
181+
<Badge>Paid</Badge>
182+
<Badge>Processing</Badge>
183+
<Badge>Fulfilled</Badge>
184+
<Badge>Completed</Badge>
185+
</Inline>
186+
</AlphaStack>
187+
);
188+
}
189+
190+
export function GapResponsive() {
191+
return (
192+
<AlphaStack>
193+
<Inline gap={{xs: '2', md: '4'}}>
194+
<Badge>Paid</Badge>
195+
<Badge>Processing</Badge>
196+
<Badge>Fulfilled</Badge>
197+
<Badge>Completed</Badge>
198+
</Inline>
199+
</AlphaStack>
171200
);
172201
}

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import React from 'react';
22
import type {SpacingSpaceScale} from '@shopify/polaris-tokens';
33

4+
import {getResponsiveProps} from '../../utilities/css';
5+
import type {ResponsiveProp} from '../../utilities/css';
6+
47
import styles from './Inline.scss';
58

69
type Align =
@@ -12,6 +15,8 @@ type Align =
1215
| 'space-evenly';
1316
type BlockAlign = 'start' | 'center' | 'end' | 'baseline' | 'stretch';
1417

18+
type Gap = ResponsiveProp<SpacingSpaceScale>;
19+
1520
export interface InlineProps {
1621
/** Adjust horizontal alignment of elements
1722
* @default 'start'
@@ -21,10 +26,13 @@ export interface InlineProps {
2126
* @default 'center'
2227
*/
2328
blockAlign?: BlockAlign;
24-
/** The spacing between elements
29+
/** The spacing between elements. Accepts a spacing token or an object of spacing tokens for different screen sizes.
2530
* @default '4'
31+
* @example
32+
* gap='2'
33+
* gap={{xs: '2', sm: '3', md: '4', lg: '5', xl: '6'}}
2634
*/
27-
gap?: SpacingSpaceScale;
35+
gap?: Gap;
2836
/** Wrap stack elements to additional rows as needed on small screens
2937
* @default true
3038
*/
@@ -44,7 +52,7 @@ export const Inline = function Inline({
4452
'--pc-inline-align': align,
4553
'--pc-inline-block-align': blockAlign,
4654
'--pc-inline-wrap': wrap ? 'wrap' : 'nowrap',
47-
'--pc-inline-gap': `var(--p-space-${gap})`,
55+
...getResponsiveProps('inline', 'gap', 'space', gap),
4856
} as React.CSSProperties;
4957

5058
return (

0 commit comments

Comments
 (0)