import React, { PropsWithChildren, useContext, useRef } from "react"; import { useTheme } from "styled-components"; import Heading from "../../components/Heading/Heading"; import getThemeValue from "../../util/getThemeValue"; import { ModalBody, ModalHeader, ModalTitle, ModalContainer, ModalCloseButton, ModalBackButton } from "./styles"; import { ModalProps, ModalWrapperProps } from "./types"; import { useMatchBreakpoints } from "../../contexts"; import { ModalCoreContext } from "./ModalCore"; import { Box } from "../../components/Box"; export const MODAL_SWIPE_TO_CLOSE_VELOCITY = 300; export const ModalWrapper = ({ children, onDismiss, hideCloseButton, ...props }: PropsWithChildren) => { const { isMobile } = useMatchBreakpoints(); const wrapperRef = useRef(null); return ( // @ts-ignore { if (wrapperRef.current) wrapperRef.current.style.animation = "none"; }} // @ts-ignore onDragEnd={(e, info) => { if (info.velocity.y > MODAL_SWIPE_TO_CLOSE_VELOCITY && onDismiss) onDismiss(); }} ref={wrapperRef} style={{ overflow: "visible" }} > {children} ); }; const Modal: React.FC> = ({ title, onDismiss: onDismiss_, onBack, children, hideCloseButton = false, headerPadding = "12px 24px", bodyPadding = "24px", headerBackground = "transparent", minWidth = "320px", headerRightSlot, bodyAlignItems, headerBorderColor, bodyTop = "0px", ...props }) => { const context = useContext(ModalCoreContext); const onDismiss = context?.onDismiss || onDismiss_; const theme = useTheme(); return ( {onBack && } {title} {headerRightSlot} {!hideCloseButton && } e.stopPropagation()} p={bodyPadding} style={{ alignItems: bodyAlignItems ?? "normal" }} > {children} ); }; export default Modal;