import { useEffect, useRef, ReactNode, Dispatch, SetStateAction } from "react"; import { AnimatePresence, motion, useAnimation } from "framer-motion"; import { cn } from "@/lib/utils"; export default function Leaflet({ setShow, children, }: { setShow: Dispatch>; children: ReactNode; }) { const leafletRef = useRef(null); const controls = useAnimation(); const transitionProps = { type: "spring", stiffness: 500, damping: 30 }; useEffect(() => { void controls.start({ y: 20, transition: transitionProps, }); // eslint-disable-next-line react-hooks/exhaustive-deps }, []); async function handleDragEnd( _: any, info: { delta: { x: number; y: number }; offset: { x: number; y: number }; point: { x: number; y: number }; velocity: { x: number; y: number }; } ) { const offset = info.offset.y; const velocity = info.velocity.y; const height = leafletRef.current?.getBoundingClientRect().height || 0; if (offset > height / 2 || velocity > 800) { await controls.start({ y: "100%", transition: transitionProps }); setShow(false); } else { void controls.start({ y: 0, transition: transitionProps }); } } return ( void handleDragEnd(_, i)} dragElastic={{ top: 0, bottom: 1 }} dragConstraints={{ top: 0, bottom: 0 }} >
{children}
setShow(false)} /> ); }