Skip to content

Has anyone implemented a draggable drawer? #2116

Answered by laurensnl
paulbalogh asked this question in General
Discussion options

You must be logged in to vote

You can try something like this:

import {
  Button,
  Drawer,
  DrawerBody,
  DrawerContent,
  DrawerFooter,
  DrawerHeader,
  DrawerOverlay,
  useDisclosure,
} from '@chakra-ui/core';
import { motion, PanInfo } from 'framer-motion';

export const SwipableDrawer = () => {
  const { isOpen, onOpen, onClose } = useDisclosure();

  const swipeConfidenceThreshold = 5000;
  const swipePower = (offset: number, velocity: number) => Math.abs(offset) * velocity;

  const onDrag = async (e: MouseEvent | TouchEvent | PointerEvent, info: PanInfo) => {
    const { offset, velocity } = info;
    const swipe = swipePower(offset.x, velocity.x);
    if (offset.x > 0 && swipe > swipeConfidenceThreshold) on…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@paulbalogh
Comment options

Answer selected by chasinhues
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants