Skip to content
This repository was archived by the owner on Sep 30, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/hip-wombats-sin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/polaris': minor
---

Refactored `Modal` and its children components to use layout primitives
12 changes: 0 additions & 12 deletions polaris-react/src/components/Modal/Modal.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@

$small-width: 620px;

.BodyWrapper {
display: flex;
flex-grow: 1;
overflow-x: hidden;
-webkit-overflow-scrolling: touch;
}

.Body {
width: 100%;
}
Expand All @@ -23,8 +16,3 @@ $small-width: 620px;
max-width: $small-width;
}
}

.Spinner {
margin: var(--p-space-4);
text-align: center;
}
16 changes: 10 additions & 6 deletions polaris-react/src/components/Modal/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {useI18n} from '../../utilities/i18n';
import {WithinContentContext} from '../../utilities/within-content-context';
import {wrapWithComponent} from '../../utilities/components';
import {Backdrop} from '../Backdrop';
import {Box} from '../Box';
import {Inline} from '../Inline';
import {Scrollable} from '../Scrollable';
import {Spinner} from '../Spinner';
import {Portal} from '../Portal';
Expand Down Expand Up @@ -152,15 +154,17 @@ export const Modal: React.FunctionComponent<ModalProps> & {
: children;

const body = loading ? (
<div className={styles.Spinner}>
<Spinner />
</div>
<Box padding="4">
<Inline align="center">
<Spinner />
</Inline>
</Box>
) : (
content
);

const scrollContainerMarkup = noScroll ? (
<div className={styles.Body}>{body}</div>
<Box width="100%">{body}</Box>
) : (
<Scrollable
shadow
Expand Down Expand Up @@ -199,7 +203,7 @@ export const Modal: React.FunctionComponent<ModalProps> & {
<Header titleHidden={titleHidden} id={headerId} onClose={onClose}>
{title}
</Header>
<div className={styles.BodyWrapper}>{bodyMarkup}</div>
{bodyMarkup}
{footerMarkup}
</Dialog>
);
Expand All @@ -211,7 +215,7 @@ export const Modal: React.FunctionComponent<ModalProps> & {

const activatorMarkup =
activator && !isRef(activator) ? (
<div ref={activatorRef}>{activator}</div>
<Box ref={activatorRef}>{activator}</Box>
) : null;

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export function Dialog({
<div
role="dialog"
aria-modal
aria-label={labelledBy}
aria-labelledby={labelledBy}
tabIndex={-1}
className={styles.Dialog}
Expand Down
15 changes: 0 additions & 15 deletions polaris-react/src/components/Modal/components/Footer/Footer.scss

This file was deleted.

25 changes: 15 additions & 10 deletions polaris-react/src/components/Modal/components/Footer/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import React from 'react';
import type {ComplexAction} from '../../../../types';
import {buttonsFrom} from '../../../Button';
import {ButtonGroup} from '../../../ButtonGroup';
import {Stack} from '../../../Stack';

import styles from './Footer.scss';
import {Box} from '../../../Box';
import {Columns} from '../../../Columns';
import {Inline} from '../../../Inline';

export interface FooterProps {
/** Primary action */
Expand Down Expand Up @@ -34,13 +34,18 @@ export function Footer({
) : null;

return (
<div className={styles.Footer}>
<div className={styles.FooterContent}>
<Stack alignment="center">
<Stack.Item fill>{children}</Stack.Item>
<Box
borderBlockStart="divider"
minHeight="var(--p-space-16)"
padding="4"
width="100%"
>
<Columns columns={{xs: '1fr auto'}}>
<Inline alignY="center">{children}</Inline>
<Inline align="end" alignY="center">
{actions}
</Stack>
</div>
</div>
</Inline>
</Columns>
</Box>
);
}
23 changes: 0 additions & 23 deletions polaris-react/src/components/Modal/components/Header/Header.scss
Original file line number Diff line number Diff line change
@@ -1,28 +1,5 @@
@import '../../../../styles/common';

.Header {
display: flex;
align-items: flex-start;
flex-shrink: 0;
padding: var(--p-space-4) var(--p-space-5);
border-bottom: var(--p-border-divider);
}

.titleHidden {
position: absolute;
right: 0;
z-index: 1;
width: 100%;
display: flex;
justify-content: flex-end;

.Title {
display: none;
}
}

.Title {
@include text-breakword;
flex: 1;
margin-top: var(--p-space-1);
}
47 changes: 37 additions & 10 deletions polaris-react/src/components/Modal/components/Header/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import React from 'react';

import {DisplayText} from '../../../DisplayText';
import {Box} from '../../../Box';
import {CloseButton} from '../CloseButton';
import {Columns} from '../../../Columns';
import {Inline} from '../../../Inline';
import {Text} from '../../../Text';

import styles from './Header.scss';

Expand All @@ -13,16 +16,40 @@ export interface HeaderProps {
}

export function Header({id, titleHidden, children, onClose}: HeaderProps) {
const titleHiddenMarkup = (
<div className={styles.titleHidden}>
<Inline align="end">
<CloseButton titleHidden={titleHidden} onClick={onClose} />
</Inline>
</div>
);

if (titleHidden || !children) {
return titleHiddenMarkup;
}

return (
<div
className={titleHidden || !children ? styles.titleHidden : styles.Header}
<Box
paddingBlockStart="4"
paddingBlockEnd="4"
paddingInlineStart="5"
paddingInlineEnd="5"
borderBlockEnd="divider"
>
<div id={id} className={styles.Title}>
<DisplayText element="h2" size="small">
{children}
</DisplayText>
</div>
<CloseButton titleHidden={titleHidden} onClick={onClose} />
</div>
<Columns columns={{xs: '1fr auto'}}>
<Inline>
<Box id={id} paddingBlockStart="1">
<Box paddingBlockStart="05">
<Text as="h2" variant="headingLg" breakWord>
{children}
</Text>
</Box>
</Box>
</Inline>
<Inline>
<CloseButton titleHidden={titleHidden} onClick={onClose} />
</Inline>
</Columns>
</Box>
);
}
17 changes: 3 additions & 14 deletions polaris-react/src/components/Modal/components/Section/Section.scss
Original file line number Diff line number Diff line change
@@ -1,24 +1,13 @@
@import '../../../../styles/common';

$close-button-width: calc(var(--p-space-12) + var(--p-space-1));

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

&:not(:last-of-type) {
border-bottom: var(--p-border-divider);
}
}

&.subdued {
background: var(--p-surface-subdued);
}

&.flush {
padding: 0;
}

&.titleHidden {
padding-right: $close-button-width;
}
.titleHidden {
padding-right: $close-button-width;
}
16 changes: 13 additions & 3 deletions polaris-react/src/components/Modal/components/Section/Section.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';

import {Box} from '../../../Box';
import {classNames} from '../../../../utilities/css';

import styles from './Section.scss';
Expand All @@ -19,10 +20,19 @@ export function Section({
}: SectionProps) {
const className = classNames(
styles.Section,
flush && styles.flush,
subdued && styles.subdued,
titleHidden && styles.titleHidden,
);

return <section className={className}>{children}</section>;
return (
<div className={className}>
<Box
as="section"
padding={flush ? '0' : '5'}
{...(titleHidden && {paddingInlineEnd: '0'})}
{...(subdued && {background: 'surface-subdued'})}
>
{children}
</Box>
</div>
);
}
11 changes: 6 additions & 5 deletions polaris-react/src/components/Modal/tests/Modal.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import React, {useRef} from 'react';
import {animationFrame} from '@shopify/jest-dom-mocks';
import {mountWithApp} from 'tests/utilities';

import {Backdrop} from '../../Backdrop';
import {Badge} from '../../Badge';
import {Box} from '../../Box';
import {Button} from '../../Button';
import {Portal} from '../../Portal';
import {Scrollable} from '../../Scrollable';
import {Spinner} from '../../Spinner';
import {Portal} from '../../Portal';
import {Backdrop} from '../../Backdrop';
import {Text} from '../../Text';
import {Footer, Dialog, Header} from '../components';
import {Modal} from '../Modal';
import {WithinContentContext} from '../../../utilities/within-content-context';
Expand Down Expand Up @@ -302,9 +304,7 @@ describe('<Modal>', () => {
<Modal onClose={jest.fn()} open title="foo" />,
);

expect(modal.find(Header)).toContainReactComponent('div', {
className: 'Header',
});
expect(modal.find(Box)).toContainReactComponent(Text);
});

it('only renders a close button when titleHidden is present', () => {
Expand All @@ -315,6 +315,7 @@ describe('<Modal>', () => {
expect(modal.find(Header)).toContainReactComponent('div', {
className: 'titleHidden',
});
expect(modal.find(Header)).not.toContainReactComponent(Box);
});
});

Expand Down