1- var React = require ( 'react' ) ;
2- var ReactDOM = require ( 'react-dom' ) ;
3- var DOMFactories = require ( 'react-dom-factories' ) ;
4- var PropTypes = require ( 'prop-types' ) ;
5- var ExecutionEnvironment = require ( 'exenv' ) ;
6- var ModalPortal = React . createFactory ( require ( './ModalPortal' ) ) ;
7- var ariaAppHider = require ( '../helpers/ariaAppHider' ) ;
8- var refCount = require ( '../helpers/refCount' ) ;
9- var elementClass = require ( 'element-class' ) ;
10- var renderSubtreeIntoContainer = require ( "react-dom" ) . unstable_renderSubtreeIntoContainer ;
11- var Assign = require ( 'lodash.assign' ) ;
12- var createReactClass = require ( 'create-react-class' ) ;
13-
14- var SafeHTMLElement = ExecutionEnvironment . canUseDOM ? window . HTMLElement : { } ;
15- var AppElement = ExecutionEnvironment . canUseDOM ? document . body : { appendChild : function ( ) { } } ;
1+ import React , { Component } from 'react' ;
2+ import ReactDOM from 'react-dom' ;
3+ import PropTypes from 'prop-types' ;
4+ import ExecutionEnvironment from 'exenv' ;
5+ import ModalPortal from './ModalPortal' ;
6+ import elementClass from 'element-class' ;
7+ import * as ariaAppHider from '../helpers/ariaAppHider' ;
8+ import * as refCount from '../helpers/refCount' ;
9+
10+ const renderSubtreeIntoContainer = ReactDOM . unstable_renderSubtreeIntoContainer ;
11+
12+ const SafeHTMLElement = ExecutionEnvironment . canUseDOM ? window . HTMLElement : { } ;
13+ let AppElement = ExecutionEnvironment . canUseDOM ? document . body : { appendChild : function ( ) { } } ;
1614
1715function getParentElement ( parentSelector ) {
1816 return parentSelector ( ) ;
1917}
2018
21- var Modal = createReactClass ( {
19+ export default class Modal extends Component {
20+ static setAppElement = function ( element ) {
21+ AppElement = ariaAppHider . setElement ( element ) ;
22+ } ;
2223
23- displayName : 'Modal' ,
24- statics : {
25- setAppElement : function ( element ) {
26- AppElement = ariaAppHider . setElement ( element ) ;
27- } ,
28- injectCSS : function ( ) {
29- "production" !== process . env . NODE_ENV
30- && console . warn ( 'React-Modal: injectCSS has been deprecated ' +
31- 'and no longer has any effect. It will be removed in a later version' ) ;
32- }
33- } ,
24+ static injectCSS = function ( ) {
25+ "production" !== process . env . NODE_ENV
26+ && console . warn ( 'React-Modal: injectCSS has been deprecated ' +
27+ 'and no longer has any effect. It will be removed in a later version' ) ;
28+ } ;
3429
35- propTypes : {
30+ static propTypes = {
3631 isOpen : PropTypes . bool . isRequired ,
3732 style : PropTypes . shape ( {
3833 content : PropTypes . object ,
@@ -49,52 +44,75 @@ var Modal = createReactClass({
4944 parentSelector : PropTypes . func ,
5045 role : PropTypes . string ,
5146 contentLabel : PropTypes . string . isRequired
52- } ,
53-
54- getDefaultProps : function ( ) {
55- return {
56- isOpen : false ,
57- portalClassName : 'ReactModalPortal' ,
58- bodyOpenClassName : 'ReactModal__Body--open' ,
59- ariaHideApp : true ,
60- closeTimeoutMS : 0 ,
61- shouldCloseOnOverlayClick : true ,
62- parentSelector : function ( ) { return document . body ; }
63- } ;
64- } ,
65-
66- componentDidMount : function ( ) {
47+ } ;
48+
49+ static defaultProps = {
50+ isOpen : false ,
51+ portalClassName : 'ReactModalPortal' ,
52+ bodyOpenClassName : 'ReactModal__Body--open' ,
53+ ariaHideApp : true ,
54+ closeTimeoutMS : 0 ,
55+ shouldCloseOnOverlayClick : true ,
56+ parentSelector : function ( ) { return document . body ; }
57+ } ;
58+
59+ static defaultStyles = {
60+ overlay : {
61+ position : 'fixed' ,
62+ top : 0 ,
63+ left : 0 ,
64+ right : 0 ,
65+ bottom : 0 ,
66+ backgroundColor : 'rgba(255, 255, 255, 0.75)'
67+ } ,
68+ content : {
69+ position : 'absolute' ,
70+ top : '40px' ,
71+ left : '40px' ,
72+ right : '40px' ,
73+ bottom : '40px' ,
74+ border : '1px solid #ccc' ,
75+ background : '#fff' ,
76+ overflow : 'auto' ,
77+ WebkitOverflowScrolling : 'touch' ,
78+ borderRadius : '4px' ,
79+ outline : 'none' ,
80+ padding : '20px'
81+ }
82+ } ;
83+
84+ componentDidMount ( ) {
6785 this . node = document . createElement ( 'div' ) ;
6886 this . node . className = this . props . portalClassName ;
6987
7088 if ( this . props . isOpen ) refCount . add ( this ) ;
7189
72- var parent = getParentElement ( this . props . parentSelector ) ;
90+ const parent = getParentElement ( this . props . parentSelector ) ;
7391 parent . appendChild ( this . node ) ;
7492 this . renderPortal ( this . props ) ;
75- } ,
93+ }
7694
77- componentWillUpdate : function ( newProps ) {
95+ componentWillUpdate ( newProps ) {
7896 if ( newProps . portalClassName !== this . props . portalClassName ) {
7997 this . node . className = newProps . portalClassName ;
8098 }
81- } ,
99+ }
82100
83- componentWillReceiveProps : function ( newProps ) {
101+ componentWillReceiveProps ( newProps ) {
84102 if ( newProps . isOpen ) refCount . add ( this ) ;
85103 if ( ! newProps . isOpen ) refCount . remove ( this ) ;
86- var currentParent = getParentElement ( this . props . parentSelector ) ;
87- var newParent = getParentElement ( newProps . parentSelector ) ;
104+ const currentParent = getParentElement ( this . props . parentSelector ) ;
105+ const newParent = getParentElement ( newProps . parentSelector ) ;
88106
89- if ( newParent !== currentParent ) {
107+ if ( newParent !== currentParent ) {
90108 currentParent . removeChild ( this . node ) ;
91109 newParent . appendChild ( this . node ) ;
92110 }
93111
94112 this . renderPortal ( newProps ) ;
95- } ,
113+ }
96114
97- componentWillUnmount : function ( ) {
115+ componentWillUnmount ( ) {
98116 if ( ! this . node ) return ;
99117
100118 refCount . remove ( this ) ;
@@ -103,9 +121,9 @@ var Modal = createReactClass({
103121 ariaAppHider . show ( this . props . appElement ) ;
104122 }
105123
106- var state = this . portal . state ;
107- var now = Date . now ( ) ;
108- var closesAt = state . isOpen && this . props . closeTimeoutMS
124+ const state = this . portal . state ;
125+ const now = Date . now ( ) ;
126+ const closesAt = state . isOpen && this . props . closeTimeoutMS
109127 && ( state . closesAt
110128 || now + this . props . closeTimeoutMS ) ;
111129
@@ -114,24 +132,24 @@ var Modal = createReactClass({
114132 this . portal . closeWithTimeout ( ) ;
115133 }
116134
117- var that = this ;
135+ const that = this ;
118136 setTimeout ( function ( ) { that . removePortal ( ) ; } , closesAt - now ) ;
119137 } else {
120138 this . removePortal ( ) ;
121139 }
122- } ,
140+ }
123141
124- removePortal : function ( ) {
142+ removePortal = ( ) => {
125143 ReactDOM . unmountComponentAtNode ( this . node ) ;
126- var parent = getParentElement ( this . props . parentSelector ) ;
144+ const parent = getParentElement ( this . props . parentSelector ) ;
127145 parent . removeChild ( this . node ) ;
128146
129147 if ( refCount . count ( ) === 0 ) {
130148 elementClass ( document . body ) . remove ( this . props . bodyOpenClassName ) ;
131149 }
132- } ,
150+ }
133151
134- renderPortal : function ( props ) {
152+ renderPortal = props => {
135153 if ( props . isOpen || refCount . count ( ) > 0 ) {
136154 elementClass ( document . body ) . add ( this . props . bodyOpenClassName ) ;
137155 } else {
@@ -142,37 +160,12 @@ var Modal = createReactClass({
142160 ariaAppHider . toggle ( props . isOpen , props . appElement ) ;
143161 }
144162
145- this . portal = renderSubtreeIntoContainer ( this , ModalPortal ( Assign ( { } , props , { defaultStyles : Modal . defaultStyles } ) ) , this . node ) ;
146- } ,
147-
148- render : function ( ) {
149- return DOMFactories . noscript ( ) ;
163+ this . portal = renderSubtreeIntoContainer ( this , (
164+ < ModalPortal defaultStyles = { Modal . defaultStyles } { ...props } />
165+ ) , this . node ) ;
150166 }
151- } ) ;
152-
153- Modal . defaultStyles = {
154- overlay : {
155- position : 'fixed' ,
156- top : 0 ,
157- left : 0 ,
158- right : 0 ,
159- bottom : 0 ,
160- backgroundColor : 'rgba(255, 255, 255, 0.75)'
161- } ,
162- content : {
163- position : 'absolute' ,
164- top : '40px' ,
165- left : '40px' ,
166- right : '40px' ,
167- bottom : '40px' ,
168- border : '1px solid #ccc' ,
169- background : '#fff' ,
170- overflow : 'auto' ,
171- WebkitOverflowScrolling : 'touch' ,
172- borderRadius : '4px' ,
173- outline : 'none' ,
174- padding : '20px'
167+
168+ render ( ) {
169+ return null ;
175170 }
176171}
177-
178- module . exports = Modal
0 commit comments