Skip to content

Commit abeef7a

Browse files
authored
[Modal] Replace boolean props (#10261)
Fixes #10259
1 parent 22a51ea commit abeef7a

File tree

9 files changed

+40
-38
lines changed

9 files changed

+40
-38
lines changed

.changeset/moody-terms-provide.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@shopify/polaris': major
3+
---
4+
5+
Replaced `small`, `large`, and `fullScreen` props with `size` prop

documentation/guides/migrating-from-v11-to-v12.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,11 @@ Polaris v12.0.0 ([full release notes](https://github.com/Shopify/polaris/release
9797
`npx @shopify/polaris-migrator react-rename-component-prop <path> --componentName="Text" --from="color" --to="tone"`
9898

9999
`npx @shopify/polaris-migrator react-rename-component-prop <path> --componentName="Text" --from="tone" --to="tone" --fromValue="warning" --toValue="caution"`
100+
101+
**Modal**
102+
103+
`npx @shopify/polaris-migrator react-rename-component-prop <path> --componentName="Modal" --from="small" --to="size" --newValue="small"`
104+
105+
`npx @shopify/polaris-migrator react-rename-component-prop <path> --componentName="Modal" --from="large" --to="size" --newValue="large"`
106+
107+
`npx @shopify/polaris-migrator react-rename-component-prop <path> --componentName="Modal" --from="fullScreen" --to="size" --newValue="fullScreen"`

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ export function Large() {
217217
return (
218218
<div style={{height: '500px'}}>
219219
<Modal
220-
large
220+
size="large"
221221
activator={activator}
222222
open={active}
223223
onClose={toggleActive}
@@ -268,7 +268,7 @@ export function Small() {
268268
return (
269269
<div style={{height: '500px'}}>
270270
<Modal
271-
small
271+
size="small"
272272
activator={activator}
273273
open={active}
274274
onClose={toggleActive}
@@ -638,7 +638,7 @@ export function Fullscreen() {
638638
open
639639
onClose={() => {}}
640640
sectioned
641-
fullScreen
641+
size="fullScreen"
642642
primaryAction={{content: 'Save'}}
643643
>
644644
<Text as="h1">Fullscreen on small displays</Text>

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

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import styles from './Modal.scss';
1919
const IFRAME_LOADING_HEIGHT = 200;
2020
const DEFAULT_IFRAME_CONTENT_HEIGHT = 400;
2121

22+
export type ModalSize = 'small' | 'large' | 'fullScreen';
23+
2224
export interface ModalProps extends FooterProps {
2325
/** Whether the modal is open or not */
2426
open: boolean;
@@ -41,10 +43,8 @@ export interface ModalProps extends FooterProps {
4143
instant?: boolean;
4244
/** Automatically adds sections to modal */
4345
sectioned?: boolean;
44-
/** Increases the modal width */
45-
large?: boolean;
46-
/** Decreases the modal width */
47-
small?: boolean;
46+
/** The size of the modal */
47+
size?: ModalSize;
4848
/** Limits modal height on large sceens with scrolling */
4949
limitHeight?: boolean;
5050
/** Replaces modal content with a spinner while a background action is being performed */
@@ -61,8 +61,6 @@ export interface ModalProps extends FooterProps {
6161
activator?: React.RefObject<HTMLElement> | React.ReactElement;
6262
/** Removes Scrollable container from the modal content */
6363
noScroll?: boolean;
64-
/** Sets modal to the height of the viewport on small screens */
65-
fullScreen?: boolean;
6664
}
6765

6866
export const Modal: React.FunctionComponent<ModalProps> & {
@@ -77,8 +75,7 @@ export const Modal: React.FunctionComponent<ModalProps> & {
7775
instant,
7876
sectioned,
7977
loading,
80-
large,
81-
small,
78+
size,
8279
limitHeight,
8380
footer,
8481
primaryAction,
@@ -89,7 +86,6 @@ export const Modal: React.FunctionComponent<ModalProps> & {
8986
onIFrameLoad,
9087
onTransitionEnd,
9188
noScroll,
92-
fullScreen,
9389
}: ModalProps) {
9490
const [iframeHeight, setIframeHeight] = useState(IFRAME_LOADING_HEIGHT);
9591
const [closing, setClosing] = useState(false);
@@ -198,10 +194,8 @@ export const Modal: React.FunctionComponent<ModalProps> & {
198194
onClose={onClose}
199195
onEntered={handleEntered}
200196
onExited={handleExited}
201-
large={large}
202-
small={small}
197+
size={size}
203198
limitHeight={limitHeight}
204-
fullScreen={fullScreen}
205199
setClosing={setClosing}
206200
>
207201
<Header

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ $large-width: 980px;
8989
}
9090
}
9191

92-
&.fullScreen {
92+
&.sizeFullScreen {
9393
height: 100%;
9494
@media #{$p-breakpoints-md-up} {
9595
height: unset;

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

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ import type {SetStateAction, Dispatch} from 'react';
33
import {Transition, CSSTransition} from 'react-transition-group';
44
import {motion} from '@shopify/polaris-tokens';
55

6-
import {classNames} from '../../../../utilities/css';
6+
import {classNames, variationName} from '../../../../utilities/css';
77
import {focusFirstFocusableNode} from '../../../../utilities/focus';
88
import {Key} from '../../../../types';
99
import {KeypressListener} from '../../../KeypressListener';
1010
import {TrapFocus} from '../../../TrapFocus';
11+
import type {ModalSize} from '../../Modal';
1112

1213
import styles from './Dialog.scss';
1314

@@ -18,37 +19,31 @@ export interface DialogProps {
1819
instant?: boolean;
1920
children?: React.ReactNode;
2021
limitHeight?: boolean;
21-
large?: boolean;
22-
small?: boolean;
22+
size?: ModalSize;
2323
onClose(): void;
2424
onEntered?(): void;
2525
onExited?(): void;
2626
in?: boolean;
27-
fullScreen?: boolean;
2827
setClosing?: Dispatch<SetStateAction<boolean>>;
2928
}
3029

3130
export function Dialog({
3231
instant,
3332
labelledBy,
3433
children,
34+
limitHeight,
35+
size,
3536
onClose,
3637
onExited,
3738
onEntered,
38-
large,
39-
small,
40-
limitHeight,
41-
fullScreen,
4239
setClosing,
4340
...props
4441
}: DialogProps) {
4542
const containerNode = useRef<HTMLDivElement>(null);
4643
const classes = classNames(
4744
styles.Modal,
48-
small && styles.sizeSmall,
49-
large && styles.sizeLarge,
45+
size && styles[variationName('size', size)],
5046
limitHeight && styles.limitHeight,
51-
fullScreen && styles.fullScreen,
5247
);
5348
const TransitionChild = instant ? Transition : FadeUp;
5449

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,12 @@ describe('<Modal>', () => {
159159
describe('large', () => {
160160
it('passes large to Dialog if true', () => {
161161
const modal = mountWithApp(
162-
<Modal title="foo" large onClose={jest.fn()} open>
162+
<Modal title="foo" size="large" onClose={jest.fn()} open>
163163
<Badge />
164164
</Modal>,
165165
);
166166

167-
expect(modal).toContainReactComponent(Dialog, {large: true});
167+
expect(modal).toContainReactComponent(Dialog, {size: 'large'});
168168
});
169169

170170
it('does not pass large to Dialog be default', () => {
@@ -174,19 +174,19 @@ describe('<Modal>', () => {
174174
</Modal>,
175175
);
176176

177-
expect(modal).toContainReactComponent(Dialog, {large: undefined});
177+
expect(modal).toContainReactComponent(Dialog, {size: undefined});
178178
});
179179
});
180180

181181
describe('small', () => {
182182
it('passes small to Dialog if true', () => {
183183
const modal = mountWithApp(
184-
<Modal title="foo" small onClose={jest.fn()} open>
184+
<Modal title="foo" size="small" onClose={jest.fn()} open>
185185
<Badge />
186186
</Modal>,
187187
);
188188

189-
expect(modal).toContainReactComponent(Dialog, {small: true});
189+
expect(modal).toContainReactComponent(Dialog, {size: 'small'});
190190
});
191191

192192
it('does not pass small to Dialog by default', () => {
@@ -196,7 +196,7 @@ describe('<Modal>', () => {
196196
</Modal>,
197197
);
198198

199-
expect(modal).toContainReactComponent(Dialog, {small: undefined});
199+
expect(modal).toContainReactComponent(Dialog, {size: undefined});
200200
});
201201
});
202202

@@ -225,12 +225,12 @@ describe('<Modal>', () => {
225225
describe('fullScreen', () => {
226226
it('passes fullScreen to Dialog if true', () => {
227227
const modal = mountWithApp(
228-
<Modal title="foo" fullScreen onClose={jest.fn()} open>
228+
<Modal title="foo" size="fullScreen" onClose={jest.fn()} open>
229229
<Badge />
230230
</Modal>,
231231
);
232232

233-
expect(modal).toContainReactComponent(Dialog, {fullScreen: true});
233+
expect(modal).toContainReactComponent(Dialog, {size: 'fullScreen'});
234234
});
235235

236236
it('does not pass fullScreen to Dialog be default', () => {
@@ -240,7 +240,7 @@ describe('<Modal>', () => {
240240
</Modal>,
241241
);
242242

243-
expect(modal).toContainReactComponent(Dialog, {fullScreen: undefined});
243+
expect(modal).toContainReactComponent(Dialog, {size: undefined});
244244
});
245245
});
246246

polaris.shopify.com/pages/examples/modal-large.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function LargeModalExample() {
1515
return (
1616
<div style={{height: '500px'}}>
1717
<Modal
18-
large
18+
size="large"
1919
activator={activator}
2020
open={active}
2121
onClose={toggleActive}

polaris.shopify.com/pages/examples/modal-small.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function SmallModalExample() {
1515
return (
1616
<div style={{height: '500px'}}>
1717
<Modal
18-
small
18+
size="small"
1919
activator={activator}
2020
open={active}
2121
onClose={toggleActive}

0 commit comments

Comments
 (0)