Skip to content

Commit 630d5f5

Browse files
authored
Merge pull request #78 from shoota/fix/apply_antd-deprecated-props
fix: rename antd visibility props to 'open' from 'visible'
2 parents 5bd49dd + d452bc9 commit 630d5f5

File tree

3 files changed

+54
-2
lines changed

3 files changed

+54
-2
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,9 @@ For every modal implementation we always need to these binding manually. So, to
361361
import NiceModal, {
362362
muiDialog,
363363
antdModal,
364+
antdModalV5,
364365
antdDrawer,
366+
antdDrawerV5,
365367
bootstrapDialog
366368
} from '@ebay/nice-modal-react';
367369

@@ -373,9 +375,15 @@ const modal = useModal();
373375
// For ant.design
374376
<Modal {...antdModal(modal)}>
375377

378+
// For ant.design v4.23.0 or later
379+
<Modal {...antdModalV5(modal)}>
380+
376381
// For antd drawer
377382
<Drawer {...antdDrawer(modal)}>
378383

384+
// For antd drawer v4.23.0 or later
385+
<Drawer {...antdDrawerV5(modal)}>
386+
379387
// For bootstrap dialog
380388
<Dialog {...bootstrapDialog(modal)}>
381389

src/index.test.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import NiceModal, {
77
register,
88
create,
99
antdDrawer,
10+
antdDrawerV5,
1011
antdModal,
12+
antdModalV5,
1113
muiDialog,
1214
bootstrapDialog,
1315
reducer,
@@ -360,9 +362,20 @@ const AntdModal = ({ visible, onOk, onCancel, afterClose, children }) => {
360362
</TestModal>
361363
);
362364
};
365+
const AntdModalV5 = ({ open, onOk, onCancel, afterClose, children }) => {
366+
return (
367+
<TestModal visible={open} onClose={onOk} onCancel={onCancel} onExited={afterClose}>
368+
{children}
369+
</TestModal>
370+
);
371+
};
363372
test('test antd modal helper', async () => {
364-
await testHelper(AntdModal, antdModal, 'AntdModal');
365-
await testHelper(AntdModal, antdModal, 'AntdModal', true);
373+
await testHelper(AntdModalV5, antdModalV5, 'AntdModalV5');
374+
await testHelper(AntdModalV5, antdModalV5, 'AntdModalV5', true);
375+
});
376+
test('test antd modal v5 helper', async () => {
377+
await testHelper(AntdModalV5, antdModalV5, 'AntdModalV5');
378+
await testHelper(AntdModalV5, antdModalV5, 'AntdModalV5', true);
366379
});
367380

368381
test('test antd modal onCancel', async () => {
@@ -392,6 +405,16 @@ test('test antd drawer helper', async () => {
392405
};
393406
await testHelper(AntdDrawer, antdDrawer, 'AntdDrawerTest');
394407
});
408+
test('test antd drawer v5 helper', async () => {
409+
const AntdDrawerV5 = ({ open, onClose, afterOpenChange, children }) => {
410+
return (
411+
<TestModal visible={open} onClose={onClose} onExited={() => afterOpenChange(false)}>
412+
{children}
413+
</TestModal>
414+
);
415+
};
416+
await testHelper(AntdDrawerV5, antdDrawerV5, 'AntdDrawerV5Test');
417+
});
395418

396419
test('test mui dialog helper', async () => {
397420
const MuiDialog = ({ open, onClose, onExited, children }) => {

src/index.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,17 @@ export const antdModal = (
502502
},
503503
};
504504
};
505+
export const antdModalV5 = (
506+
modal: NiceModalHandler,
507+
): { open: boolean; onCancel: () => void; onOk: () => void; afterClose: () => void } => {
508+
const {onOk, onCancel, afterClose} = antdModal(modal)
509+
return {
510+
open: modal.visible,
511+
onOk,
512+
onCancel,
513+
afterClose,
514+
};
515+
};
505516
export const antdDrawer = (
506517
modal: NiceModalHandler,
507518
): { visible: boolean; onClose: () => void; afterVisibleChange: (visible: boolean) => void } => {
@@ -516,6 +527,16 @@ export const antdDrawer = (
516527
},
517528
};
518529
};
530+
export const antdDrawerV5 = (
531+
modal: NiceModalHandler,
532+
): { open: boolean; onClose: () => void; afterOpenChange: (visible: boolean) => void } => {
533+
const {onClose, afterVisibleChange: afterOpenChange} = antdDrawer(modal)
534+
return {
535+
open: modal.visible,
536+
onClose,
537+
afterOpenChange,
538+
};
539+
};
519540
export const muiDialog = (modal: NiceModalHandler): { open: boolean; onClose: () => void; onExited: () => void } => {
520541
return {
521542
open: modal.visible,

0 commit comments

Comments
 (0)