5
5
6
6
import { ClayPortal } from '@clayui/shared' ;
7
7
import classNames from 'classnames' ;
8
- import React from 'react' ;
8
+ import React , { useEffect , useRef , useState } from 'react' ;
9
9
import warning from 'warning' ;
10
10
11
11
import Body from './Body' ;
@@ -64,24 +64,22 @@ const ClayModal: React.FunctionComponent<IProps> = ({
64
64
status,
65
65
...otherProps
66
66
} : IProps ) => {
67
- const modalBodyElementRef = React . useRef < HTMLDivElement | null > ( null ) ;
67
+ const modalElementRef = useRef < HTMLDivElement | null > ( null ) ;
68
+ const modalBodyElementRef = useRef < HTMLDivElement | null > ( null ) ;
68
69
69
70
warning ( observer !== undefined , warningMessage ) ;
70
71
71
- useUserInteractions ( modalBodyElementRef , ( ) =>
72
+ useUserInteractions ( modalElementRef , modalBodyElementRef , ( ) =>
72
73
observer . dispatch ( ObserverType . Close )
73
74
) ;
74
75
75
- React . useEffect ( ( ) => observer . dispatch ( ObserverType . Open ) , [ ] ) ;
76
-
77
- // Defines a default Modal size when size is not set.
78
- const maxWidth = size ? { } : { maxWidth : '600px' } ;
76
+ useEffect ( ( ) => observer . dispatch ( ObserverType . Open ) , [ ] ) ;
79
77
80
78
const [ show , content ] =
81
79
observer && observer . mutation ? observer . mutation : [ false , false ] ;
82
80
83
81
return (
84
- < ClayPortal subPortalRef = { modalBodyElementRef } >
82
+ < ClayPortal subPortalRef = { modalElementRef } >
85
83
< div
86
84
className = { classNames ( 'modal-backdrop fade' , {
87
85
show,
@@ -92,34 +90,28 @@ const ClayModal: React.FunctionComponent<IProps> = ({
92
90
className = { classNames ( 'fade modal d-block' , className , {
93
91
show,
94
92
} ) }
93
+ ref = { modalElementRef }
95
94
>
96
95
< div
97
- className = { classNames ( {
96
+ className = { classNames ( 'modal-dialog' , {
98
97
[ `modal-${ size } ` ] : size ,
98
+ [ `modal-${ status } ` ] : status ,
99
+ 'modal-dialog-centered' : center ,
99
100
} ) }
100
101
ref = { modalBodyElementRef }
101
- style = { { margin : 'auto' , ... maxWidth } }
102
+ tabIndex = { - 1 }
102
103
>
103
- < div
104
- className = { classNames ( 'modal-dialog' , {
105
- [ `modal-${ size } ` ] : size ,
106
- [ `modal-${ status } ` ] : status ,
107
- 'modal-dialog-centered' : center ,
108
- } ) }
109
- tabIndex = { - 1 }
110
- >
111
- < div className = "modal-content" >
112
- < Context . Provider
113
- value = { {
114
- onClose : ( ) =>
115
- observer . dispatch ( ObserverType . Close ) ,
116
- spritemap,
117
- status,
118
- } }
119
- >
120
- { content && children }
121
- </ Context . Provider >
122
- </ div >
104
+ < div className = "modal-content" >
105
+ < Context . Provider
106
+ value = { {
107
+ onClose : ( ) =>
108
+ observer . dispatch ( ObserverType . Close ) ,
109
+ spritemap,
110
+ status,
111
+ } }
112
+ >
113
+ { content && children }
114
+ </ Context . Provider >
123
115
</ div >
124
116
</ div >
125
117
</ div >
0 commit comments