diff --git a/src/components/Modal.jsx b/src/components/Modal.jsx index 4f8a3c88c..82f864d70 100644 --- a/src/components/Modal.jsx +++ b/src/components/Modal.jsx @@ -1,14 +1,15 @@ import { Dialog, Transition } from "@headlessui/react"; import clsx from "clsx"; import PropTypes from "prop-types"; -import React, { Fragment } from "react"; +import React, { Fragment, useState } from "react"; import { CloseIcon } from "../icons/CloseIcon"; +// Widths are for desktop designs because mobile is always full width const sizes = { - small: "max-w-100", - medium: "max-w-125", - large: "max-w-150", - huge: "max-w-200", + small: "sm:max-w-100", + medium: "sm:max-w-125", + large: "sm:max-w-150", + huge: "sm:max-w-200", }; export const Modal = ({ @@ -25,10 +26,36 @@ export const Modal = ({ } }; + const [clientY, setClientY] = useState(); + const handleTouchStart = (e) => { + e.stopPropagation(); + setClientY(e.touches?.[0].clientY); + }; + + const handleTouchMove = (e) => { + e.stopPropagation(); + const currentY = e.touches?.[0].clientY; + const diffY = currentY - clientY; + if (diffY > 80) { + // The swipe was more than 80px, so close the div + setTimeout(() => { + // Hack because sometimes there are other operations queued up and calling close now won't close it + onClose(); + setClientY(null); + }, 100); + } + }; + return ( - -
+ +
- {/* This element is to trick the browser into centering the modal contents. */} -