-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathModalWrapper.js
44 lines (37 loc) · 921 Bytes
/
ModalWrapper.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import React, { useRef } from 'react'
import Reoverlay from './Reoverlay'
const ModalWrapper = ({
children,
wrapperClassName,
contentContainerClassName,
animation,
onClose,
}) => {
const wrapperElement = useRef(null)
const handleClose = (event) => {
onClose(event)
}
const handleClickOutside = (event) => {
if (event.target === wrapperElement.current) {
handleClose(event)
}
}
return (
<div
ref={wrapperElement}
role="dialog"
className={`reOverlay__modalWrapper -ro-${animation} ${wrapperClassName}`}
onClick={handleClickOutside}
>
<div className={`reOverlay__modalContainer ${contentContainerClassName}`}>{children}</div>
</div>
)
}
ModalWrapper.defaultProps = {
children: null,
wrapperClassName: '',
contentContainerClassName: '',
animation: 'fade',
onClose: () => Reoverlay.hideModal(),
}
export default ModalWrapper