Skip to content

armgit / mimik

Public Imported from GitHub
0

🎬 A browser extension and desktop app that turns your clicks into step-by-step guides with annotated screenshots πŸ“–

562 B
Raw Blame
import { useRef } from 'react';
import type { DragHandleProps } from '../types';

export function useCardDrag(dragHandleProps?: DragHandleProps) {
  const pressedHandle = useRef(false);
  return {
    draggable: !!dragHandleProps,
    onPointerDownCapture: (e: React.PointerEvent) => {
      pressedHandle.current = !!(e.target as Element).closest('[data-drag-handle]');
    },
    onDragStart: (e: React.DragEvent) => {
      if (!pressedHandle.current) {
        e.preventDefault();
        return;
      }
      dragHandleProps?.onDragStart(e);
    },
  };
}