@@ -530,6 +530,8 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < argument
530
530
531
531
var _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 ; } ; } ( ) ;
532
532
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
+
533
535
var _react = __webpack_require__ ( 3 ) ;
534
536
535
537
var _react2 = _interopRequireDefault ( _react ) ;
@@ -567,7 +569,9 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function"
567
569
var portalClassName = exports . portalClassName = 'ReactModalPortal' ;
568
570
var bodyOpenClassName = exports . bodyOpenClassName = 'ReactModal__Body--open' ;
569
571
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 ;
571
575
572
576
function getParentElement ( parentSelector ) {
573
577
return parentSelector ( ) ;
@@ -588,28 +592,32 @@ var Modal = function (_Component) {
588
592
}
589
593
590
594
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 ) ;
592
596
var parent = getParentElement ( _this . props . parentSelector ) ;
593
597
parent . removeChild ( _this . node ) ;
598
+ } , _this . portalRef = function ( ref ) {
599
+ _this . portal = ref ;
594
600
} , _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 ) ;
596
603
} , _temp ) , _possibleConstructorReturn ( _this , _ret ) ;
597
604
}
598
605
599
606
_createClass ( Modal , [ {
600
607
key : 'componentDidMount' ,
601
608
value : function componentDidMount ( ) {
602
- this . node = document . createElement ( 'div' ) ;
609
+ if ( ! canUseDOM ) return ;
603
610
this . node . className = this . props . portalClassName ;
604
611
605
612
var parent = getParentElement ( this . props . parentSelector ) ;
606
613
parent . appendChild ( this . node ) ;
607
614
608
- this . renderPortal ( this . props ) ;
615
+ ! isReact16 && this . renderPortal ( this . props ) ;
609
616
}
610
617
} , {
611
618
key : 'componentWillReceiveProps' ,
612
619
value : function componentWillReceiveProps ( newProps ) {
620
+ if ( ! canUseDOM ) return ;
613
621
var isOpen = newProps . isOpen ;
614
622
// Stop unnecessary renders if modal is remaining closed
615
623
@@ -623,19 +631,20 @@ var Modal = function (_Component) {
623
631
newParent . appendChild ( this . node ) ;
624
632
}
625
633
626
- this . renderPortal ( newProps ) ;
634
+ ! isReact16 && this . renderPortal ( newProps ) ;
627
635
}
628
636
} , {
629
637
key : 'componentWillUpdate' ,
630
638
value : function componentWillUpdate ( newProps ) {
639
+ if ( ! canUseDOM ) return ;
631
640
if ( newProps . portalClassName !== this . props . portalClassName ) {
632
641
this . node . className = newProps . portalClassName ;
633
642
}
634
643
}
635
644
} , {
636
645
key : 'componentWillUnmount' ,
637
646
value : function componentWillUnmount ( ) {
638
- if ( ! this . node || ! this . portal ) return ;
647
+ if ( ! canUseDOM || ! this . node || ! this . portal ) return ;
639
648
640
649
var state = this . portal . state ;
641
650
var now = Date . now ( ) ;
@@ -654,7 +663,17 @@ var Modal = function (_Component) {
654
663
} , {
655
664
key : 'render' ,
656
665
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 ) ;
658
677
}
659
678
} ] , [ {
660
679
key : 'setAppElement' ,
0 commit comments