From 60116fc8f1d2ec188a40963aeefd11cd2eaa8ebb Mon Sep 17 00:00:00 2001 From: seondal Date: Wed, 20 Mar 2024 05:10:36 +0900 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor=20:=20=20ModalWra?= =?UTF-8?q?pper=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Modal/ImageModal.client.tsx | 18 ---------- src/components/Modal/ModalWrapper.tsx | 39 ---------------------- src/hooks/useOnClickOutside.ts | 25 -------------- 3 files changed, 82 deletions(-) delete mode 100644 src/components/Modal/ImageModal.client.tsx delete mode 100644 src/components/Modal/ModalWrapper.tsx delete mode 100644 src/hooks/useOnClickOutside.ts diff --git a/src/components/Modal/ImageModal.client.tsx b/src/components/Modal/ImageModal.client.tsx deleted file mode 100644 index ca5eb363..00000000 --- a/src/components/Modal/ImageModal.client.tsx +++ /dev/null @@ -1,18 +0,0 @@ -import Image from 'next/image'; - -import ModalWrapper from './ModalWrapper'; - -interface ImageModalProps { - image: string; - onClose: () => void; -} - -export default function ImageModal({ image, onClose }: ImageModalProps) { - return ( - -
- fullImage -
-
- ); -} diff --git a/src/components/Modal/ModalWrapper.tsx b/src/components/Modal/ModalWrapper.tsx deleted file mode 100644 index b7f867ab..00000000 --- a/src/components/Modal/ModalWrapper.tsx +++ /dev/null @@ -1,39 +0,0 @@ -'use client'; -import { motion } from 'framer-motion'; -import { useRef } from 'react'; - -import { useOnClickOutside } from '@/hooks/useOnClickOutside'; -import cn from '@/utils/cn'; - -import type { StrictPropsWithChildren } from '@/types'; - -interface ModalWrapperProps { - onClose?: () => void; - className?: string; -} - -export default function ModalWrapper({ - onClose = () => {}, - className, - children, -}: StrictPropsWithChildren) { - const modalRef = useRef(null); - - useOnClickOutside(modalRef, onClose); - - return ( - -
- {children} -
-
- ); -} diff --git a/src/hooks/useOnClickOutside.ts b/src/hooks/useOnClickOutside.ts deleted file mode 100644 index 44a1d18c..00000000 --- a/src/hooks/useOnClickOutside.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { useEffect } from 'react'; - -export function useOnClickOutside( - ref: React.RefObject, - handler: (event: MouseEvent | TouchEvent) => void -) { - useEffect(() => { - const listener = (event: MouseEvent | TouchEvent) => { - event.stopPropagation(); - if (!ref.current || ref.current.contains(event.target as Node)) { - return; - } - - handler(event); - }; - - document.addEventListener('mousedown', listener); - document.addEventListener('touchstart', listener); - - return () => { - document.removeEventListener('mousedown', listener); - document.removeEventListener('touchstart', listener); - }; - }, [ref, handler]); -}