Skip to content

Commit 7ffd87f

Browse files
laurkimavelinekyledurand
authored
[Layout foundations][Batch 1] Rebuild components with layout primitives (#7408)
### WHY are these changes introduced? Related to [7565](#7565). ### WHAT is this pull request doing? Rebuilds the following components to use our layout primitives. - `ChoiceList` #7354 - `Modal` #7340 - `AccountConnection` #7341 - `Banner` #7358 ### How to 🎩 [Spin instance](https://admin.web.layout-rebuild-batch-1-b.lo-kim.us.spin.dev/store/shop1) [Storybook](https://5d559397bae39100201eedc1-cshuopiodd.chromatic.com/) 🖥 [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) ### 🎩 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 Co-authored-by: aveline <aveline@users.noreply.github.com> Co-authored-by: Kyle Durand <kyledurand@users.noreply.github.com>
1 parent bfb5377 commit 7ffd87f

27 files changed

+250
-331
lines changed

.changeset/cold-keys-raise.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@shopify/polaris': minor
3+
---
4+
5+
- Refactored `ChoiceList` to use primitive Layout components
6+
- Added support for `legend` element to `Box`
7+
- Added support for `fieldset` element to `AlphaStack`
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@shopify/polaris': minor
3+
---
4+
5+
Updated `Banner` component to use new layout primitives

.changeset/hip-wombats-sin.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@shopify/polaris': minor
3+
---
4+
5+
Refactored `Modal` and its children components to use layout primitives

.changeset/pink-apricots-help.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@shopify/polaris': minor
3+
---
4+
5+
Refactored `AccountConnection` to use new layout primitives

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

Lines changed: 0 additions & 10 deletions
This file was deleted.

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

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import React from 'react';
33
import type {Action} from '../../types';
44
import {Avatar} from '../Avatar';
55
import {buttonFrom} from '../Button';
6-
import {Card} from '../Card';
7-
import {Stack} from '../Stack';
8-
import {Text} from '../Text';
96
import {SettingAction} from '../SettingAction';
10-
11-
import styles from './AccountConnection.scss';
7+
import {AlphaCard} from '../AlphaCard';
8+
import {Box} from '../Box';
9+
import {Inline} from '../Inline';
10+
import {Text} from '../Text';
11+
import {AlphaStack} from '../AlphaStack';
1212

1313
export interface AccountConnectionProps {
1414
/** Content to display as title */
@@ -52,43 +52,34 @@ export function AccountConnection({
5252
/>
5353
) : null;
5454

55-
let titleMarkup: React.ReactNode = null;
56-
if (title) {
57-
titleMarkup = <div>{title}</div>;
58-
} else if (accountName) {
59-
titleMarkup = <div>{accountName}</div>;
60-
}
55+
const titleMarkup = title ? title : accountName;
6156

6257
const detailsMarkup = details ? (
63-
<div>
64-
<Text variant="bodyMd" color="subdued" as="span">
65-
{details}
66-
</Text>
67-
</div>
58+
<Text as="span" variant="bodyMd" color="subdued">
59+
{details}
60+
</Text>
6861
) : null;
6962

7063
const termsOfServiceMarkup = termsOfService ? (
71-
<div className={styles.TermsOfService}>{termsOfService}</div>
64+
<Box paddingBlockStart="5">{termsOfService}</Box>
7265
) : null;
7366

7467
const actionElement = action
7568
? buttonFrom(action, {primary: !connected})
7669
: null;
7770

7871
return (
79-
<Card sectioned>
72+
<AlphaCard>
8073
<SettingAction action={actionElement}>
81-
<Stack>
74+
<Inline gap="4">
8275
{avatarMarkup}
83-
<Stack.Item fill>
84-
<div className={styles.Content}>
85-
{titleMarkup}
86-
{detailsMarkup}
87-
</div>
88-
</Stack.Item>
89-
</Stack>
76+
<AlphaStack gap="2">
77+
{titleMarkup}
78+
{detailsMarkup}
79+
</AlphaStack>
80+
</Inline>
9081
</SettingAction>
9182
{termsOfServiceMarkup}
92-
</Card>
83+
</AlphaCard>
9384
);
9485
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
import React from 'react';
22
import {mountWithApp} from 'tests/utilities';
3+
import {matchMedia} from '@shopify/jest-dom-mocks';
34

45
import {Avatar} from '../../Avatar';
56
import {Button} from '../../Button';
67
import {AccountConnection} from '../AccountConnection';
78

89
describe('<AccountConnection />', () => {
10+
beforeEach(() => {
11+
matchMedia.mock();
12+
});
13+
14+
afterEach(() => {
15+
matchMedia.restore();
16+
});
17+
918
describe('title', () => {
1019
it('shows the title when one is provided', () => {
1120
const title = 'Example app';

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@
4646
padding-inline-start: 0;
4747
}
4848

49+
.fieldsetReset {
50+
border: none;
51+
margin: 0;
52+
padding: 0;
53+
}
54+
4955
.fullWidth {
5056
> * {
5157
// stylelint-disable-next-line -- generated by polaris-migrator DO NOT COPY

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export const AlphaStack = ({
5454
styles.AlphaStack,
5555
fullWidth && styles.fullWidth,
5656
as === 'ul' && styles.listReset,
57+
as === 'fieldset' && styles.fieldsetReset,
5758
);
5859

5960
const style = {

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

Lines changed: 6 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@
7575
// stylelint-disable-next-line -- generated by polaris-migrator DO NOT COPY
7676
display: flex;
7777

78-
// stylelint-disable selector-max-class, selector-max-combinators, selector-max-specificity -- generated by polaris-migrator DO NOT COPY
79-
&.statusCritical .PrimaryAction .Button {
78+
// stylelint-disable selector-max-class, selector-max-specificity -- generated by polaris-migrator DO NOT COPY
79+
&.statusCritical .PrimaryAction.Button {
8080
border-color: var(--p-border-critical-subdued);
8181
background: var(--p-surface-critical-subdued);
8282

@@ -96,7 +96,7 @@
9696
}
9797
}
9898

99-
&.statusWarning .PrimaryAction .Button {
99+
&.statusWarning .PrimaryAction.Button {
100100
border-color: var(--p-border-warning-subdued);
101101
background: var(--p-surface-warning-subdued);
102102

@@ -116,7 +116,7 @@
116116
}
117117
}
118118

119-
&.statusInfo .PrimaryAction .Button {
119+
&.statusInfo .PrimaryAction.Button {
120120
border-color: var(--p-border-highlight-subdued);
121121
background: var(--p-surface-highlight-subdued);
122122

@@ -136,7 +136,7 @@
136136
}
137137
}
138138

139-
&.statusSuccess .PrimaryAction .Button {
139+
&.statusSuccess .PrimaryAction.Button {
140140
border-color: var(--p-border-success-subdued);
141141
background: var(--p-surface-success-subdued);
142142

@@ -155,13 +155,7 @@
155155
background: var(--p-surface-success-subdued);
156156
}
157157
}
158-
// stylelint-enable selector-max-class, selector-max-combinators, selector-max-specificity
159-
}
160-
161-
.ContentWrapper {
162-
margin-top: calc(-1 * var(--p-space-05));
163-
// stylelint-disable-next-line -- generated by polaris-migrator DO NOT COPY
164-
flex: 1 1 auto;
158+
// stylelint-enable selector-max-class, selector-max-specificity
165159
}
166160

167161
.withinContentContainer {
@@ -176,19 +170,11 @@
176170
position: absolute;
177171
}
178172

179-
.Ribbon {
180-
padding-right: var(--p-space-4);
181-
}
182-
183173
@include banner-variants($in-page: false);
184174

185175
+ .Banner {
186176
margin-top: var(--p-space-2);
187177
}
188-
189-
.Actions {
190-
padding: var(--p-space-3) 0 var(--p-space-1) 0;
191-
}
192178
}
193179

194180
.withinPage {
@@ -206,10 +192,6 @@
206192
padding-right: var(--p-space-4);
207193
}
208194

209-
.Actions {
210-
padding-top: var(--p-space-4);
211-
}
212-
213195
.Dismiss {
214196
// stylelint-disable-next-line -- generated by polaris-migrator DO NOT COPY
215197
right: var(--p-space-4);
@@ -225,25 +207,6 @@
225207
padding-right: calc(var(--p-space-8) + var(--p-icon-size-small));
226208
}
227209

228-
.Heading {
229-
word-break: break-word;
230-
}
231-
232-
.Content {
233-
// stylelint-disable-next-line -- generated by polaris-migrator DO NOT COPY
234-
@include text-breakword;
235-
padding: var(--p-space-05) 0;
236-
}
237-
238-
.Ribbon {
239-
// stylelint-disable-next-line -- generated by polaris-migrator DO NOT COPY
240-
flex: 0 0 var(--p-space-8);
241-
}
242-
243-
.PrimaryAction {
244-
margin-right: var(--p-space-2);
245-
}
246-
247210
// We need pretty high specificity to do the descendant selectors
248211
// onto the text, which needs to be the relative positioned wrapper
249212
// so that the borders/ backgrounds do not extend outside of it.

0 commit comments

Comments
 (0)