@atlaskit/modal-dialog 12.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2111 -0
- package/LICENSE +13 -0
- package/README.md +13 -0
- package/__perf__/default.tsx +42 -0
- package/__perf__/interactions.tsx +136 -0
- package/__perf__/scroll.tsx +98 -0
- package/codemods/12.0.0-lite-mode.ts +51 -0
- package/codemods/__tests__/12.0.0-lite-mode.test.ts +493 -0
- package/codemods/__tests__/handle-prop-spread.tsx +276 -0
- package/codemods/__tests__/inline-WidthNames-declaration.test.ts +260 -0
- package/codemods/__tests__/map-actions-prop.tsx +436 -0
- package/codemods/__tests__/map-body-from-props.test.ts +645 -0
- package/codemods/__tests__/map-container-from-props.test.ts +323 -0
- package/codemods/__tests__/map-footer-from-props.test.ts +544 -0
- package/codemods/__tests__/map-header-from-props.test.ts +559 -0
- package/codemods/__tests__/map-heading-prop.tsx +438 -0
- package/codemods/__tests__/remove-appearance-prop.test.ts +79 -0
- package/codemods/__tests__/remove-component-override-props.test.ts +153 -0
- package/codemods/__tests__/remove-is-chromeless.tsx +182 -0
- package/codemods/__tests__/rename-appearance-type.test.ts +52 -0
- package/codemods/__tests__/rename-inner-component-prop-types.test.ts +82 -0
- package/codemods/__tests__/rename-scrollBehavior-to-shouldScrollInViewport.test.ts +237 -0
- package/codemods/internal/constants.tsx +41 -0
- package/codemods/internal/utils.tsx +223 -0
- package/codemods/migrations/handle-prop-spread.tsx +51 -0
- package/codemods/migrations/inline-WidthNames-declaration.ts +92 -0
- package/codemods/migrations/map-actions-prop.tsx +430 -0
- package/codemods/migrations/map-body-from-props.ts +147 -0
- package/codemods/migrations/map-container-from-props.ts +72 -0
- package/codemods/migrations/map-footer-from-props.ts +107 -0
- package/codemods/migrations/map-header-from-props.ts +101 -0
- package/codemods/migrations/map-heading-prop.tsx +193 -0
- package/codemods/migrations/remove-appearance-prop.ts +27 -0
- package/codemods/migrations/remove-component-override-props.ts +84 -0
- package/codemods/migrations/remove-is-chromeless.tsx +42 -0
- package/codemods/migrations/rename-appearance-type.ts +9 -0
- package/codemods/migrations/rename-inner-component-prop-types.ts +28 -0
- package/codemods/migrations/rename-scrollBehavior-to-shouldScrollInViewport.ts +82 -0
- package/dist/cjs/hooks.js +22 -0
- package/dist/cjs/index.js +63 -0
- package/dist/cjs/internal/components/modal-dialog.js +155 -0
- package/dist/cjs/internal/components/positioner.js +89 -0
- package/dist/cjs/internal/components/scroll-container.js +138 -0
- package/dist/cjs/internal/constants.js +48 -0
- package/dist/cjs/internal/context.js +13 -0
- package/dist/cjs/internal/hooks/use-modal-stack.js +110 -0
- package/dist/cjs/internal/hooks/use-on-motion-finish.js +24 -0
- package/dist/cjs/internal/hooks/use-prevent-programmatic-scroll.js +55 -0
- package/dist/cjs/internal/hooks/use-scroll.js +20 -0
- package/dist/cjs/internal/utils.js +35 -0
- package/dist/cjs/modal-body.js +66 -0
- package/dist/cjs/modal-footer.js +40 -0
- package/dist/cjs/modal-header.js +43 -0
- package/dist/cjs/modal-title.js +108 -0
- package/dist/cjs/modal-transition.js +21 -0
- package/dist/cjs/modal-wrapper.js +126 -0
- package/dist/cjs/types.js +5 -0
- package/dist/cjs/version.json +5 -0
- package/dist/es2019/hooks.js +11 -0
- package/dist/es2019/index.js +7 -0
- package/dist/es2019/internal/components/modal-dialog.js +120 -0
- package/dist/es2019/internal/components/positioner.js +78 -0
- package/dist/es2019/internal/components/scroll-container.js +97 -0
- package/dist/es2019/internal/constants.js +27 -0
- package/dist/es2019/internal/context.js +3 -0
- package/dist/es2019/internal/hooks/use-modal-stack.js +85 -0
- package/dist/es2019/internal/hooks/use-on-motion-finish.js +17 -0
- package/dist/es2019/internal/hooks/use-prevent-programmatic-scroll.js +39 -0
- package/dist/es2019/internal/hooks/use-scroll.js +11 -0
- package/dist/es2019/internal/utils.js +22 -0
- package/dist/es2019/modal-body.js +50 -0
- package/dist/es2019/modal-footer.js +30 -0
- package/dist/es2019/modal-header.js +30 -0
- package/dist/es2019/modal-title.js +94 -0
- package/dist/es2019/modal-transition.js +10 -0
- package/dist/es2019/modal-wrapper.js +88 -0
- package/dist/es2019/types.js +1 -0
- package/dist/es2019/version.json +5 -0
- package/dist/esm/hooks.js +11 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/internal/components/modal-dialog.js +131 -0
- package/dist/esm/internal/components/positioner.js +76 -0
- package/dist/esm/internal/components/scroll-container.js +114 -0
- package/dist/esm/internal/constants.js +27 -0
- package/dist/esm/internal/context.js +3 -0
- package/dist/esm/internal/hooks/use-modal-stack.js +96 -0
- package/dist/esm/internal/hooks/use-on-motion-finish.js +16 -0
- package/dist/esm/internal/hooks/use-prevent-programmatic-scroll.js +44 -0
- package/dist/esm/internal/hooks/use-scroll.js +11 -0
- package/dist/esm/internal/utils.js +22 -0
- package/dist/esm/modal-body.js +49 -0
- package/dist/esm/modal-footer.js +29 -0
- package/dist/esm/modal-header.js +29 -0
- package/dist/esm/modal-title.js +93 -0
- package/dist/esm/modal-transition.js +10 -0
- package/dist/esm/modal-wrapper.js +96 -0
- package/dist/esm/types.js +1 -0
- package/dist/esm/version.json +5 -0
- package/dist/types/hooks.d.ts +1 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/types/internal/components/modal-dialog.d.ts +3 -0
- package/dist/types/internal/components/positioner.d.ts +10 -0
- package/dist/types/internal/components/scroll-container.d.ts +20 -0
- package/dist/types/internal/constants.d.ts +25 -0
- package/dist/types/internal/context.d.ts +20 -0
- package/dist/types/internal/hooks/use-modal-stack.d.ts +13 -0
- package/dist/types/internal/hooks/use-on-motion-finish.d.ts +4 -0
- package/dist/types/internal/hooks/use-prevent-programmatic-scroll.d.ts +7 -0
- package/dist/types/internal/hooks/use-scroll.d.ts +1 -0
- package/dist/types/internal/utils.d.ts +3 -0
- package/dist/types/modal-body.d.ts +16 -0
- package/dist/types/modal-footer.d.ts +16 -0
- package/dist/types/modal-header.d.ts +16 -0
- package/dist/types/modal-title.d.ts +26 -0
- package/dist/types/modal-transition.d.ts +3 -0
- package/dist/types/modal-wrapper.d.ts +5 -0
- package/dist/types/types.d.ts +90 -0
- package/extract-react-types/modal-attributes.tsx +5 -0
- package/hooks/package.json +7 -0
- package/modal-body/package.json +7 -0
- package/modal-dialog/package.json +7 -0
- package/modal-footer/package.json +7 -0
- package/modal-header/package.json +7 -0
- package/modal-title/package.json +7 -0
- package/modal-transition/package.json +7 -0
- package/package.json +113 -0
- package/types/package.json +7 -0
|
@@ -0,0 +1,436 @@
|
|
|
1
|
+
import { createTransformer } from '@atlaskit/codemod-utils';
|
|
2
|
+
|
|
3
|
+
import { mapActionsProp } from '../migrations/map-actions-prop';
|
|
4
|
+
|
|
5
|
+
const transformer = createTransformer([mapActionsProp]);
|
|
6
|
+
|
|
7
|
+
const defineInlineTest = require('jscodeshift/dist/testUtils').defineInlineTest;
|
|
8
|
+
|
|
9
|
+
describe('map actions prop', () => {
|
|
10
|
+
['tsx', 'babylon'].forEach((parser) => {
|
|
11
|
+
describe(`parser: ${parser}`, () => {
|
|
12
|
+
defineInlineTest(
|
|
13
|
+
{ default: transformer, parser },
|
|
14
|
+
{},
|
|
15
|
+
`
|
|
16
|
+
import React, { useState } from 'react';
|
|
17
|
+
import Modal, { ModalTransition } from '@atlaskit/modal-dialog';
|
|
18
|
+
|
|
19
|
+
const DefaultModal = () => {
|
|
20
|
+
const [isOpen, setIsOpen] = useState(true);
|
|
21
|
+
const close = () => setIsOpen(false);
|
|
22
|
+
const actions = [
|
|
23
|
+
{ text: 'Close', onClick: close, testId: 'primary' },
|
|
24
|
+
{
|
|
25
|
+
text: 'Secondary Action',
|
|
26
|
+
onClick: ()=>{},
|
|
27
|
+
testId: 'secondary',
|
|
28
|
+
},
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<ModalTransition>
|
|
33
|
+
{isOpen && (
|
|
34
|
+
<Modal
|
|
35
|
+
actions={actions}
|
|
36
|
+
onClose={close}
|
|
37
|
+
>
|
|
38
|
+
<p>modal body</p>
|
|
39
|
+
</Modal>
|
|
40
|
+
)}
|
|
41
|
+
</ModalTransition>
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
`,
|
|
45
|
+
`
|
|
46
|
+
import React, { useState } from 'react';
|
|
47
|
+
import Button from "@atlaskit/button/standard-button";
|
|
48
|
+
import Modal, { ModalTransition, ModalFooter } from "@atlaskit/modal-dialog";
|
|
49
|
+
|
|
50
|
+
const DefaultModal = () => {
|
|
51
|
+
const [isOpen, setIsOpen] = useState(true);
|
|
52
|
+
const close = () => setIsOpen(false);
|
|
53
|
+
const actions = [
|
|
54
|
+
{ text: 'Close', onClick: close, testId: 'primary' },
|
|
55
|
+
{
|
|
56
|
+
text: 'Secondary Action',
|
|
57
|
+
onClick: ()=>{},
|
|
58
|
+
testId: 'secondary',
|
|
59
|
+
},
|
|
60
|
+
];
|
|
61
|
+
|
|
62
|
+
return (
|
|
63
|
+
<ModalTransition>
|
|
64
|
+
{isOpen && (
|
|
65
|
+
(<Modal onClose={close}>
|
|
66
|
+
<p>modal body</p>
|
|
67
|
+
<ModalFooter>
|
|
68
|
+
{actions.map((props, index) => <Button
|
|
69
|
+
{...props}
|
|
70
|
+
autoFocus={index === 0}
|
|
71
|
+
appearance={index === 0 ? "primary" : "subtle"}>{props.text}</Button>).reverse()}
|
|
72
|
+
</ModalFooter>
|
|
73
|
+
</Modal>)
|
|
74
|
+
)}
|
|
75
|
+
</ModalTransition>
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
`,
|
|
79
|
+
`should map the actions prop to ModalFooter buttons, add autoFocus primary button, flip buttons when appearance is not present on actions`,
|
|
80
|
+
);
|
|
81
|
+
defineInlineTest(
|
|
82
|
+
{ default: transformer, parser },
|
|
83
|
+
{},
|
|
84
|
+
`
|
|
85
|
+
import React, { useState } from 'react';
|
|
86
|
+
import Modal, { ModalTransition } from '@atlaskit/modal-dialog';
|
|
87
|
+
const actions = [];
|
|
88
|
+
const DefaultModal = () => {
|
|
89
|
+
const [isOpen, setIsOpen] = useState(true);
|
|
90
|
+
const close = () => setIsOpen(false);
|
|
91
|
+
const actions = [
|
|
92
|
+
{ text: 'Close', onClick: close, testId: 'primary' },
|
|
93
|
+
{
|
|
94
|
+
text: 'Secondary Action',
|
|
95
|
+
onClick: ()=>{},
|
|
96
|
+
testId: 'secondary',
|
|
97
|
+
},
|
|
98
|
+
];
|
|
99
|
+
|
|
100
|
+
return (
|
|
101
|
+
<ModalTransition>
|
|
102
|
+
{isOpen && (
|
|
103
|
+
<Modal
|
|
104
|
+
actions={actions}
|
|
105
|
+
onClose={close}
|
|
106
|
+
>
|
|
107
|
+
<p>modal body</p>
|
|
108
|
+
</Modal>
|
|
109
|
+
)}
|
|
110
|
+
</ModalTransition>
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
`,
|
|
114
|
+
`
|
|
115
|
+
import React, { useState } from 'react';
|
|
116
|
+
import Button from "@atlaskit/button/standard-button";
|
|
117
|
+
import Modal, { ModalTransition, ModalFooter } from "@atlaskit/modal-dialog";
|
|
118
|
+
const actions = [];
|
|
119
|
+
const DefaultModal = () => {
|
|
120
|
+
const [isOpen, setIsOpen] = useState(true);
|
|
121
|
+
const close = () => setIsOpen(false);
|
|
122
|
+
const actions = [
|
|
123
|
+
{ text: 'Close', onClick: close, testId: 'primary' },
|
|
124
|
+
{
|
|
125
|
+
text: 'Secondary Action',
|
|
126
|
+
onClick: ()=>{},
|
|
127
|
+
testId: 'secondary',
|
|
128
|
+
},
|
|
129
|
+
];
|
|
130
|
+
|
|
131
|
+
return (
|
|
132
|
+
<ModalTransition>
|
|
133
|
+
{isOpen && (
|
|
134
|
+
/* TODO: (from codemod)\u0020
|
|
135
|
+
In this codemod, we are moving the position of the primary button to the right-hand side of
|
|
136
|
+
modal footer to align with the design guidelines while we convert your usage of 'actions' prop.
|
|
137
|
+
|
|
138
|
+
However, we could not definitively determine if the 'appearance' prop has been included in the 'actions' prop in this file,
|
|
139
|
+
so in this case, we have converted the 'actions' prop into Button components without moving the position of the primary button.
|
|
140
|
+
To complete the migration and align with the design guidelines, please make the necessary changes manually. */
|
|
141
|
+
(<Modal onClose={close}>
|
|
142
|
+
<p>modal body</p>
|
|
143
|
+
<ModalFooter>
|
|
144
|
+
{actions.map((props, index) => <Button
|
|
145
|
+
{...props}
|
|
146
|
+
appearance={index === 0 ? props.appearance || "primary" : props.appearance || "subtle"}>{props.text}</Button>)}
|
|
147
|
+
</ModalFooter>
|
|
148
|
+
</Modal>)
|
|
149
|
+
)}
|
|
150
|
+
</ModalTransition>
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
`,
|
|
154
|
+
`should add the comment when there are multiple variables as with same name as actions prop`,
|
|
155
|
+
);
|
|
156
|
+
defineInlineTest(
|
|
157
|
+
{ default: transformer, parser },
|
|
158
|
+
{},
|
|
159
|
+
`
|
|
160
|
+
import React, { useState } from 'react';
|
|
161
|
+
import Modal, { ModalTransition } from '@atlaskit/modal-dialog';
|
|
162
|
+
|
|
163
|
+
const DefaultModal = () => {
|
|
164
|
+
const [isOpen, setIsOpen] = useState(true);
|
|
165
|
+
const close = () => setIsOpen(false);
|
|
166
|
+
const actions = [
|
|
167
|
+
{ text: 'Close', onClick: close, testId: 'primary', appearance:'some-appearance' },
|
|
168
|
+
{
|
|
169
|
+
text: 'Secondary Action',
|
|
170
|
+
onClick: ()=>{},
|
|
171
|
+
testId: 'secondary',
|
|
172
|
+
},
|
|
173
|
+
];
|
|
174
|
+
|
|
175
|
+
return (
|
|
176
|
+
<ModalTransition>
|
|
177
|
+
{isOpen && (
|
|
178
|
+
<Modal
|
|
179
|
+
actions={actions}
|
|
180
|
+
onClose={close}
|
|
181
|
+
>
|
|
182
|
+
<p>modal body</p>
|
|
183
|
+
</Modal>
|
|
184
|
+
)}
|
|
185
|
+
</ModalTransition>
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
`,
|
|
189
|
+
`
|
|
190
|
+
import React, { useState } from 'react';
|
|
191
|
+
import Button from "@atlaskit/button/standard-button";
|
|
192
|
+
import Modal, { ModalTransition, ModalFooter } from "@atlaskit/modal-dialog";
|
|
193
|
+
|
|
194
|
+
const DefaultModal = () => {
|
|
195
|
+
const [isOpen, setIsOpen] = useState(true);
|
|
196
|
+
const close = () => setIsOpen(false);
|
|
197
|
+
const actions = [
|
|
198
|
+
{ text: 'Close', onClick: close, testId: 'primary', appearance:'some-appearance' },
|
|
199
|
+
{
|
|
200
|
+
text: 'Secondary Action',
|
|
201
|
+
onClick: ()=>{},
|
|
202
|
+
testId: 'secondary',
|
|
203
|
+
},
|
|
204
|
+
];
|
|
205
|
+
|
|
206
|
+
return (
|
|
207
|
+
<ModalTransition>
|
|
208
|
+
{isOpen && (
|
|
209
|
+
(<Modal onClose={close}>
|
|
210
|
+
<p>modal body</p>
|
|
211
|
+
<ModalFooter>
|
|
212
|
+
{actions.map((props, index) => <Button
|
|
213
|
+
{...props}
|
|
214
|
+
appearance={index === 0 ? props.appearance || "primary" : props.appearance || "subtle"}>{props.text}</Button>)}
|
|
215
|
+
</ModalFooter>
|
|
216
|
+
</Modal>)
|
|
217
|
+
)}
|
|
218
|
+
</ModalTransition>
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
`,
|
|
222
|
+
`should map the actions prop to ModalFooter buttons, shouldn't autoFocus primary button, shouldn't flip buttons when appearance is present on any actions item`,
|
|
223
|
+
);
|
|
224
|
+
defineInlineTest(
|
|
225
|
+
{ default: transformer, parser },
|
|
226
|
+
{},
|
|
227
|
+
`
|
|
228
|
+
import React, { useState } from 'react';
|
|
229
|
+
import Modal, { ModalTransition } from '@atlaskit/modal-dialog';
|
|
230
|
+
import Button from "@atlaskit/button/standard-button";
|
|
231
|
+
|
|
232
|
+
const DefaultModal = () => {
|
|
233
|
+
const [isOpen, setIsOpen] = useState(true);
|
|
234
|
+
const close = () => setIsOpen(false);
|
|
235
|
+
|
|
236
|
+
return (
|
|
237
|
+
<ModalTransition>
|
|
238
|
+
{isOpen && (
|
|
239
|
+
<Modal
|
|
240
|
+
actions={[
|
|
241
|
+
{ text: 'Close', onClick: close, testId: 'primary' },
|
|
242
|
+
{
|
|
243
|
+
text: 'Secondary Action',
|
|
244
|
+
onClick: ()=>{},
|
|
245
|
+
},
|
|
246
|
+
]}
|
|
247
|
+
onClose={close}
|
|
248
|
+
appearance="danger"
|
|
249
|
+
>
|
|
250
|
+
<p>modal body</p>
|
|
251
|
+
</Modal>
|
|
252
|
+
)}
|
|
253
|
+
</ModalTransition>
|
|
254
|
+
);
|
|
255
|
+
}
|
|
256
|
+
`,
|
|
257
|
+
`
|
|
258
|
+
import React, { useState } from 'react';
|
|
259
|
+
import Modal, { ModalTransition, ModalFooter } from "@atlaskit/modal-dialog";
|
|
260
|
+
import Button from "@atlaskit/button/standard-button";
|
|
261
|
+
|
|
262
|
+
const DefaultModal = () => {
|
|
263
|
+
const [isOpen, setIsOpen] = useState(true);
|
|
264
|
+
const close = () => setIsOpen(false);
|
|
265
|
+
|
|
266
|
+
return (
|
|
267
|
+
<ModalTransition>
|
|
268
|
+
{isOpen && (
|
|
269
|
+
(<Modal onClose={close} appearance="danger">
|
|
270
|
+
<p>modal body</p>
|
|
271
|
+
<ModalFooter>
|
|
272
|
+
{[
|
|
273
|
+
{ text: 'Close', onClick: close, testId: 'primary' },
|
|
274
|
+
{
|
|
275
|
+
text: 'Secondary Action',
|
|
276
|
+
onClick: ()=>{},
|
|
277
|
+
},
|
|
278
|
+
].map((props, index) => <Button
|
|
279
|
+
{...props}
|
|
280
|
+
autoFocus={index === 0}
|
|
281
|
+
appearance={index === 0 ? "danger" || "primary" : "subtle"}>{props.text}</Button>).reverse()}
|
|
282
|
+
</ModalFooter>
|
|
283
|
+
</Modal>)
|
|
284
|
+
)}
|
|
285
|
+
</ModalTransition>
|
|
286
|
+
);
|
|
287
|
+
}
|
|
288
|
+
`,
|
|
289
|
+
`should map the actions prop to ModalFooter buttons and take apperance prop from modal, should autoFocus primary button and flip actions buttons `,
|
|
290
|
+
);
|
|
291
|
+
defineInlineTest(
|
|
292
|
+
{ default: transformer, parser },
|
|
293
|
+
{},
|
|
294
|
+
`
|
|
295
|
+
import React, { useState } from 'react';
|
|
296
|
+
import Modal, { ModalTransition } from '@atlaskit/modal-dialog';
|
|
297
|
+
|
|
298
|
+
const DefaultModal = () => {
|
|
299
|
+
const [isOpen, setIsOpen] = useState(true);
|
|
300
|
+
const close = () => setIsOpen(false);
|
|
301
|
+
const secondaryAction = () => alert('Secondary button has been clicked!');
|
|
302
|
+
const actions = [
|
|
303
|
+
{ text: 'Close', onClick: close, testId: 'primary', appearance: "primary" },
|
|
304
|
+
{
|
|
305
|
+
text: 'Secondary Action',
|
|
306
|
+
onClick: secondaryAction,
|
|
307
|
+
testId: 'secondary',
|
|
308
|
+
appearance: "subtle"
|
|
309
|
+
},
|
|
310
|
+
];
|
|
311
|
+
|
|
312
|
+
const appearanceValue = 'danger'
|
|
313
|
+
|
|
314
|
+
return (
|
|
315
|
+
<ModalTransition>
|
|
316
|
+
{isOpen && (
|
|
317
|
+
<Modal
|
|
318
|
+
actions={actions}
|
|
319
|
+
onClose={close}
|
|
320
|
+
testId="modal"
|
|
321
|
+
appearance={appearanceValue}
|
|
322
|
+
>
|
|
323
|
+
<p>modal body</p>
|
|
324
|
+
</Modal>
|
|
325
|
+
)}
|
|
326
|
+
</ModalTransition>
|
|
327
|
+
);
|
|
328
|
+
}
|
|
329
|
+
`,
|
|
330
|
+
`
|
|
331
|
+
import React, { useState } from 'react';
|
|
332
|
+
import Button from "@atlaskit/button/standard-button";
|
|
333
|
+
import Modal, { ModalTransition, ModalFooter } from "@atlaskit/modal-dialog";
|
|
334
|
+
|
|
335
|
+
const DefaultModal = () => {
|
|
336
|
+
const [isOpen, setIsOpen] = useState(true);
|
|
337
|
+
const close = () => setIsOpen(false);
|
|
338
|
+
const secondaryAction = () => alert('Secondary button has been clicked!');
|
|
339
|
+
const actions = [
|
|
340
|
+
{ text: 'Close', onClick: close, testId: 'primary', appearance: "primary" },
|
|
341
|
+
{
|
|
342
|
+
text: 'Secondary Action',
|
|
343
|
+
onClick: secondaryAction,
|
|
344
|
+
testId: 'secondary',
|
|
345
|
+
appearance: "subtle"
|
|
346
|
+
},
|
|
347
|
+
];
|
|
348
|
+
|
|
349
|
+
const appearanceValue = 'danger'
|
|
350
|
+
|
|
351
|
+
return (
|
|
352
|
+
<ModalTransition>
|
|
353
|
+
{isOpen && (
|
|
354
|
+
(<Modal onClose={close} testId="modal" appearance={appearanceValue}>
|
|
355
|
+
<p>modal body</p>
|
|
356
|
+
<ModalFooter>
|
|
357
|
+
{actions.map((props, index) => <Button
|
|
358
|
+
{...props}
|
|
359
|
+
appearance={index === 0 ? props.appearance || appearanceValue || "primary" : props.appearance || "subtle"}>{props.text}</Button>)}
|
|
360
|
+
</ModalFooter>
|
|
361
|
+
</Modal>)
|
|
362
|
+
)}
|
|
363
|
+
</ModalTransition>
|
|
364
|
+
);
|
|
365
|
+
}
|
|
366
|
+
`,
|
|
367
|
+
`should map the actions prop to ModalFooter buttons, not take apperance prop from modal, not add autoFocus and not flip buttons when apperance is defined in actions`,
|
|
368
|
+
);
|
|
369
|
+
|
|
370
|
+
defineInlineTest(
|
|
371
|
+
{ default: transformer, parser },
|
|
372
|
+
{},
|
|
373
|
+
`
|
|
374
|
+
import React, { useState } from 'react';
|
|
375
|
+
import Modal, { ModalTransition } from '@atlaskit/modal-dialog';
|
|
376
|
+
|
|
377
|
+
import { getModalDialogActions } from './utils';
|
|
378
|
+
|
|
379
|
+
const DefaultModal = () => {
|
|
380
|
+
const [isOpen, setIsOpen] = useState(true);
|
|
381
|
+
const close = () => setIsOpen(false);
|
|
382
|
+
const secondaryAction = () => alert('Secondary button has been clicked!');
|
|
383
|
+
|
|
384
|
+
const appearanceValue = 'danger';
|
|
385
|
+
|
|
386
|
+
return (
|
|
387
|
+
<ModalTransition>
|
|
388
|
+
{isOpen && (
|
|
389
|
+
<Modal
|
|
390
|
+
actions={getModalDialogActions(close)}
|
|
391
|
+
onClose={close}
|
|
392
|
+
testId="modal"
|
|
393
|
+
appearance={appearanceValue}
|
|
394
|
+
>
|
|
395
|
+
<p>modal body</p>
|
|
396
|
+
</Modal>
|
|
397
|
+
)}
|
|
398
|
+
</ModalTransition>
|
|
399
|
+
);
|
|
400
|
+
}
|
|
401
|
+
`,
|
|
402
|
+
`
|
|
403
|
+
import React, { useState } from 'react';
|
|
404
|
+
import Button from "@atlaskit/button/standard-button";
|
|
405
|
+
import Modal, { ModalTransition, ModalFooter } from "@atlaskit/modal-dialog";
|
|
406
|
+
|
|
407
|
+
import { getModalDialogActions } from './utils';
|
|
408
|
+
|
|
409
|
+
const DefaultModal = () => {
|
|
410
|
+
const [isOpen, setIsOpen] = useState(true);
|
|
411
|
+
const close = () => setIsOpen(false);
|
|
412
|
+
const secondaryAction = () => alert('Secondary button has been clicked!');
|
|
413
|
+
|
|
414
|
+
const appearanceValue = 'danger';
|
|
415
|
+
|
|
416
|
+
return (
|
|
417
|
+
<ModalTransition>
|
|
418
|
+
{isOpen && (
|
|
419
|
+
(<Modal onClose={close} testId="modal" appearance={appearanceValue}>
|
|
420
|
+
<p>modal body</p>
|
|
421
|
+
<ModalFooter>
|
|
422
|
+
{getModalDialogActions(close).map((props, index) => <Button
|
|
423
|
+
{...props}
|
|
424
|
+
appearance={index === 0 ? props.appearance || appearanceValue || "primary" : props.appearance || "subtle"}>{props.text}</Button>)}
|
|
425
|
+
</ModalFooter>
|
|
426
|
+
</Modal>)
|
|
427
|
+
)}
|
|
428
|
+
</ModalTransition>
|
|
429
|
+
);
|
|
430
|
+
}
|
|
431
|
+
`,
|
|
432
|
+
`should map the actions prop to ModalFooter buttons, NOT add autoFocus and NOT flip buttons when actions are not declared in the same file`,
|
|
433
|
+
);
|
|
434
|
+
});
|
|
435
|
+
});
|
|
436
|
+
});
|
|
@@ -0,0 +1,645 @@
|
|
|
1
|
+
import { createTransformer } from '@atlaskit/codemod-utils';
|
|
2
|
+
|
|
3
|
+
import { mapBodyFromProps } from '../migrations/map-body-from-props';
|
|
4
|
+
|
|
5
|
+
const transformer = createTransformer([mapBodyFromProps]);
|
|
6
|
+
|
|
7
|
+
const defineInlineTest = require('jscodeshift/dist/testUtils').defineInlineTest;
|
|
8
|
+
|
|
9
|
+
describe('map body from props', () => {
|
|
10
|
+
['tsx', 'babylon'].forEach((parser) => {
|
|
11
|
+
describe(`parser: ${parser}`, () => {
|
|
12
|
+
defineInlineTest(
|
|
13
|
+
{ default: transformer, parser },
|
|
14
|
+
{},
|
|
15
|
+
`
|
|
16
|
+
import React from 'react';
|
|
17
|
+
|
|
18
|
+
import ModalDialog from '@atlaskit/modal-dialog';
|
|
19
|
+
|
|
20
|
+
const Body = (props) => (<div>{props.children}</div>);
|
|
21
|
+
const Header = (props) => (<div><h1>{props.children}</h1></div>);
|
|
22
|
+
|
|
23
|
+
export default function modalDialog() {
|
|
24
|
+
return (
|
|
25
|
+
<ModalDialog
|
|
26
|
+
onClose={handleClose}
|
|
27
|
+
components={{ Body, Header }}
|
|
28
|
+
>
|
|
29
|
+
{content}
|
|
30
|
+
</ModalDialog>
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
`,
|
|
34
|
+
`
|
|
35
|
+
import React from 'react';
|
|
36
|
+
|
|
37
|
+
import ModalDialog from '@atlaskit/modal-dialog';
|
|
38
|
+
|
|
39
|
+
const Body = (props) => (<div>{props.children}</div>);
|
|
40
|
+
const Header = (props) => (<div><h1>{props.children}</h1></div>);
|
|
41
|
+
|
|
42
|
+
export default function modalDialog() {
|
|
43
|
+
return (
|
|
44
|
+
<ModalDialog
|
|
45
|
+
onClose={handleClose}
|
|
46
|
+
components={{
|
|
47
|
+
Header
|
|
48
|
+
}}>
|
|
49
|
+
{Body({
|
|
50
|
+
children: <>
|
|
51
|
+
{content}
|
|
52
|
+
</>
|
|
53
|
+
})}
|
|
54
|
+
</ModalDialog>
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
`,
|
|
58
|
+
'should invoke Body declared as shorthand with children passed as argument',
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
defineInlineTest(
|
|
62
|
+
{ default: transformer, parser },
|
|
63
|
+
{},
|
|
64
|
+
`
|
|
65
|
+
import React from 'react';
|
|
66
|
+
|
|
67
|
+
import ModalDialog from '@atlaskit/modal-dialog';
|
|
68
|
+
|
|
69
|
+
const BodyComponent = (props) => (<div>{props.children}</div>);
|
|
70
|
+
const Header = (props) => (<div><h1>{props.children}</h1></div>);
|
|
71
|
+
|
|
72
|
+
export default function modalDialog() {
|
|
73
|
+
return (
|
|
74
|
+
<ModalDialog
|
|
75
|
+
onClose={handleClose}
|
|
76
|
+
components={{
|
|
77
|
+
Body: BodyComponent,
|
|
78
|
+
Header
|
|
79
|
+
}}
|
|
80
|
+
>
|
|
81
|
+
{content}
|
|
82
|
+
</ModalDialog>
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
`,
|
|
86
|
+
`
|
|
87
|
+
import React from 'react';
|
|
88
|
+
|
|
89
|
+
import ModalDialog from '@atlaskit/modal-dialog';
|
|
90
|
+
|
|
91
|
+
const BodyComponent = (props) => (<div>{props.children}</div>);
|
|
92
|
+
const Header = (props) => (<div><h1>{props.children}</h1></div>);
|
|
93
|
+
|
|
94
|
+
export default function modalDialog() {
|
|
95
|
+
return (
|
|
96
|
+
<ModalDialog
|
|
97
|
+
onClose={handleClose}
|
|
98
|
+
components={{
|
|
99
|
+
Header
|
|
100
|
+
}}>
|
|
101
|
+
{BodyComponent({
|
|
102
|
+
children: <>
|
|
103
|
+
{content}
|
|
104
|
+
</>
|
|
105
|
+
})}
|
|
106
|
+
</ModalDialog>
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
`,
|
|
110
|
+
'should invoke Body declared as assigned variable with children passed as argument',
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
defineInlineTest(
|
|
114
|
+
{ default: transformer, parser },
|
|
115
|
+
{},
|
|
116
|
+
`
|
|
117
|
+
import React from 'react';
|
|
118
|
+
|
|
119
|
+
import ModalDialog from '@atlaskit/modal-dialog';
|
|
120
|
+
import Form from '@atlaskit/form';
|
|
121
|
+
|
|
122
|
+
const Header = (props) => (<div><h1>{props.children}</h1></div>);
|
|
123
|
+
|
|
124
|
+
export default function modalDialog() {
|
|
125
|
+
return (
|
|
126
|
+
<ModalDialog
|
|
127
|
+
onClose={handleClose}
|
|
128
|
+
components={{
|
|
129
|
+
Header,
|
|
130
|
+
Body: (props) => (
|
|
131
|
+
<Form onSubmit={onSubmit}>
|
|
132
|
+
{({ formProps }) => <form {...formProps}>{props.children}</form>}
|
|
133
|
+
</Form>
|
|
134
|
+
)
|
|
135
|
+
}}
|
|
136
|
+
>
|
|
137
|
+
<div>First content</div>
|
|
138
|
+
<div>Second content</div>
|
|
139
|
+
</ModalDialog>
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
`,
|
|
143
|
+
`
|
|
144
|
+
import React from 'react';
|
|
145
|
+
|
|
146
|
+
import ModalDialog from '@atlaskit/modal-dialog';
|
|
147
|
+
import Form from '@atlaskit/form';
|
|
148
|
+
|
|
149
|
+
const Header = (props) => (<div><h1>{props.children}</h1></div>);
|
|
150
|
+
|
|
151
|
+
export default function modalDialog() {
|
|
152
|
+
return (
|
|
153
|
+
<ModalDialog
|
|
154
|
+
onClose={handleClose}
|
|
155
|
+
components={{
|
|
156
|
+
Header
|
|
157
|
+
}}>
|
|
158
|
+
{(props => <Form onSubmit={onSubmit}>
|
|
159
|
+
{({ formProps }) => <form {...formProps}>{props.children}</form>}
|
|
160
|
+
</Form>)({
|
|
161
|
+
children: <>
|
|
162
|
+
<div>First content</div>
|
|
163
|
+
<div>Second content</div>
|
|
164
|
+
</>
|
|
165
|
+
})}
|
|
166
|
+
</ModalDialog>
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
`,
|
|
170
|
+
'should invoke Body declared as a function expression with children passed as argument',
|
|
171
|
+
);
|
|
172
|
+
|
|
173
|
+
defineInlineTest(
|
|
174
|
+
{ default: transformer, parser },
|
|
175
|
+
{},
|
|
176
|
+
`
|
|
177
|
+
import React from 'react';
|
|
178
|
+
|
|
179
|
+
import ModalDialog from '@atlaskit/modal-dialog';
|
|
180
|
+
|
|
181
|
+
const Header = (props) => (<div><h1>{props.children}</h1></div>);
|
|
182
|
+
|
|
183
|
+
class CustomModalDialog extends React.Component {
|
|
184
|
+
body = (props) => (<div>{props.children}</div>);
|
|
185
|
+
|
|
186
|
+
render() {
|
|
187
|
+
return (
|
|
188
|
+
<ModalDialog
|
|
189
|
+
onClose={handleClose}
|
|
190
|
+
components={{
|
|
191
|
+
Body: this.body,
|
|
192
|
+
Header
|
|
193
|
+
}}
|
|
194
|
+
>
|
|
195
|
+
{content}
|
|
196
|
+
</ModalDialog>
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
`,
|
|
201
|
+
`
|
|
202
|
+
import React from 'react';
|
|
203
|
+
|
|
204
|
+
import ModalDialog from '@atlaskit/modal-dialog';
|
|
205
|
+
|
|
206
|
+
const Header = (props) => (<div><h1>{props.children}</h1></div>);
|
|
207
|
+
|
|
208
|
+
class CustomModalDialog extends React.Component {
|
|
209
|
+
body = (props) => (<div>{props.children}</div>);
|
|
210
|
+
|
|
211
|
+
render() {
|
|
212
|
+
return (
|
|
213
|
+
<ModalDialog
|
|
214
|
+
onClose={handleClose}
|
|
215
|
+
components={{
|
|
216
|
+
Header
|
|
217
|
+
}}>
|
|
218
|
+
{this.body({
|
|
219
|
+
children: <>
|
|
220
|
+
{content}
|
|
221
|
+
</>
|
|
222
|
+
})}
|
|
223
|
+
</ModalDialog>
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
`,
|
|
228
|
+
'should invoke Body of a modal dialog declared as class component',
|
|
229
|
+
);
|
|
230
|
+
|
|
231
|
+
defineInlineTest(
|
|
232
|
+
{ default: transformer, parser },
|
|
233
|
+
{},
|
|
234
|
+
`
|
|
235
|
+
import React from 'react';
|
|
236
|
+
|
|
237
|
+
import ModalDialog from '@atlaskit/modal-dialog';
|
|
238
|
+
|
|
239
|
+
const Header = (props) => (<div><h1>{props.children}</h1></div>);
|
|
240
|
+
|
|
241
|
+
class CustomModalDialog extends React.Component {
|
|
242
|
+
body = (props) => (<div>{props.children}</div>);
|
|
243
|
+
|
|
244
|
+
render() {
|
|
245
|
+
return (
|
|
246
|
+
<ModalDialog
|
|
247
|
+
onClose={handleClose}
|
|
248
|
+
body={this.body}
|
|
249
|
+
components={{
|
|
250
|
+
Header
|
|
251
|
+
}}>
|
|
252
|
+
{content}
|
|
253
|
+
</ModalDialog>
|
|
254
|
+
);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
`,
|
|
258
|
+
`
|
|
259
|
+
import React from 'react';
|
|
260
|
+
|
|
261
|
+
import ModalDialog from '@atlaskit/modal-dialog';
|
|
262
|
+
|
|
263
|
+
const Header = (props) => (<div><h1>{props.children}</h1></div>);
|
|
264
|
+
|
|
265
|
+
class CustomModalDialog extends React.Component {
|
|
266
|
+
body = (props) => (<div>{props.children}</div>);
|
|
267
|
+
|
|
268
|
+
render() {
|
|
269
|
+
return (
|
|
270
|
+
<ModalDialog
|
|
271
|
+
onClose={handleClose}
|
|
272
|
+
body={this.body}
|
|
273
|
+
components={{
|
|
274
|
+
Header
|
|
275
|
+
}}>
|
|
276
|
+
{this.body({
|
|
277
|
+
children: <>
|
|
278
|
+
{content}
|
|
279
|
+
</>
|
|
280
|
+
})}
|
|
281
|
+
</ModalDialog>
|
|
282
|
+
);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
`,
|
|
286
|
+
'should invoke Body passed to the body prop',
|
|
287
|
+
);
|
|
288
|
+
|
|
289
|
+
defineInlineTest(
|
|
290
|
+
{ default: transformer, parser },
|
|
291
|
+
{},
|
|
292
|
+
`
|
|
293
|
+
import React from 'react';
|
|
294
|
+
|
|
295
|
+
import ModalDialog from '@atlaskit/modal-dialog';
|
|
296
|
+
|
|
297
|
+
const Header = (props) => (<div><h1>{props.children}</h1></div>);
|
|
298
|
+
|
|
299
|
+
class CustomModalDialog extends React.Component {
|
|
300
|
+
body = (props) => (<div>{props.children}</div>);
|
|
301
|
+
|
|
302
|
+
render() {
|
|
303
|
+
return (
|
|
304
|
+
<ModalDialog
|
|
305
|
+
onClose={handleClose}
|
|
306
|
+
body={({ children }) => <div>{children}</div>}
|
|
307
|
+
components={{
|
|
308
|
+
Header,
|
|
309
|
+
Body: this.body
|
|
310
|
+
}}
|
|
311
|
+
>
|
|
312
|
+
{content}
|
|
313
|
+
</ModalDialog>
|
|
314
|
+
);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
`,
|
|
318
|
+
`
|
|
319
|
+
import React from 'react';
|
|
320
|
+
|
|
321
|
+
import ModalDialog from '@atlaskit/modal-dialog';
|
|
322
|
+
|
|
323
|
+
const Header = (props) => (<div><h1>{props.children}</h1></div>);
|
|
324
|
+
|
|
325
|
+
class CustomModalDialog extends React.Component {
|
|
326
|
+
body = (props) => (<div>{props.children}</div>);
|
|
327
|
+
|
|
328
|
+
render() {
|
|
329
|
+
return (
|
|
330
|
+
<ModalDialog
|
|
331
|
+
onClose={handleClose}
|
|
332
|
+
body={({ children }) => <div>{children}</div>}
|
|
333
|
+
components={{
|
|
334
|
+
Header
|
|
335
|
+
}}>
|
|
336
|
+
{this.body({
|
|
337
|
+
children: <>
|
|
338
|
+
{content}
|
|
339
|
+
</>
|
|
340
|
+
})}
|
|
341
|
+
</ModalDialog>
|
|
342
|
+
);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
`,
|
|
346
|
+
'should take Body passed from components prop if both declarations exist',
|
|
347
|
+
);
|
|
348
|
+
|
|
349
|
+
defineInlineTest(
|
|
350
|
+
{ default: transformer, parser },
|
|
351
|
+
{},
|
|
352
|
+
`
|
|
353
|
+
import React from 'react';
|
|
354
|
+
|
|
355
|
+
import ModalDialog from '@atlaskit/modal-dialog';
|
|
356
|
+
|
|
357
|
+
const components = {
|
|
358
|
+
Body: (props) => (<div>{props.children}</div>),
|
|
359
|
+
};
|
|
360
|
+
|
|
361
|
+
export default function modalDialog() {
|
|
362
|
+
return (
|
|
363
|
+
<ModalDialog onClose={handleClose} components={components}>
|
|
364
|
+
{content}
|
|
365
|
+
</ModalDialog>
|
|
366
|
+
);
|
|
367
|
+
}
|
|
368
|
+
`,
|
|
369
|
+
`
|
|
370
|
+
import React from 'react';
|
|
371
|
+
|
|
372
|
+
import ModalDialog, { ModalBody } from "@atlaskit/modal-dialog";
|
|
373
|
+
|
|
374
|
+
const components = {
|
|
375
|
+
Body: (props) => (<div>{props.children}</div>),
|
|
376
|
+
};
|
|
377
|
+
|
|
378
|
+
export default function modalDialog() {
|
|
379
|
+
return (
|
|
380
|
+
<ModalDialog onClose={handleClose} components={components}>
|
|
381
|
+
<ModalBody>
|
|
382
|
+
{content}
|
|
383
|
+
</ModalBody>
|
|
384
|
+
</ModalDialog>
|
|
385
|
+
);
|
|
386
|
+
}
|
|
387
|
+
`,
|
|
388
|
+
'should wrap children in default ModalBody if components prop is NOT defined as inline object expression',
|
|
389
|
+
);
|
|
390
|
+
|
|
391
|
+
defineInlineTest(
|
|
392
|
+
{ default: transformer, parser },
|
|
393
|
+
{},
|
|
394
|
+
`
|
|
395
|
+
import React from 'react';
|
|
396
|
+
|
|
397
|
+
import ModalDialog from '@atlaskit/modal-dialog';
|
|
398
|
+
|
|
399
|
+
const Header = (props) => (<div><h1>{props.children}</h1></div>);
|
|
400
|
+
|
|
401
|
+
export default function modalDialog() {
|
|
402
|
+
return (
|
|
403
|
+
<ModalDialog
|
|
404
|
+
onClose={handleClose}
|
|
405
|
+
components={{
|
|
406
|
+
Header
|
|
407
|
+
}}
|
|
408
|
+
>
|
|
409
|
+
{content}
|
|
410
|
+
</ModalDialog>
|
|
411
|
+
);
|
|
412
|
+
}
|
|
413
|
+
`,
|
|
414
|
+
`
|
|
415
|
+
import React from 'react';
|
|
416
|
+
|
|
417
|
+
import ModalDialog, { ModalBody } from "@atlaskit/modal-dialog";
|
|
418
|
+
|
|
419
|
+
const Header = (props) => (<div><h1>{props.children}</h1></div>);
|
|
420
|
+
|
|
421
|
+
export default function modalDialog() {
|
|
422
|
+
return (
|
|
423
|
+
<ModalDialog
|
|
424
|
+
onClose={handleClose}
|
|
425
|
+
components={{
|
|
426
|
+
Header
|
|
427
|
+
}}>
|
|
428
|
+
<ModalBody>
|
|
429
|
+
{content}
|
|
430
|
+
</ModalBody>
|
|
431
|
+
</ModalDialog>
|
|
432
|
+
);
|
|
433
|
+
}
|
|
434
|
+
`,
|
|
435
|
+
'should wrap children in default ModalBody if no override exists in the components prop',
|
|
436
|
+
);
|
|
437
|
+
|
|
438
|
+
defineInlineTest(
|
|
439
|
+
{ default: transformer, parser },
|
|
440
|
+
{},
|
|
441
|
+
`
|
|
442
|
+
import React from 'react';
|
|
443
|
+
|
|
444
|
+
import ModalDialog from '@atlaskit/modal-dialog';
|
|
445
|
+
|
|
446
|
+
export default function modalDialog() {
|
|
447
|
+
return (
|
|
448
|
+
<ModalDialog onClose={handleClose}>
|
|
449
|
+
{content}
|
|
450
|
+
</ModalDialog>
|
|
451
|
+
);
|
|
452
|
+
}
|
|
453
|
+
`,
|
|
454
|
+
`
|
|
455
|
+
import React from 'react';
|
|
456
|
+
|
|
457
|
+
import ModalDialog, { ModalBody } from "@atlaskit/modal-dialog";
|
|
458
|
+
|
|
459
|
+
export default function modalDialog() {
|
|
460
|
+
return (
|
|
461
|
+
<ModalDialog onClose={handleClose}>
|
|
462
|
+
<ModalBody>
|
|
463
|
+
{content}
|
|
464
|
+
</ModalBody>
|
|
465
|
+
</ModalDialog>
|
|
466
|
+
);
|
|
467
|
+
}
|
|
468
|
+
`,
|
|
469
|
+
'should wrap children in default ModalBody if no components/body props exist',
|
|
470
|
+
);
|
|
471
|
+
|
|
472
|
+
defineInlineTest(
|
|
473
|
+
{ default: transformer, parser },
|
|
474
|
+
{},
|
|
475
|
+
`
|
|
476
|
+
import React from 'react';
|
|
477
|
+
|
|
478
|
+
const ModalDialog = React.lazy(() => import('@atlaskit/modal-dialog'));
|
|
479
|
+
|
|
480
|
+
export default function modalDialog() {
|
|
481
|
+
return (
|
|
482
|
+
<ModalDialog onClose={handleClose}>
|
|
483
|
+
{content}
|
|
484
|
+
</ModalDialog>
|
|
485
|
+
);
|
|
486
|
+
}
|
|
487
|
+
`,
|
|
488
|
+
`
|
|
489
|
+
import React from 'react';
|
|
490
|
+
|
|
491
|
+
const ModalDialog = React.lazy(() => import('@atlaskit/modal-dialog'));
|
|
492
|
+
|
|
493
|
+
/* TODO: (from codemod) We have added "React.lazy" here. Feel free to change it to "lazy" or other named import depending upon how you imported. */
|
|
494
|
+
const ModalBody = React.lazy(() => import("@atlaskit/modal-dialog/modal-body"));
|
|
495
|
+
|
|
496
|
+
export default function modalDialog() {
|
|
497
|
+
return (
|
|
498
|
+
<ModalDialog onClose={handleClose}>
|
|
499
|
+
<ModalBody>
|
|
500
|
+
{content}
|
|
501
|
+
</ModalBody>
|
|
502
|
+
</ModalDialog>
|
|
503
|
+
);
|
|
504
|
+
}
|
|
505
|
+
`,
|
|
506
|
+
'should wrap import ModalBody dynamically when ModalDialog is dynamically imported',
|
|
507
|
+
);
|
|
508
|
+
|
|
509
|
+
defineInlineTest(
|
|
510
|
+
{ default: transformer, parser },
|
|
511
|
+
{},
|
|
512
|
+
`
|
|
513
|
+
import React from 'react';
|
|
514
|
+
|
|
515
|
+
import ModalDialog from '@atlaskit/modal-dialog';
|
|
516
|
+
|
|
517
|
+
const Header = (props) => (<div><h1>{props.children}</h1></div>);
|
|
518
|
+
|
|
519
|
+
export default function modalDialog() {
|
|
520
|
+
const ModalBody = () => <div />;
|
|
521
|
+
|
|
522
|
+
return (
|
|
523
|
+
<ModalDialog
|
|
524
|
+
onClose={handleClose}
|
|
525
|
+
components={{
|
|
526
|
+
Header
|
|
527
|
+
}}
|
|
528
|
+
>
|
|
529
|
+
{content}
|
|
530
|
+
</ModalDialog>
|
|
531
|
+
);
|
|
532
|
+
}
|
|
533
|
+
`,
|
|
534
|
+
`
|
|
535
|
+
import React from 'react';
|
|
536
|
+
|
|
537
|
+
import ModalDialog, { ModalBody as AKModalBody } from "@atlaskit/modal-dialog";
|
|
538
|
+
|
|
539
|
+
const Header = (props) => (<div><h1>{props.children}</h1></div>);
|
|
540
|
+
|
|
541
|
+
export default function modalDialog() {
|
|
542
|
+
const ModalBody = () => <div />;
|
|
543
|
+
|
|
544
|
+
return (
|
|
545
|
+
<ModalDialog
|
|
546
|
+
onClose={handleClose}
|
|
547
|
+
components={{
|
|
548
|
+
Header
|
|
549
|
+
}}>
|
|
550
|
+
<AKModalBody>
|
|
551
|
+
{content}
|
|
552
|
+
</AKModalBody>
|
|
553
|
+
</ModalDialog>
|
|
554
|
+
);
|
|
555
|
+
}
|
|
556
|
+
`,
|
|
557
|
+
'should import default ModalBody as AKModalBody if the declaration already exists',
|
|
558
|
+
);
|
|
559
|
+
|
|
560
|
+
defineInlineTest(
|
|
561
|
+
{ default: transformer, parser },
|
|
562
|
+
{},
|
|
563
|
+
`
|
|
564
|
+
import React from 'react';
|
|
565
|
+
|
|
566
|
+
import ModalDialog, { ModalBody } from '@atlaskit/modal-dialog';
|
|
567
|
+
|
|
568
|
+
const CustomBody = (props) => (
|
|
569
|
+
<form>
|
|
570
|
+
<ModalBody>
|
|
571
|
+
{props.children}
|
|
572
|
+
</ModalBody>
|
|
573
|
+
</form>
|
|
574
|
+
);
|
|
575
|
+
|
|
576
|
+
export default function modalDialog() {
|
|
577
|
+
return (
|
|
578
|
+
<ModalDialog onClose={handleClose}>
|
|
579
|
+
<CustomBody>
|
|
580
|
+
{content}
|
|
581
|
+
</CustomBody>
|
|
582
|
+
</ModalDialog>
|
|
583
|
+
);
|
|
584
|
+
}
|
|
585
|
+
`,
|
|
586
|
+
`
|
|
587
|
+
import React from 'react';
|
|
588
|
+
|
|
589
|
+
import ModalDialog, { ModalBody } from '@atlaskit/modal-dialog';
|
|
590
|
+
|
|
591
|
+
const CustomBody = (props) => (
|
|
592
|
+
<form>
|
|
593
|
+
<ModalBody>
|
|
594
|
+
{props.children}
|
|
595
|
+
</ModalBody>
|
|
596
|
+
</form>
|
|
597
|
+
);
|
|
598
|
+
|
|
599
|
+
export default function modalDialog() {
|
|
600
|
+
return (
|
|
601
|
+
<ModalDialog onClose={handleClose}>
|
|
602
|
+
<CustomBody>
|
|
603
|
+
{content}
|
|
604
|
+
</CustomBody>
|
|
605
|
+
</ModalDialog>
|
|
606
|
+
);
|
|
607
|
+
}
|
|
608
|
+
`,
|
|
609
|
+
'should do nothing if ModalBody is already imported',
|
|
610
|
+
);
|
|
611
|
+
|
|
612
|
+
defineInlineTest(
|
|
613
|
+
{ default: transformer, parser },
|
|
614
|
+
{},
|
|
615
|
+
`
|
|
616
|
+
import React from 'react';
|
|
617
|
+
|
|
618
|
+
import ModalDialog from '@atlaskit/modal-dialog';
|
|
619
|
+
|
|
620
|
+
const Header = (props) => (<div><h1>{props.children}</h1></div>);
|
|
621
|
+
|
|
622
|
+
export default function modalDialog() {
|
|
623
|
+
return (
|
|
624
|
+
<ModalDialog onClose={handleClose} header={Header} />
|
|
625
|
+
);
|
|
626
|
+
}
|
|
627
|
+
`,
|
|
628
|
+
`
|
|
629
|
+
import React from 'react';
|
|
630
|
+
|
|
631
|
+
import ModalDialog from '@atlaskit/modal-dialog';
|
|
632
|
+
|
|
633
|
+
const Header = (props) => (<div><h1>{props.children}</h1></div>);
|
|
634
|
+
|
|
635
|
+
export default function modalDialog() {
|
|
636
|
+
return (
|
|
637
|
+
<ModalDialog onClose={handleClose} header={Header} />
|
|
638
|
+
);
|
|
639
|
+
}
|
|
640
|
+
`,
|
|
641
|
+
'should do nothing when no overrides exist and ModalDialog is self-closing',
|
|
642
|
+
);
|
|
643
|
+
});
|
|
644
|
+
});
|
|
645
|
+
});
|