-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPopupContainer.tsx
More file actions
50 lines (46 loc) · 1.35 KB
/
PopupContainer.tsx
File metadata and controls
50 lines (46 loc) · 1.35 KB
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
import { useEffect } from 'react';
import { createPortal } from 'react-dom';
import Popup from './Popup';
type PopupType = 'input' | 'subtext' | 'default';
interface BasePopupProps {
type: PopupType;
title: string;
left: string;
right: string;
subtext?: string;
placeholder?: string;
isError?: boolean;
helperText?: string;
onLeftClick?: () => void;
onRightClick?: () => void;
}
interface PopupContainerProps extends BasePopupProps {
isOpen: boolean;
onClose: () => void;
}
const PopupContainer = ({
isOpen,
onClose,
...popupProps
}: PopupContainerProps) => {
// ESC 키로 닫는 것 정도 (외부 클릭은 안되게! : 어차피 x박스나 취소버튼이 있음)
useEffect(() => {
if (!isOpen) return;
const handleEsc = (e: KeyboardEvent) => {
if (e.key === 'Escape') onClose();
};
window.addEventListener('keydown', handleEsc);
return () => window.removeEventListener('keydown', handleEsc);
}, [isOpen, onClose]);
if (!isOpen) return null;
return createPortal(
<div className="fixed inset-0 z-10 flex items-center justify-center">
<div className="absolute inset-0 bg-[#00000099]" />
<div className="relative">
<Popup {...popupProps} onLeftClick={onClose} />
</div>
</div>,
document.body // body 위에서 렌더링 되게 함!
);
};
export default PopupContainer;