Skip to content
This repository was archived by the owner on Sep 30, 2025. It is now read-only.

Commit a707318

Browse files
authored
[Box] Add support for paddingInline and paddingBlock (#11170)
### WHY are these changes introduced? Resolves #10617. ### WHAT is this pull request doing? Adds: - support for `paddingInline` and `paddingBlock` to reduce the need to set the value redundantly with multiple props - updates to `Box` padding documentation on style guide and storybook - fixes the text color on layout component style guide examples for accessibility <details> <summary>Box padding documentation — before</summary> <img src="https://github.com/Shopify/polaris/assets/26749317/a1e91acb-c9fc-4783-8365-a2ebc48a2fd7" alt="Box padding documentation — before"> </details> <details> <summary>Box padding documentation — after</summary> <img src="https://github.com/Shopify/polaris/assets/26749317/950a7fd0-ced5-41a4-b3e9-a9aea7c89506" alt="Box padding documentation — after"> </details> ### How to 🎩 Example that tests different use cases for Box padding props in the Playground included below. 🖥 [Local development instructions](https://github.com/Shopify/polaris/blob/main/README.md#local-development) 🗒 [General tophatting guidelines](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting.md) 📄 [Changelog guidelines](https://github.com/Shopify/polaris/blob/main/.github/CONTRIBUTING.md#changelog) <details> <summary>Copy-paste this code in <code>playground/Playground.tsx</code>:</summary> ```jsx import React from 'react'; import {Page, Box, BlockStack, Text} from '../src'; export function Playground() { return ( <Page title="Playground"> {/* Add the code you want to test in here */} <BlockStack gap="800"> <BlockStack gap="200"> <Text as="h1" variant="headingLg"> Box padding — default </Text> <Box background="bg-surface" borderWidth="025" borderColor="border"> <Text as="p" variant="bodyMd" truncate> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent aliquet libero et metus tempus, sit amet malesuada justo posuere. Nulla egestas, diam et dapibus maximus, nisl neque tempus sapien, semper tincidunt nulla elit vitae dui. Nulla scelerisque porta ex at mattis. Phasellus tempor augue nec eros egestas laoreet. </Text> </Box> </BlockStack> <BlockStack gap="200"> <Text as="h1" variant="headingLg"> Box padding — paddingBlock only </Text> <Box background="bg-fill-magic-secondary" paddingBlock="2400" borderWidth="025" borderColor="border" > <Text as="p" variant="bodyMd" truncate> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent aliquet libero et metus tempus, sit amet malesuada justo posuere. Nulla egestas, diam et dapibus maximus, nisl neque tempus sapien, semper tincidunt nulla elit vitae dui. Nulla scelerisque porta ex at mattis. Phasellus tempor augue nec eros egestas laoreet. </Text> </Box> </BlockStack> <BlockStack gap="200"> <Text as="h1" variant="headingLg"> Box padding — paddingBlock responsive (xs and lg breakpoint) </Text> <Box background="bg-fill-magic-secondary" paddingBlock={{xs: '0', lg: '2400'}} borderWidth="025" borderColor="border" > <Text as="p" variant="bodyMd" truncate> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent aliquet libero et metus tempus, sit amet malesuada justo posuere. Nulla egestas, diam et dapibus maximus, nisl neque tempus sapien, semper tincidunt nulla elit vitae dui. Nulla scelerisque porta ex at mattis. Phasellus tempor augue nec eros egestas laoreet. </Text> </Box> </BlockStack> <BlockStack gap="200"> <Text as="h1" variant="headingLg"> Box padding — paddingBlock and paddingBlockStart (different values) </Text> <Box background="bg-fill-magic-secondary" paddingBlock="2400" paddingBlockEnd="800" borderWidth="025" borderColor="border" > <Text as="p" variant="bodyMd" truncate> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent aliquet libero et metus tempus, sit amet malesuada justo posuere. Nulla egestas, diam et dapibus maximus, nisl neque tempus sapien, semper tincidunt nulla elit vitae dui. Nulla scelerisque porta ex at mattis. Phasellus tempor augue nec eros egestas laoreet. </Text> </Box> </BlockStack> <BlockStack gap="200"> <Text as="h1" variant="headingLg"> Box padding — paddingInline only </Text> <Box background="bg-fill-warning-secondary" paddingInline="3200" borderWidth="025" borderColor="border" > <Text as="p" variant="bodyMd" truncate> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent aliquet libero et metus tempus, sit amet malesuada justo posuere. Nulla egestas, diam et dapibus maximus, nisl neque tempus sapien, semper tincidunt nulla elit vitae dui. Nulla scelerisque porta ex at mattis. Phasellus tempor augue nec eros egestas laoreet. </Text> </Box> </BlockStack> <BlockStack gap="200"> <Text as="h1" variant="headingLg"> Box padding — paddingInline responsive (xs and lg breakpoint) </Text> <Box background="bg-fill-warning-secondary" paddingInline={{xs: '0', lg: '3200'}} borderWidth="025" borderColor="border" > <Text as="p" variant="bodyMd" truncate> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent aliquet libero et metus tempus, sit amet malesuada justo posuere. Nulla egestas, diam et dapibus maximus, nisl neque tempus sapien, semper tincidunt nulla elit vitae dui. Nulla scelerisque porta ex at mattis. Phasellus tempor augue nec eros egestas laoreet. </Text> </Box> </BlockStack> <BlockStack gap="200"> <Text as="h1" variant="headingLg"> Box padding — paddingInline and paddingInlineEnd (different values) </Text> <Box background="bg-fill-warning-secondary" paddingInline="3200" paddingInlineEnd="800" borderWidth="025" borderColor="border" > <Text as="p" variant="bodyMd" truncate> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent aliquet libero et metus tempus, sit amet malesuada justo posuere. Nulla egestas, diam et dapibus maximus, nisl neque tempus sapien, semper tincidunt nulla elit vitae dui. Nulla scelerisque porta ex at mattis. Phasellus tempor augue nec eros egestas laoreet. </Text> </Box> </BlockStack> <BlockStack gap="200"> <Text as="h1" variant="headingLg"> Box padding — padding only </Text> <Box background="bg-surface-success" padding="500" borderWidth="025" borderColor="border" > <Text as="p" variant="bodyMd" truncate> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent aliquet libero et metus tempus, sit amet malesuada justo posuere. Nulla egestas, diam et dapibus maximus, nisl neque tempus sapien, semper tincidunt nulla elit vitae dui. Nulla scelerisque porta ex at mattis. Phasellus tempor augue nec eros egestas laoreet. </Text> </Box> </BlockStack> <BlockStack gap="200"> <Text as="h1" variant="headingLg"> Box padding — padding responsive (xs and lg breakpoint) </Text> <Box background="bg-surface-success" padding={{xs: '0', lg: '500'}} borderWidth="025" borderColor="border" > <Text as="p" variant="bodyMd" truncate> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent aliquet libero et metus tempus, sit amet malesuada justo posuere. Nulla egestas, diam et dapibus maximus, nisl neque tempus sapien, semper tincidunt nulla elit vitae dui. Nulla scelerisque porta ex at mattis. Phasellus tempor augue nec eros egestas laoreet. </Text> </Box> </BlockStack> <BlockStack gap="200"> <Text as="h1" variant="headingLg"> Box padding — paddingInlineStart, paddingInlineEnd, paddingBlockStart, paddingBlockEnd (different values) </Text> <Box background="bg-fill-critical-secondary" paddingInlineStart="200" paddingInlineEnd="400" paddingBlockStart="600" paddingBlockEnd="800" borderWidth="025" borderColor="border" > <Text as="p" variant="bodyMd" truncate> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent aliquet libero et metus tempus, sit amet malesuada justo posuere. Nulla egestas, diam et dapibus maximus, nisl neque tempus sapien, semper tincidunt nulla elit vitae dui. Nulla scelerisque porta ex at mattis. Phasellus tempor augue nec eros egestas laoreet. </Text> </Box> </BlockStack> <BlockStack gap="200"> <Text as="h1" variant="headingLg"> Box padding — paddingInlineStart, paddingInlineEnd, paddingBlockStart, paddingBlockEnd responsive (xs and lg breakpoint) </Text> <Box background="bg-fill-critical-secondary" paddingInlineStart={{xs: '0', lg: '200'}} paddingInlineEnd={{xs: '0', lg: '400'}} paddingBlockStart={{xs: '0', lg: '600'}} paddingBlockEnd={{xs: '0', lg: '800'}} borderWidth="025" borderColor="border" > <Text as="p" variant="bodyMd" truncate> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent aliquet libero et metus tempus, sit amet malesuada justo posuere. Nulla egestas, diam et dapibus maximus, nisl neque tempus sapien, semper tincidunt nulla elit vitae dui. Nulla scelerisque porta ex at mattis. Phasellus tempor augue nec eros egestas laoreet. </Text> </Box> </BlockStack> </BlockStack> </Page> ); } ``` </details> ### 🎩 checklist - [x] Tested on [mobile](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting.md#cross-browser-testing) - [x] Tested on [multiple browsers](https://help.shopify.com/en/manual/shopify-admin/supported-browsers) - [ ] Tested for [accessibility](https://github.com/Shopify/polaris/blob/main/documentation/Accessibility%20testing.md) - [ ] Updated the component's `README.md` with documentation changes - [x] [Tophatted documentation](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting%20documentation.md) changes in the style guide
1 parent ef18aa1 commit a707318

15 files changed

+166
-40
lines changed

.changeset/serious-days-grow.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 `paddingInline` and `paddingBlock` on `Box` component with updated documentation

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

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,69 @@ export function WithBorderRadius() {
141141
);
142142
}
143143

144+
export function WithPadding() {
145+
return (
146+
<BlockStack gap="400">
147+
<Box
148+
background="bg-surface"
149+
padding="100"
150+
borderWidth="050"
151+
borderColor="border-info"
152+
>
153+
<Icon source={PaintBrushMajor} tone="base" />
154+
</Box>
155+
<Box
156+
background="bg-surface"
157+
paddingBlock="400"
158+
borderWidth="050"
159+
borderColor="border-info"
160+
>
161+
<Icon source={PaintBrushMajor} tone="base" />
162+
</Box>
163+
<Box
164+
background="bg-surface"
165+
paddingBlockStart="400"
166+
borderWidth="050"
167+
borderColor="border-info"
168+
>
169+
<Icon source={PaintBrushMajor} tone="base" />
170+
</Box>
171+
<Box
172+
background="bg-surface"
173+
paddingBlockEnd="400"
174+
borderWidth="050"
175+
borderColor="border-info"
176+
>
177+
<Icon source={PaintBrushMajor} tone="base" />
178+
</Box>
179+
<Box
180+
background="bg-surface"
181+
paddingInline="400"
182+
borderWidth="050"
183+
borderColor="border-info"
184+
>
185+
<Icon source={PaintBrushMajor} tone="base" />
186+
</Box>
187+
<Box
188+
background="bg-surface"
189+
paddingInlineStart="400"
190+
borderWidth="050"
191+
borderColor="border-info"
192+
>
193+
<Icon source={PaintBrushMajor} tone="base" />
194+
</Box>
195+
<Box
196+
background="bg-surface"
197+
paddingInlineEnd="400"
198+
borderWidth="050"
199+
borderColor="border-info"
200+
>
201+
<Icon source={PaintBrushMajor} tone="base" />
202+
</Box>
203+
</BlockStack>
204+
);
205+
}
206+
144207
export function WithResponsivePadding() {
145208
return (
146209
<BlockStack gap="400">

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

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ export interface BoxProps extends React.AriaAttributes {
7878
* padding={{xs: '200', sm: '300', md: '400', lg: '500', xl: '600'}}
7979
*/
8080
padding?: Spacing;
81+
/** Vertical start and end spacing around children. Accepts a spacing token or an object of spacing tokens for different screen sizes.
82+
* @example
83+
* paddingBlock='400'
84+
* paddingBlock={{xs: '200', sm: '300', md: '400', lg: '500', xl: '600'}}
85+
*/
86+
paddingBlock?: Spacing;
8187
/** Vertical start spacing around children. Accepts a spacing token or an object of spacing tokens for different screen sizes.
8288
* @example
8389
* paddingBlockStart='400'
@@ -90,6 +96,12 @@ export interface BoxProps extends React.AriaAttributes {
9096
* paddingBlockEnd={{xs: '200', sm: '300', md: '400', lg: '500', xl: '600'}}
9197
*/
9298
paddingBlockEnd?: Spacing;
99+
/** Horizontal start and end spacing around children. Accepts a spacing token or an object of spacing tokens for different screen sizes.
100+
* @example
101+
* paddingInline='400'
102+
* paddingInline={{xs: '200', sm: '300', md: '400', lg: '500', xl: '600'}}
103+
*/
104+
paddingInline?: Spacing;
93105
/** Horizontal start spacing around children. Accepts a spacing token or an object of spacing tokens for different screen sizes.
94106
* @example
95107
* paddingInlineStart='400'
@@ -169,8 +181,10 @@ export const Box = forwardRef<HTMLElement, BoxProps>(
169181
outlineStyle,
170182
outlineWidth,
171183
padding,
184+
paddingBlock,
172185
paddingBlockStart,
173186
paddingBlockEnd,
187+
paddingInline,
174188
paddingInlineStart,
175189
paddingInlineEnd,
176190
role,
@@ -265,27 +279,27 @@ export const Box = forwardRef<HTMLElement, BoxProps>(
265279
'--pc-box-overflow-y': overflowY,
266280
...getResponsiveProps(
267281
'box',
268-
'padding-block-end',
282+
'padding-block-start',
269283
'space',
270-
paddingBlockEnd || padding,
284+
paddingBlockStart || paddingBlock || padding,
271285
),
272286
...getResponsiveProps(
273287
'box',
274-
'padding-block-start',
288+
'padding-block-end',
275289
'space',
276-
paddingBlockStart || padding,
290+
paddingBlockEnd || paddingBlock || padding,
277291
),
278292
...getResponsiveProps(
279293
'box',
280294
'padding-inline-start',
281295
'space',
282-
paddingInlineStart || padding,
296+
paddingInlineStart || paddingInline || padding,
283297
),
284298
...getResponsiveProps(
285299
'box',
286300
'padding-inline-end',
287301
'space',
288-
paddingInlineEnd || padding,
302+
paddingInlineEnd || paddingInline || padding,
289303
),
290304
'--pc-box-shadow': shadow ? `var(--p-shadow-${shadow})` : undefined,
291305
'--pc-box-width': width,

polaris.shopify.com/pages/examples/bleed-horizontal.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,12 @@ const Placeholder = ({label = '', height = 'auto', width = 'auto'}) => {
3232
color: 'var(--p-color-text-info-on-bg-fill)',
3333
}}
3434
>
35-
<Text as="h2" variant="bodyMd" fontWeight="regular">
35+
<Text
36+
as="h2"
37+
variant="bodyMd"
38+
fontWeight="regular"
39+
tone="text-inverse"
40+
>
3641
{label}
3742
</Text>
3843
</div>

polaris.shopify.com/pages/examples/bleed-specific-direction.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,12 @@ const Placeholder = ({label = '', height = 'auto', width = 'auto'}) => {
4747
color: 'var(--p-color-text-info-on-bg-fill)',
4848
}}
4949
>
50-
<Text as="h2" variant="bodyMd" fontWeight="regular">
50+
<Text
51+
as="h2"
52+
variant="bodyMd"
53+
fontWeight="regular"
54+
tone="text-inverse"
55+
>
5156
{label}
5257
</Text>
5358
</div>

polaris.shopify.com/pages/examples/bleed-vertical.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,12 @@ const Placeholder = ({label = '', height = 'auto', width = 'auto'}) => {
2929
color: 'var(--p-color-text-info-on-bg-fill)',
3030
}}
3131
>
32-
<Text as="h2" variant="bodyMd" fontWeight="regular">
32+
<Text
33+
as="h2"
34+
variant="bodyMd"
35+
fontWeight="regular"
36+
tone="text-inverse"
37+
>
3338
{label}
3439
</Text>
3540
</div>

polaris.shopify.com/pages/examples/block-stack-with-align.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,12 @@ const Placeholder = ({
5959
color: 'var(--p-color-text-info-on-bg-fill)',
6060
}}
6161
>
62-
<Text as="h2" variant="bodyMd" fontWeight="regular">
62+
<Text
63+
as="h2"
64+
variant="bodyMd"
65+
fontWeight="regular"
66+
tone="text-inverse"
67+
>
6368
{label}
6469
</Text>
6570
</div>

polaris.shopify.com/pages/examples/block-stack-with-inline-align.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,12 @@ const Placeholder = ({
5353
color: 'var(--p-color-text-info-on-bg-fill)',
5454
}}
5555
>
56-
<Text as="h2" variant="bodyMd" fontWeight="regular">
56+
<Text
57+
as="h2"
58+
variant="bodyMd"
59+
fontWeight="regular"
60+
tone="text-inverse"
61+
>
5762
{label}
5863
</Text>
5964
</div>

polaris.shopify.com/pages/examples/box-with-color.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {withPolarisExample} from '../../src/components/PolarisExampleWrapper';
55

66
function BoxWithColorExample() {
77
return (
8-
<Box background="bg-surface-selected">
8+
<Box background="bg-fill-info">
99
<Placeholder label="Content inside a box" />
1010
</Box>
1111
);

polaris.shopify.com/pages/examples/box-with-padding.tsx

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,37 +8,34 @@ function BoxWithPaddingExample() {
88
<BlockStack gap="400">
99
<div
1010
style={{
11-
backgroundColor: 'var(--p-color-bg-fill-info)',
1211
width: '586px',
1312
}}
1413
>
15-
<Box padding="400" width="586px">
14+
<Box padding="400" width="586px" background="bg-fill-info">
1615
<Placeholder label="padding" childAlign="center" />
1716
</Box>
1817
</div>
1918
<InlineStack gap="400">
20-
<div style={{backgroundColor: 'var(--p-color-bg-fill-info)'}}>
21-
<Box paddingInlineStart="400" width="284px">
22-
<Placeholder label="paddingInlineStart" childAlign="start" />
23-
</Box>
24-
</div>
25-
<div style={{backgroundColor: 'var(--p-color-bg-fill-info)'}}>
26-
<Box paddingInlineEnd="400" width="284px">
27-
<Placeholder label="paddingInlineEnd" childAlign="end" />
28-
</Box>
29-
</div>
19+
<Box paddingInline="400" width="586px" background="bg-fill-info">
20+
<Placeholder label="paddingInline" childAlign="center" />
21+
</Box>
22+
<Box paddingInlineStart="400" width="284px" background="bg-fill-info">
23+
<Placeholder label="paddingInlineStart" childAlign="start" />
24+
</Box>
25+
<Box paddingInlineEnd="400" width="284px" background="bg-fill-info">
26+
<Placeholder label="paddingInlineEnd" childAlign="end" />
27+
</Box>
3028
</InlineStack>
3129
<InlineStack gap="400">
32-
<div style={{backgroundColor: 'var(--p-color-bg-fill-info)'}}>
33-
<Box paddingBlockStart="400" width="284px">
34-
<Placeholder label="paddingBlockStart" childAlign="center" />
35-
</Box>
36-
</div>
37-
<div style={{backgroundColor: 'var(--p-color-bg-fill-info)'}}>
38-
<Box paddingBlockEnd="400" width="284px">
39-
<Placeholder label="paddingBlockEnd" childAlign="center" />
40-
</Box>
41-
</div>
30+
<Box paddingBlock="400" width="586px" background="bg-fill-info">
31+
<Placeholder label="paddingBlock" childAlign="center" />
32+
</Box>
33+
<Box paddingBlockStart="400" width="284px" background="bg-fill-info">
34+
<Placeholder label="paddingBlockStart" childAlign="center" />
35+
</Box>
36+
<Box paddingBlockEnd="400" width="284px" background="bg-fill-info">
37+
<Placeholder label="paddingBlockEnd" childAlign="center" />
38+
</Box>
4239
</InlineStack>
4340
</BlockStack>
4441
);
@@ -69,7 +66,12 @@ const Placeholder = ({
6966
color: 'var(--p-color-text-info-on-bg-fill)',
7067
}}
7168
>
72-
<Text as="h2" variant="bodyMd" fontWeight="medium">
69+
<Text
70+
as="h2"
71+
variant="bodyMd"
72+
fontWeight="medium"
73+
tone="text-inverse"
74+
>
7375
{label}
7476
</Text>
7577
</div>

0 commit comments

Comments
 (0)