@@ -18,12 +18,12 @@ import {
18
18
useKeyOnly ,
19
19
} from '../../lib'
20
20
import Icon from '../../elements/Icon'
21
- import MountNode from '../../addons/MountNode'
22
21
import Portal from '../../addons/Portal'
23
- import ModalHeader from './ModalHeader'
24
- import ModalContent from './ModalContent'
25
22
import ModalActions from './ModalActions'
23
+ import ModalContent from './ModalContent'
26
24
import ModalDescription from './ModalDescription'
25
+ import ModalDimmer from './ModalDimmer'
26
+ import ModalHeader from './ModalHeader'
27
27
import { canFit , getLegacyStyles , isLegacy } from './utils'
28
28
29
29
const debug = makeDebugger ( 'modal' )
@@ -132,17 +132,8 @@ class Modal extends Component {
132
132
_ . invoke ( this . props , 'onUnmount' , e , this . props )
133
133
}
134
134
135
- setDimmerNodeStyle = ( ) => {
136
- debug ( 'setDimmerNodeStyle()' )
137
- const { current } = this . dimmerRef
138
-
139
- if ( current && current . style && current . style . display !== 'flex' ) {
140
- current . style . setProperty ( 'display' , 'flex' , 'important' )
141
- }
142
- }
143
-
144
135
setPositionAndClassNames = ( ) => {
145
- const { centered, dimmer } = this . props
136
+ const { centered } = this . props
146
137
147
138
let scrolling
148
139
const newState = { }
@@ -164,18 +155,8 @@ class Modal extends Component {
164
155
}
165
156
}
166
157
167
- const classes = cx (
168
- useKeyOnly ( dimmer , 'dimmable dimmed' ) ,
169
- useKeyOnly ( dimmer === 'blurring' , ' blurring' ) ,
170
- useKeyOnly ( scrolling , ' scrolling' ) ,
171
- )
172
-
173
- if ( this . state . mountClasses !== classes ) newState . mountClasses = classes
174
158
if ( ! _ . isEmpty ( newState ) ) this . setState ( newState )
175
-
176
159
this . animationRequestId = requestAnimationFrame ( this . setPositionAndClassNames )
177
-
178
- this . setDimmerNodeStyle ( )
179
160
}
180
161
181
162
renderContent = ( rest ) => {
@@ -187,11 +168,10 @@ class Modal extends Component {
187
168
closeIcon,
188
169
content,
189
170
header,
190
- mountNode,
191
171
size,
192
172
style,
193
173
} = this . props
194
- const { legacyStyles, mountClasses , scrolling } = this . state
174
+ const { legacyStyles, scrolling } = this . state
195
175
196
176
const classes = cx (
197
177
'ui' ,
@@ -210,8 +190,6 @@ class Modal extends Component {
210
190
return (
211
191
< Ref innerRef = { this . ref } >
212
192
< ElementType { ...rest } className = { classes } style = { { ...legacyStyles , ...style } } >
213
- < MountNode className = { mountClasses } node = { mountNode } />
214
-
215
193
{ closeIconJSX }
216
194
{ childrenUtils . isNil ( children ) ? (
217
195
< >
@@ -228,8 +206,8 @@ class Modal extends Component {
228
206
}
229
207
230
208
render ( ) {
231
- const { open } = this . state
232
209
const { centered, closeOnDocumentClick, dimmer, eventPool, trigger } = this . props
210
+ const { open, scrolling } = this . state
233
211
const mountNode = this . getMountNode ( )
234
212
235
213
// Short circuit when server side rendering
@@ -251,14 +229,6 @@ class Modal extends Component {
251
229
)
252
230
const portalProps = _ . pick ( unhandled , portalPropNames )
253
231
254
- // wrap dimmer modals
255
- const dimmerClasses = cx (
256
- 'ui' ,
257
- dimmer === 'inverted' && 'inverted' ,
258
- ! centered && 'top aligned' ,
259
- 'page modals dimmer transition visible active' ,
260
- )
261
-
262
232
// Heads up!
263
233
//
264
234
// The SUI CSS selector to prevent the modal itself from blurring requires an immediate .dimmer child:
@@ -283,9 +253,21 @@ class Modal extends Component {
283
253
onOpen = { this . handleOpen }
284
254
onUnmount = { this . handlePortalUnmount }
285
255
>
286
- < div className = { dimmerClasses } ref = { this . dimmerRef } >
287
- { this . renderContent ( rest ) }
288
- </ div >
256
+ < Ref innerRef = { this . dimmerRef } >
257
+ { ModalDimmer . create ( _ . isPlainObject ( dimmer ) ? dimmer : { } , {
258
+ autoGenerateKey : false ,
259
+ defaultProps : {
260
+ blurring : dimmer === 'blurring' ,
261
+ inverted : dimmer === 'inverted' ,
262
+ } ,
263
+ overrideProps : {
264
+ children : this . renderContent ( rest ) ,
265
+ centered,
266
+ mountNode,
267
+ scrolling,
268
+ } ,
269
+ } ) }
270
+ </ Ref >
289
271
</ Portal >
290
272
)
291
273
}
@@ -326,7 +308,12 @@ Modal.propTypes = {
326
308
defaultOpen : PropTypes . bool ,
327
309
328
310
/** A Modal can appear in a dimmer. */
329
- dimmer : PropTypes . oneOf ( [ true , 'inverted' , 'blurring' ] ) ,
311
+ dimmer : PropTypes . oneOfType ( [
312
+ PropTypes . bool ,
313
+ PropTypes . func ,
314
+ PropTypes . object ,
315
+ PropTypes . oneOf ( [ 'inverted' , 'blurring' ] ) ,
316
+ ] ) ,
330
317
331
318
/** Event pool namespace that is used to handle component events */
332
319
eventPool : PropTypes . string ,
@@ -405,9 +392,10 @@ Modal.defaultProps = {
405
392
406
393
Modal . autoControlledProps = [ 'open' ]
407
394
408
- Modal . Header = ModalHeader
395
+ Modal . Actions = ModalActions
409
396
Modal . Content = ModalContent
410
397
Modal . Description = ModalDescription
411
- Modal . Actions = ModalActions
398
+ Modal . Dimmer = ModalDimmer
399
+ Modal . Header = ModalHeader
412
400
413
401
export default Modal
0 commit comments