diff --git a/src/app/molecules/mobile-context-menu/MobileContextMenu.jsx b/src/app/molecules/mobile-context-menu/MobileContextMenu.jsx new file mode 100644 index 00000000..e2915e7c --- /dev/null +++ b/src/app/molecules/mobile-context-menu/MobileContextMenu.jsx @@ -0,0 +1,62 @@ +import React, { useEffect } from 'react'; +import { useSpring, animated } from '@react-spring/web'; +import { useDrag } from 'react-use-gesture'; +import './MobileContextMenu.scss'; + +export function MobileContextMenu({ isOpen, onClose, children }) { + const { innerHeight } = window; + + const [{ y }, api] = useSpring(() => ({ + y: innerHeight, + config: { tension: 250, friction: 25 }, + })); + + useEffect(() => { + api.start({ y: isOpen ? 0 : innerHeight }); + }, [api, innerHeight, isOpen]); + + const bind = useDrag( + ({ last, movement: [, my], velocities: [, vy] }) => { + if (last) { + if (my > innerHeight / 4) { + onClose(); + } else { + api.start({ y: 0 }); + } + } else { + api.start({ y: Math.max(my, 0), immediate: true }); + } + }, + { + from: () => [0, y.get()], + filterTaps: true, + bounds: { top: 0 }, + rubberband: true, + } + ); + if (!isOpen) return null; + + return ( + <> + + + +
+
{children}
+ + + ); +} + +export default MobileContextMenu;