-
Notifications
You must be signed in to change notification settings - Fork 5
/
modal.tsx
84 lines (73 loc) · 1.9 KB
/
modal.tsx
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import Rodal from 'rodal';
import React, { useEffect, useMemo, useState } from 'react';
import { useMasa } from '../../provider';
function getWindowDimensions() {
if (typeof window === 'undefined') return { width: 0, height: 0 };
const { innerWidth: width, innerHeight: height } = window;
return {
width,
height,
};
}
export default function useWindowDimensions() {
const [windowDimensions, setWindowDimensions] = useState(
getWindowDimensions()
);
useEffect(() => {
function handleResize() {
setWindowDimensions(getWindowDimensions());
}
if (typeof window !== 'undefined')
window.addEventListener('resize', handleResize);
return () => {
if (typeof window !== 'undefined')
window.removeEventListener('resize', handleResize);
};
}, []);
return windowDimensions;
}
const useIsMobile = () => {
const { height, width } = useWindowDimensions();
const isMobile = useMemo(() => {
return width < 480;
}, [width]);
return { isMobile, height, width };
};
export interface ModalProps {
children: React.ReactNode;
open: boolean;
setOpen: (val: boolean) => void;
close: () => void;
height?: number;
}
export const ModalComponent = ({
children,
open,
close,
height,
}: ModalProps): JSX.Element => {
const { isMobile, height: screenHeight, width: screenWidth } = useIsMobile();
const { modalSize } = useMasa();
return (
<Rodal
data-cy="closeMasaModal"
height={
isMobile
? screenHeight
: modalSize
? modalSize.height
: height
? height
: 615
}
width={isMobile ? screenWidth : modalSize ? modalSize.width : 550}
visible={open}
onClose={(): void => close()}
className="masa-rodal-container"
>
<div className="masa-modal">
<div className="masa-modal-container">{children}</div>
</div>
</Rodal>
);
};