1- import PropTypes from 'prop-types' ;
21import React , { useCallback , useRef } from 'react' ;
32import MediaQuery from 'react-responsive' ;
43import { useSelector } from 'react-redux' ;
54import { useHistory } from 'react-router-dom' ;
65import { useTranslation } from 'react-i18next' ;
76import { useModalClose } from '../../../common/useModalClose' ;
7+ import type { RootState } from '../../../reducers' ;
88
99import ExitIcon from '../../../images/exit.svg' ;
1010
11- const Overlay = ( {
11+ type OverlayProps = {
12+ children ?: React . ReactElement ;
13+ actions ?: React . ReactElement ;
14+ closeOverlay ?: ( ) => void ;
15+ title ?: string ;
16+ ariaLabel ?: string ;
17+ isFixedHeight ?: boolean ;
18+ } ;
19+
20+ export const Overlay = ( {
1221 actions,
13- ariaLabel,
22+ ariaLabel = 'modal' ,
1423 children,
1524 closeOverlay,
16- isFixedHeight,
17- title
18- } ) => {
25+ isFixedHeight = false ,
26+ title = 'Modal'
27+ } : OverlayProps ) => {
1928 const { t } = useTranslation ( ) ;
2029
21- const previousPath = useSelector ( ( state ) => state . ide . previousPath ) ;
30+ const previousPath = useSelector (
31+ ( state : RootState ) => state . ide . previousPath
32+ ) ;
2233
23- const ref = useRef ( null ) ;
34+ const ref = useRef < HTMLElement > ( null ) ;
2435
2536 const browserHistory = useHistory ( ) ;
2637
@@ -29,7 +40,7 @@ const Overlay = ({
2940 if ( ! node ) return ;
3041 // Only close if it is the last (and therefore the topmost overlay)
3142 const overlays = document . getElementsByClassName ( 'overlay' ) ;
32- if ( node . parentElement . parentElement !== overlays [ overlays . length - 1 ] )
43+ if ( node . parentElement ? .parentElement !== overlays [ overlays . length - 1 ] )
3344 return ;
3445
3546 if ( ! closeOverlay ) {
@@ -76,23 +87,3 @@ const Overlay = ({
7687 </ div >
7788 ) ;
7889} ;
79-
80- Overlay . propTypes = {
81- children : PropTypes . element ,
82- actions : PropTypes . element ,
83- closeOverlay : PropTypes . func ,
84- title : PropTypes . string ,
85- ariaLabel : PropTypes . string ,
86- isFixedHeight : PropTypes . bool
87- } ;
88-
89- Overlay . defaultProps = {
90- children : null ,
91- actions : null ,
92- title : 'Modal' ,
93- closeOverlay : null ,
94- ariaLabel : 'modal' ,
95- isFixedHeight : false
96- } ;
97-
98- export default Overlay ;
0 commit comments