@@ -530,6 +530,8 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < argument
530530
531531var _createClass = function ( ) { function defineProperties ( target , props ) { for ( var i = 0 ; i < props . length ; i ++ ) { var descriptor = props [ i ] ; descriptor . enumerable = descriptor . enumerable || false ; descriptor . configurable = true ; if ( "value" in descriptor ) descriptor . writable = true ; Object . defineProperty ( target , descriptor . key , descriptor ) ; } } return function ( Constructor , protoProps , staticProps ) { if ( protoProps ) defineProperties ( Constructor . prototype , protoProps ) ; if ( staticProps ) defineProperties ( Constructor , staticProps ) ; return Constructor ; } ; } ( ) ;
532532
533+ var _typeof = typeof Symbol === "function" && typeof Symbol . iterator === "symbol" ? function ( obj ) { return typeof obj ; } : function ( obj ) { return obj && typeof Symbol === "function" && obj . constructor === Symbol && obj !== Symbol . prototype ? "symbol" : typeof obj ; } ;
534+
533535var _react = __webpack_require__ ( 3 ) ;
534536
535537var _react2 = _interopRequireDefault ( _react ) ;
@@ -567,7 +569,9 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function"
567569var portalClassName = exports . portalClassName = 'ReactModalPortal' ;
568570var bodyOpenClassName = exports . bodyOpenClassName = 'ReactModal__Body--open' ;
569571
570- var renderSubtreeIntoContainer = _reactDom2 . default . unstable_renderSubtreeIntoContainer ;
572+ var canUseDOM = ( typeof window === 'undefined' ? 'undefined' : _typeof ( window ) ) !== undefined ;
573+ var isReact16 = _reactDom2 . default . createPortal !== undefined ;
574+ var createPortal = isReact16 ? _reactDom2 . default . createPortal : _reactDom2 . default . unstable_renderSubtreeIntoContainer ;
571575
572576function getParentElement ( parentSelector ) {
573577 return parentSelector ( ) ;
@@ -588,28 +592,32 @@ var Modal = function (_Component) {
588592 }
589593
590594 return _ret = ( _temp = ( _this = _possibleConstructorReturn ( this , ( _ref = Modal . __proto__ || Object . getPrototypeOf ( Modal ) ) . call . apply ( _ref , [ this ] . concat ( args ) ) ) , _this ) , _this . removePortal = function ( ) {
591- _reactDom2 . default . unmountComponentAtNode ( _this . node ) ;
595+ ! isReact16 && _reactDom2 . default . unmountComponentAtNode ( _this . node ) ;
592596 var parent = getParentElement ( _this . props . parentSelector ) ;
593597 parent . removeChild ( _this . node ) ;
598+ } , _this . portalRef = function ( ref ) {
599+ _this . portal = ref ;
594600 } , _this . renderPortal = function ( props ) {
595- _this . portal = renderSubtreeIntoContainer ( _this , _react2 . default . createElement ( _ModalPortal2 . default , _extends ( { defaultStyles : Modal . defaultStyles } , props ) ) , _this . node ) ;
601+ var portal = createPortal ( _this , _react2 . default . createElement ( _ModalPortal2 . default , _extends ( { defaultStyles : Modal . defaultStyles } , props ) ) , _this . node ) ;
602+ _this . portalRef ( portal ) ;
596603 } , _temp ) , _possibleConstructorReturn ( _this , _ret ) ;
597604 }
598605
599606 _createClass ( Modal , [ {
600607 key : 'componentDidMount' ,
601608 value : function componentDidMount ( ) {
602- this . node = document . createElement ( 'div' ) ;
609+ if ( ! canUseDOM ) return ;
603610 this . node . className = this . props . portalClassName ;
604611
605612 var parent = getParentElement ( this . props . parentSelector ) ;
606613 parent . appendChild ( this . node ) ;
607614
608- this . renderPortal ( this . props ) ;
615+ ! isReact16 && this . renderPortal ( this . props ) ;
609616 }
610617 } , {
611618 key : 'componentWillReceiveProps' ,
612619 value : function componentWillReceiveProps ( newProps ) {
620+ if ( ! canUseDOM ) return ;
613621 var isOpen = newProps . isOpen ;
614622 // Stop unnecessary renders if modal is remaining closed
615623
@@ -623,19 +631,20 @@ var Modal = function (_Component) {
623631 newParent . appendChild ( this . node ) ;
624632 }
625633
626- this . renderPortal ( newProps ) ;
634+ ! isReact16 && this . renderPortal ( newProps ) ;
627635 }
628636 } , {
629637 key : 'componentWillUpdate' ,
630638 value : function componentWillUpdate ( newProps ) {
639+ if ( ! canUseDOM ) return ;
631640 if ( newProps . portalClassName !== this . props . portalClassName ) {
632641 this . node . className = newProps . portalClassName ;
633642 }
634643 }
635644 } , {
636645 key : 'componentWillUnmount' ,
637646 value : function componentWillUnmount ( ) {
638- if ( ! this . node || ! this . portal ) return ;
647+ if ( ! canUseDOM || ! this . node || ! this . portal ) return ;
639648
640649 var state = this . portal . state ;
641650 var now = Date . now ( ) ;
@@ -654,7 +663,17 @@ var Modal = function (_Component) {
654663 } , {
655664 key : 'render' ,
656665 value : function render ( ) {
657- return null ;
666+ if ( ! canUseDOM || ! isReact16 ) {
667+ return null ;
668+ }
669+
670+ if ( ! this . node ) {
671+ this . node = document . createElement ( 'div' ) ;
672+ }
673+
674+ return createPortal ( _react2 . default . createElement ( _ModalPortal2 . default , _extends ( { ref : this . portalRef ,
675+ defaultStyles : Modal . defaultStyles
676+ } , this . props ) ) , this . node ) ;
658677 }
659678 } ] , [ {
660679 key : 'setAppElement' ,
0 commit comments