Skip to content

Commit cb882f4

Browse files
authored
[Box] Refactor position to use logical properties (#7777)
### WHY are these changes introduced? Resolves #7771. Refactors `Box` to use logical properties to align with other layout primitives. ### WHAT is this pull request doing? Refactors `top`, `bottom`, `left`, and `right` props on `Box` to be `insetBlockStart`, `insetBlockEnd`, `insetInlineStart`, and `insetInlineEnd`. Updates prop names in style guide. ### How to 🎩 🖥 [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 {Box, Page} from '../src'; export function Playground() { return ( <Page title="Playground"> <Box position="relative" width="100%" minHeight="600px" background="action-primary-depressed" > <Box position="absolute" insetInlineStart="0" insetBlockEnd="0" width="50px" minHeight="50px" background="action-critical-depressed" zIndex="1" /> <Box position="absolute" insetInlineStart="0" insetBlockEnd="6" width="50px" minHeight="50px" background="action-critical" zIndex="2" /> <Box position="absolute" insetBlockStart="4" insetInlineEnd="4" width="100px" minHeight="100px" background="action-critical" zIndex="2" > <Box position="absolute" insetBlockEnd="2" insetInlineStart="0" width="50px" minHeight="50px" background="action-secondary" zIndex="1" > <Box visuallyHidden>asdf</Box> </Box> </Box> </Box> </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 300b6d4 commit cb882f4

File tree

4 files changed

+1989
-1975
lines changed

4 files changed

+1989
-1975
lines changed

.changeset/lovely-moose-refuse.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@shopify/polaris': patch
3+
'polaris.shopify.com': patch
4+
---
5+
6+
Refactored `position` properties on `Box` to use logical property names

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@
5252
--pc-box-padding-block-start: initial;
5353
--pc-box-width: initial;
5454
--pc-box-border-width: var(--p-border-width-1);
55-
--pc-box-top: initial;
56-
--pc-box-right: initial;
57-
--pc-box-bottom: initial;
58-
--pc-box-left: initial;
59-
top: var(--pc-box-top);
60-
right: var(--pc-box-right);
61-
bottom: var(--pc-box-bottom);
62-
left: var(--pc-box-left);
55+
--pc-box-inset-block-start: initial;
56+
--pc-box-inset-block-end: initial;
57+
--pc-box-inset-inline-start: initial;
58+
--pc-box-inset-inline-end: initial;
59+
inset-block-start: var(--pc-box-inset-block-start);
60+
inset-block-end: var(--pc-box-inset-block-end);
61+
inset-inline-start: var(--pc-box-inset-inline-start);
62+
inset-inline-end: var(--pc-box-inset-inline-end);
6363
background-color: var(--pc-box-background);
6464
box-shadow: var(--pc-box-shadow);
6565
border-radius: var(--pc-box-border-radius);

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

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,13 @@ export interface BoxProps {
158158
/** Position of box */
159159
position?: Position;
160160
/** Top position of box */
161-
top?: Spacing;
161+
insetBlockStart?: Spacing;
162162
/** Bottom position of box */
163-
right?: Spacing;
163+
insetBlockEnd?: Spacing;
164164
/** Left position of box */
165-
bottom?: Spacing;
165+
insetInlineStart?: Spacing;
166166
/** Right position of box */
167-
left?: Spacing;
167+
insetInlineEnd?: Spacing;
168168
/** Opacity of box */
169169
opacity?: string;
170170
/** Visually hide the contents (still announced by screenreader) */
@@ -210,10 +210,10 @@ export const Box = forwardRef<HTMLElement, BoxProps>(
210210
width,
211211
visuallyHidden,
212212
position,
213-
top,
214-
right,
215-
bottom,
216-
left,
213+
insetBlockStart,
214+
insetBlockEnd,
215+
insetInlineStart,
216+
insetInlineEnd,
217217
zIndex,
218218
opacity,
219219
},
@@ -298,10 +298,18 @@ export const Box = forwardRef<HTMLElement, BoxProps>(
298298
'--pc-box-shadow': shadow ? `var(--p-shadow-${shadow})` : undefined,
299299
'--pc-box-width': width,
300300
position,
301-
'--pc-box-top': top ? `var(--p-space-${top})` : undefined,
302-
'--pc-box-right': right ? `var(--p-space-${right})` : undefined,
303-
'--pc-box-bottom': bottom ? `var(--p-space-${bottom})` : undefined,
304-
'--pc-box-left': left ? `var(--p-space-${left})` : undefined,
301+
'--pc-box-inset-block-start': insetBlockStart
302+
? `var(--p-space-${insetBlockStart})`
303+
: undefined,
304+
'--pc-box-inset-block-end': insetBlockEnd
305+
? `var(--p-space-${insetBlockEnd})`
306+
: undefined,
307+
'--pc-box-inset-inline-start': insetInlineStart
308+
? `var(--p-space-${insetInlineStart})`
309+
: undefined,
310+
'--pc-box-inset-inline-end': insetInlineEnd
311+
? `var(--p-space-${insetInlineEnd})`
312+
: undefined,
305313
zIndex,
306314
opacity,
307315
} as React.CSSProperties;

0 commit comments

Comments
 (0)