diff --git a/app/components/modals/ImageModal.tsx b/app/components/modals/ImageModal.tsx
index d72a35d4..3574dfcb 100644
--- a/app/components/modals/ImageModal.tsx
+++ b/app/components/modals/ImageModal.tsx
@@ -3,9 +3,13 @@
import useImageModal from '@/app/hooks/useImageModal';
import { X } from '@phosphor-icons/react';
import { useEffect, useState } from 'react';
+import { useOutsideClickModal } from '@/app/hooks/useOutsideClickModal';
const ImageModal = () => {
const imageModal = useImageModal();
+ const thisRef = useOutsideClickModal(() => {
+ handleClose();
+ });
const [showModal, setShowModal] = useState(imageModal.isOpen);
@@ -14,6 +18,7 @@ const ImageModal = () => {
}, [imageModal.isOpen]);
const handleClose = () => {
+ setShowModal(false);
setTimeout(() => {
imageModal.onClose();
}, 300);
@@ -24,9 +29,8 @@ const ImageModal = () => {
}
return (
- <>
-
{
focus:outline-none
bg-neutral-800/70
"
- >
-
{
lg:h-auto
md:h-auto
"
- >
-
+
{
${showModal ? 'translate-y-0' : 'translate-y-full'}
${showModal ? 'opacity-100' : 'opacity-0'}
`}
- >
-
{
outline-none
focus:outline-none
"
- >
-
{
relative
border-b-[1px]
"
- >
-
-
-
-
-
+ >
+
+
+
+
+
- >
+
);
};
diff --git a/app/components/modals/Modal.tsx b/app/components/modals/Modal.tsx
index 8a788874..41c32d58 100644
--- a/app/components/modals/Modal.tsx
+++ b/app/components/modals/Modal.tsx
@@ -3,6 +3,7 @@
import React, { useCallback, useEffect, useState } from 'react';
import { X } from '@phosphor-icons/react';
import Button from '../Button';
+import { useOutsideClickModal } from '@/app/hooks/useOutsideClickModal';
interface ModalProps {
isOpen?: boolean;
@@ -30,6 +31,9 @@ const Modal: React.FC = ({
secondaryActionLabel,
}) => {
const [showModal, setShowModal] = useState(isOpen);
+ const thisRef = useOutsideClickModal(() => {
+ handleClose();
+ });
useEffect(() => {
setShowModal(isOpen);
@@ -115,6 +119,7 @@ const Modal: React.FC = ({
outline-none
focus:outline-none
"
+ ref={thisRef}
>
diff --git a/app/hooks/useOutsideClickModal.ts b/app/hooks/useOutsideClickModal.ts
new file mode 100644
index 00000000..1225413b
--- /dev/null
+++ b/app/hooks/useOutsideClickModal.ts
@@ -0,0 +1,21 @@
+import { useEffect, useRef } from 'react';
+
+export const useOutsideClickModal = (callback: () => void) => {
+ const ref = useRef(null);
+
+ useEffect(() => {
+ const handleClickOutside = (event: MouseEvent) => {
+ if (ref.current && !ref.current.contains(event.target as Node)) {
+ callback();
+ }
+ };
+
+ document.addEventListener('mousedown', handleClickOutside);
+
+ return () => {
+ document.removeEventListener('mousedown', handleClickOutside);
+ };
+ }, [callback]);
+
+ return ref;
+};