1- import * as React from 'react' ;
21import Portal from '@rc-component/portal' ;
2+ import * as React from 'react' ;
3+ import { RefContext } from './context' ;
34import Dialog from './Dialog' ;
45import type { IDialogPropTypes } from './IDialogPropTypes' ;
56
@@ -13,46 +14,47 @@ import type { IDialogPropTypes } from './IDialogPropTypes';
1314 * */
1415
1516const DialogWrap : React . FC < IDialogPropTypes > = ( props : IDialogPropTypes ) => {
16- const { visible, getContainer, forceRender, destroyOnClose = false , afterClose } = props ;
17+ const {
18+ visible,
19+ getContainer,
20+ forceRender,
21+ destroyOnClose = false ,
22+ afterClose,
23+ panelRef,
24+ } = props ;
1725 const [ animatedVisible , setAnimatedVisible ] = React . useState < boolean > ( visible ) ;
1826
27+ const refContext = React . useMemo ( ( ) => ( { panel : panelRef } ) , [ panelRef ] ) ;
28+
1929 React . useEffect ( ( ) => {
2030 if ( visible ) {
2131 setAnimatedVisible ( true ) ;
2232 }
2333 } , [ visible ] ) ;
2434
25- // // 渲染在当前 dom 里;
26- // if (getContainer === false) {
27- // return (
28- // <Dialog
29- // {...props}
30- // getOpenCount={() => 2} // 不对 body 做任何操作。。
31- // />
32- // );
33- // }
34-
3535 // Destroy on close will remove wrapped div
3636 if ( ! forceRender && destroyOnClose && ! animatedVisible ) {
3737 return null ;
3838 }
3939
4040 return (
41- < Portal
42- open = { visible || forceRender || animatedVisible }
43- autoDestroy = { false }
44- getContainer = { getContainer }
45- autoLock = { visible || animatedVisible }
46- >
47- < Dialog
48- { ...props }
49- destroyOnClose = { destroyOnClose }
50- afterClose = { ( ) => {
51- afterClose ?.( ) ;
52- setAnimatedVisible ( false ) ;
53- } }
54- />
55- </ Portal >
41+ < RefContext . Provider value = { refContext } >
42+ < Portal
43+ open = { visible || forceRender || animatedVisible }
44+ autoDestroy = { false }
45+ getContainer = { getContainer }
46+ autoLock = { visible || animatedVisible }
47+ >
48+ < Dialog
49+ { ...props }
50+ destroyOnClose = { destroyOnClose }
51+ afterClose = { ( ) => {
52+ afterClose ?.( ) ;
53+ setAnimatedVisible ( false ) ;
54+ } }
55+ />
56+ </ Portal >
57+ </ RefContext . Provider >
5658 ) ;
5759} ;
5860
0 commit comments