1- import React , { PropsWithChildren } from 'react' ;
1+ import React from 'react' ;
22
33import { useSafeState } from '@td-design/rn-hooks' ;
44
55import Portal from '../../portal' ;
66import ModalView from '../Modal/ModalView' ;
7- import { ModalProps } from '../type' ;
7+ import { ImperativeModalChildrenProps , ModalProps } from '../type' ;
88
99export default function show (
10- comp : React . ReactElement ,
10+ comp : React . ReactElement < ImperativeModalChildrenProps < { } > > ,
1111 props ?: Omit < ModalProps , 'onAnimationEnd' | 'visible' | 'onClose' >
1212) {
1313 const key = Portal . add (
@@ -24,7 +24,10 @@ export default function show(
2424 ) ;
2525}
2626
27- const ModalContent = ( { children, ...props } : PropsWithChildren < Omit < ModalProps , 'visible' | 'onClose' > > ) => {
27+ const ModalContent = ( {
28+ children,
29+ ...props
30+ } : Omit < ModalProps , 'visible' | 'onClose' > & { children : React . ReactElement < ImperativeModalChildrenProps < { } > > } ) => {
2831 const [ visible , setVisible ] = useSafeState ( true ) ;
2932
3033 return (
@@ -37,7 +40,14 @@ const ModalContent = ({ children, ...props }: PropsWithChildren<Omit<ModalProps,
3740 visible = { visible }
3841 onClose = { ( ) => setVisible ( false ) }
3942 >
40- { children }
43+ { React . isValidElement ( children )
44+ ? React . cloneElement ( children , {
45+ // Add any props you want to pass to the child here
46+ closeModal ( ) {
47+ setVisible ( false ) ;
48+ } ,
49+ } )
50+ : null }
4151 </ ModalView >
4252 ) ;
4353} ;
0 commit comments