@@ -18,12 +18,12 @@ import {
1818 useKeyOnly ,
1919} from '../../lib'
2020import Icon from '../../elements/Icon'
21- import MountNode from '../../addons/MountNode'
2221import Portal from '../../addons/Portal'
23- import ModalHeader from './ModalHeader'
24- import ModalContent from './ModalContent'
2522import ModalActions from './ModalActions'
23+ import ModalContent from './ModalContent'
2624import ModalDescription from './ModalDescription'
25+ import ModalDimmer from './ModalDimmer'
26+ import ModalHeader from './ModalHeader'
2727import { canFit , getLegacyStyles , isLegacy } from './utils'
2828
2929const debug = makeDebugger ( 'modal' )
@@ -132,17 +132,8 @@ class Modal extends Component {
132132 _ . invoke ( this . props , 'onUnmount' , e , this . props )
133133 }
134134
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-
144135 setPositionAndClassNames = ( ) => {
145- const { centered, dimmer } = this . props
136+ const { centered } = this . props
146137
147138 let scrolling
148139 const newState = { }
@@ -164,18 +155,8 @@ class Modal extends Component {
164155 }
165156 }
166157
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
174158 if ( ! _ . isEmpty ( newState ) ) this . setState ( newState )
175-
176159 this . animationRequestId = requestAnimationFrame ( this . setPositionAndClassNames )
177-
178- this . setDimmerNodeStyle ( )
179160 }
180161
181162 renderContent = ( rest ) => {
@@ -187,11 +168,10 @@ class Modal extends Component {
187168 closeIcon,
188169 content,
189170 header,
190- mountNode,
191171 size,
192172 style,
193173 } = this . props
194- const { legacyStyles, mountClasses , scrolling } = this . state
174+ const { legacyStyles, scrolling } = this . state
195175
196176 const classes = cx (
197177 'ui' ,
@@ -210,8 +190,6 @@ class Modal extends Component {
210190 return (
211191 < Ref innerRef = { this . ref } >
212192 < ElementType { ...rest } className = { classes } style = { { ...legacyStyles , ...style } } >
213- < MountNode className = { mountClasses } node = { mountNode } />
214-
215193 { closeIconJSX }
216194 { childrenUtils . isNil ( children ) ? (
217195 < >
@@ -228,8 +206,8 @@ class Modal extends Component {
228206 }
229207
230208 render ( ) {
231- const { open } = this . state
232209 const { centered, closeOnDocumentClick, dimmer, eventPool, trigger } = this . props
210+ const { open, scrolling } = this . state
233211 const mountNode = this . getMountNode ( )
234212
235213 // Short circuit when server side rendering
@@ -251,14 +229,6 @@ class Modal extends Component {
251229 )
252230 const portalProps = _ . pick ( unhandled , portalPropNames )
253231
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-
262232 // Heads up!
263233 //
264234 // The SUI CSS selector to prevent the modal itself from blurring requires an immediate .dimmer child:
@@ -283,9 +253,21 @@ class Modal extends Component {
283253 onOpen = { this . handleOpen }
284254 onUnmount = { this . handlePortalUnmount }
285255 >
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 >
289271 </ Portal >
290272 )
291273 }
@@ -326,7 +308,12 @@ Modal.propTypes = {
326308 defaultOpen : PropTypes . bool ,
327309
328310 /** 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+ ] ) ,
330317
331318 /** Event pool namespace that is used to handle component events */
332319 eventPool : PropTypes . string ,
@@ -405,9 +392,10 @@ Modal.defaultProps = {
405392
406393Modal . autoControlledProps = [ 'open' ]
407394
408- Modal . Header = ModalHeader
395+ Modal . Actions = ModalActions
409396Modal . Content = ModalContent
410397Modal . Description = ModalDescription
411- Modal . Actions = ModalActions
398+ Modal . Dimmer = ModalDimmer
399+ Modal . Header = ModalHeader
412400
413401export default Modal
0 commit comments