Skip to content

Commit 7979d03

Browse files
laurkimchazdean
authored andcommitted
[Modal] Rebuild with layout primitives (#7454)
Resolves #7340. Refactors `Modal` and its child components to use our layout primitives. [Storybook URL](https://5d559397bae39100201eedc1-nrruulmwsh.chromatic.com/?path=/story/all-components-modal--default). Refactors `Modal`, `Modal.Section`, `Modal.Header`, and `Modal.Footer` to use our layout primitives and remove css. [Storybook URL](https://5d559397bae39100201eedc1-nrruulmwsh.chromatic.com/?path=/story/all-components-modal--default). I've tophatted all of our stories as well as the UI for all of our breakpoints. 🖥 [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) - [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) - [x] Tested for [accessibility](https://github.com/Shopify/polaris/blob/main/documentation/Accessibility%20testing.md) - [ ] Updated the component's `README.md` with documentation changes - [ ] [Tophatted documentation](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting%20documentation.md) changes in the style guide
1 parent cf68459 commit 7979d03

File tree

11 files changed

+91
-109
lines changed

11 files changed

+91
-109
lines changed

.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

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

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,6 @@
22

33
$small-width: 620px;
44

5-
.BodyWrapper {
6-
display: flex;
7-
flex-grow: 1;
8-
overflow-x: hidden;
9-
-webkit-overflow-scrolling: touch;
10-
}
11-
125
.Body {
136
width: 100%;
147
}
@@ -23,8 +16,3 @@ $small-width: 620px;
2316
max-width: $small-width;
2417
}
2518
}
26-
27-
.Spinner {
28-
margin: var(--p-space-4);
29-
text-align: center;
30-
}

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import {useI18n} from '../../utilities/i18n';
77
import {WithinContentContext} from '../../utilities/within-content-context';
88
import {wrapWithComponent} from '../../utilities/components';
99
import {Backdrop} from '../Backdrop';
10+
import {Box} from '../Box';
11+
import {Inline} from '../Inline';
1012
import {Scrollable} from '../Scrollable';
1113
import {Spinner} from '../Spinner';
1214
import {Portal} from '../Portal';
@@ -153,15 +155,17 @@ export const Modal: React.FunctionComponent<ModalProps> & {
153155
: children;
154156

155157
const body = loading ? (
156-
<div className={styles.Spinner}>
157-
<Spinner />
158-
</div>
158+
<Box padding="4">
159+
<Inline align="center">
160+
<Spinner />
161+
</Inline>
162+
</Box>
159163
) : (
160164
content
161165
);
162166

163167
const scrollContainerMarkup = noScroll ? (
164-
<div className={styles.Body}>{body}</div>
168+
<Box width="100%">{body}</Box>
165169
) : (
166170
<Scrollable
167171
shadow
@@ -206,7 +210,7 @@ export const Modal: React.FunctionComponent<ModalProps> & {
206210
>
207211
{title}
208212
</Header>
209-
<div className={styles.BodyWrapper}>{bodyMarkup}</div>
213+
{bodyMarkup}
210214
{footerMarkup}
211215
</Dialog>
212216
);
@@ -218,7 +222,7 @@ export const Modal: React.FunctionComponent<ModalProps> & {
218222

219223
const activatorMarkup =
220224
activator && !isRef(activator) ? (
221-
<div ref={activatorRef}>{activator}</div>
225+
<Box ref={activatorRef}>{activator}</Box>
222226
) : null;
223227

224228
return (

polaris-react/src/components/Modal/components/Dialog/Dialog.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ export function Dialog({
8888
<div
8989
role="dialog"
9090
aria-modal
91+
aria-label={labelledBy}
9192
aria-labelledby={labelledBy}
9293
tabIndex={-1}
9394
className={styles.Dialog}

polaris-react/src/components/Modal/components/Footer/Footer.scss

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

polaris-react/src/components/Modal/components/Footer/Footer.tsx

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import React from 'react';
33
import type {ComplexAction} from '../../../../types';
44
import {buttonsFrom} from '../../../Button';
55
import {ButtonGroup} from '../../../ButtonGroup';
6-
import {Stack} from '../../../Stack';
7-
8-
import styles from './Footer.scss';
6+
import {Box} from '../../../Box';
7+
import {Columns} from '../../../Columns';
8+
import {Inline} from '../../../Inline';
99

1010
export interface FooterProps {
1111
/** Primary action */
@@ -34,13 +34,18 @@ export function Footer({
3434
) : null;
3535

3636
return (
37-
<div className={styles.Footer}>
38-
<div className={styles.FooterContent}>
39-
<Stack alignment="center">
40-
<Stack.Item fill>{children}</Stack.Item>
37+
<Box
38+
borderBlockStart="divider"
39+
minHeight="var(--p-space-16)"
40+
padding="4"
41+
width="100%"
42+
>
43+
<Columns columns={{xs: '1fr auto'}}>
44+
<Inline alignY="center">{children}</Inline>
45+
<Inline align="end" alignY="center">
4146
{actions}
42-
</Stack>
43-
</div>
44-
</div>
47+
</Inline>
48+
</Columns>
49+
</Box>
4550
);
4651
}
Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,5 @@
1-
@import '../../../../styles/common';
2-
3-
.Header {
4-
display: flex;
5-
align-items: flex-start;
6-
flex-shrink: 0;
7-
padding: var(--p-space-4) var(--p-space-5);
8-
border-bottom: var(--p-border-divider);
9-
}
10-
111
.titleHidden {
122
position: absolute;
133
right: 0;
144
z-index: 1;
15-
width: 100%;
16-
display: flex;
17-
justify-content: flex-end;
18-
19-
.Title {
20-
display: none;
21-
}
22-
}
23-
24-
.Title {
25-
@include text-breakword;
26-
flex: 1;
27-
align-self: center;
285
}
Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import React from 'react';
22

3-
import {Text} from '../../../Text';
3+
import {Box} from '../../../Box';
44
import {CloseButton} from '../CloseButton';
5+
import {Columns} from '../../../Columns';
6+
import {Inline} from '../../../Inline';
7+
import {Text} from '../../../Text';
58

69
import styles from './Header.scss';
710

@@ -13,27 +16,41 @@ export interface HeaderProps {
1316
onClose(): void;
1417
}
1518

16-
export function Header({
17-
id,
18-
titleHidden,
19-
closing,
20-
children,
21-
onClose,
22-
}: HeaderProps) {
19+
export function Header({id, titleHidden, children, onClose}: HeaderProps) {
20+
const titleHiddenMarkup = (
21+
<div className={styles.titleHidden}>
22+
<Inline align="end">
23+
<CloseButton titleHidden={titleHidden} onClick={onClose} />
24+
</Inline>
25+
</div>
26+
);
27+
28+
if (titleHidden || !children) {
29+
return titleHiddenMarkup;
30+
}
31+
2332
return (
24-
<div
25-
className={titleHidden || !children ? styles.titleHidden : styles.Header}
33+
<Box
34+
paddingBlockStart="4"
35+
paddingBlockEnd="4"
36+
paddingInlineStart="5"
37+
paddingInlineEnd="5"
38+
borderBlockEnd="divider"
2639
>
27-
<div id={id} className={styles.Title}>
28-
<Text as="h2" variant="headingLg">
29-
{children}
30-
</Text>
31-
</div>
32-
<CloseButton
33-
pressed={closing}
34-
titleHidden={titleHidden}
35-
onClick={onClose}
36-
/>
37-
</div>
40+
<Columns columns={{xs: '1fr auto'}}>
41+
<Inline>
42+
<Box id={id} paddingBlockStart="1">
43+
<Box paddingBlockStart="05">
44+
<Text as="h2" variant="headingLg" breakWord>
45+
{children}
46+
</Text>
47+
</Box>
48+
</Box>
49+
</Inline>
50+
<Inline>
51+
<CloseButton titleHidden={titleHidden} onClick={onClose} />
52+
</Inline>
53+
</Columns>
54+
</Box>
3855
);
3956
}
Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,13 @@
1-
@import '../../../../styles/common';
2-
31
$close-button-width: calc(var(--p-space-12) + var(--p-space-1));
42

53
.Section {
64
flex: 0 0 auto;
7-
padding: var(--p-space-5);
85

96
&:not(:last-of-type) {
107
border-bottom: var(--p-border-divider);
118
}
9+
}
1210

13-
&.subdued {
14-
background: var(--p-surface-subdued);
15-
}
16-
17-
&.flush {
18-
padding: 0;
19-
}
20-
21-
&.titleHidden {
22-
padding-right: $close-button-width;
23-
}
11+
.titleHidden {
12+
padding-right: $close-button-width;
2413
}

polaris-react/src/components/Modal/components/Section/Section.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
22

3+
import {Box} from '../../../Box';
34
import {classNames} from '../../../../utilities/css';
45

56
import styles from './Section.scss';
@@ -19,10 +20,19 @@ export function Section({
1920
}: SectionProps) {
2021
const className = classNames(
2122
styles.Section,
22-
flush && styles.flush,
23-
subdued && styles.subdued,
2423
titleHidden && styles.titleHidden,
2524
);
2625

27-
return <section className={className}>{children}</section>;
26+
return (
27+
<div className={className}>
28+
<Box
29+
as="section"
30+
padding={flush ? '0' : '5'}
31+
{...(titleHidden && {paddingInlineEnd: '0'})}
32+
{...(subdued && {background: 'surface-subdued'})}
33+
>
34+
{children}
35+
</Box>
36+
</div>
37+
);
2838
}

0 commit comments

Comments
 (0)