@@ -3,6 +3,7 @@ import React from 'react';
33import { modal } from '../Modal' ;
44import MotionDrawer from '../MotionDrawer' ;
55import { IModalOptions } from '../types' ;
6+ import { createQueueKey } from '../utils' ;
67
78
89
@@ -50,13 +51,15 @@ type TMotionModal<T> =
5051 * @param modalOptions
5152 */
5253function createModal < T = undefined > ( ModalComponent : React . FC < T > , modalOptions ?: IModalOptions ) : ICreateModal < T > {
54+ const { _effect, ...options } = modalOptions ?? { } as IModalOptions ;
55+
5356 /**
5457 * Add framer motion
5558 * @param args
5659 */
5760 const MotionModal : TMotionModal < T > = ( args ?: T ) => {
5861 return (
59- < MotionDrawer modalOptions = { modalOptions } >
62+ < MotionDrawer modalOptions = { options } >
6063 < ModalComponent { ...args as T & { } } />
6164 </ MotionDrawer >
6265 ) ;
@@ -66,22 +69,26 @@ function createModal<T = undefined>(ModalComponent: React.FC<T>, modalOptions?:
6669 function show ( ) ;
6770 function show ( args : T ) : void ;
6871 function show ( args ?: T ) : void {
72+ const queueKey = createQueueKey ( ) ;
73+
6974 if ( args ) {
70- modal . show ( MotionModal , args ) ;
75+ modal . showWithKey ( MotionModal , queueKey , args , _effect ?. onHide ) ;
7176 } else {
72- modal . show ( MotionModal ) ;
77+ modal . showWithKey ( MotionModal , queueKey , undefined , _effect ?. onHide ) ;
7378 }
79+ if ( _effect ?. onShow ) _effect . onShow ( queueKey ) ;
7480 }
7581
7682 // Overload signatures
7783 function showWithKey ( queueKey : string ) ;
7884 function showWithKey ( queueKey : string , args : T ) : void ;
7985 function showWithKey ( queueKey : string , args ?: T ) : void {
8086 if ( args ) {
81- modal . showWithKey ( MotionModal , queueKey , args ) ;
87+ modal . showWithKey ( MotionModal , queueKey , args , _effect ?. onHide ) ;
8288 } else {
83- modal . showWithKey ( MotionModal , queueKey ) ;
89+ modal . showWithKey ( MotionModal , queueKey , undefined , _effect ?. onHide ) ;
8490 }
91+ if ( _effect ?. onShow ) _effect . onShow ( queueKey ) ;
8592 }
8693
8794 // Assign the overloaded function to MotionModal.show
0 commit comments