Skip to content

Commit

Permalink
feat: 모달 컴포넌트 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
happyGyu committed Jun 29, 2024
1 parent 2846416 commit c719474
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/components/common/Modal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { AnimatePresence, motion } from "framer-motion";
import type { FC, ReactNode } from "react";
import { createPortal } from "react-dom";

type ModalProps = {
isOpen: boolean;
onClose: () => void;
children: ReactNode;
};

const Modal: FC<ModalProps> = ({ isOpen, onClose, children }) => {
return createPortal(
<AnimatePresence>
{isOpen && (
<motion.div
className="fixed inset-0 bg-gray100 bg-opacity-50 flex items-center justify-center"
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
exit={{ opacity: 0 }}
onClick={onClose}
>
<motion.div
className="bg-offWhite010 p-4 rounded-20"
initial={{ scale: 0.5, opacity: 0 }}
animate={{ scale: 1, opacity: 1 }}
exit={{ scale: 0.5, opacity: 0 }}
onClick={(e) => e.stopPropagation()}
>
{children}
</motion.div>
</motion.div>
)}
</AnimatePresence>,
document.body,
);
};

export default Modal;

0 comments on commit c719474

Please # to comment.