How to use the react-dnd.useDrop function in react-dnd

To help you get started, we’ve selected a few react-dnd examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jamstack-cms / jamstack-cms / src / components / pageTemplates / heroTemplate.js View on Github external
function Draggable({ content, updateContent, currentView, component: Component, id, deleteComponent, index, moveCard, theme }) {
  const ref = useRef(null)
  const [, drop] = useDrop({
    accept: 'COMPONENT',
    hover(item, monitor) {
      if (!ref.current) {
        return
      }
      const dragIndex = item.index
      const hoverIndex = index
      // Don't replace items with themselves
      if (dragIndex === hoverIndex) {
        return
      }
      // Determine rectangle on screen
      const hoverBoundingRect = ref.current.getBoundingClientRect()
      // Get vertical middle
      const hoverMiddleY =
        (hoverBoundingRect.bottom - hoverBoundingRect.top) / 2
github MichelleWillaQu / ObjectViewGallery-Art-Showcase / static / gallery.js View on Github external
// entire lifetime of the component
  const reference = useRef(null);

  const [{isDragging}, drag] = useDrag({
    item: {id: props.id,
           name: props.name,
           order: props.order, 
           type: ItemTypes.TWOD,
           url: props.url},
    canDrag: () => props.editMode,
    collect: (monitor) => ({
      isDragging: !!monitor.isDragging()
    })
  });

  const [, drop] = useDrop({
    accept: [ItemTypes.TWOD, ItemTypes.OBJ, ItemTypes.GLTF],
    canDrop: () => props.editMode,
    hover(item) {
      if (item.order !== props.order){
        props.onHover(item, props);
      }
    }
  });
  // Initialize drag and drop reference component
  drag(drop(reference))
  // Background-image over img tag to be able to use background-size/position
  const imageElement = (
    <div style="{{backgroundImage:" name="{props.name}"></div>
github mikey1384 / twinkle-network / source / components / SortableThumb.js View on Github external
export default function SortableThumb({ id, onMove, video }) {
  const [onTitleHover, setOnTitleHover] = useState(false);
  const Draggable = useRef(null);
  const ThumbLabelRef = useRef(null);
  const [{ isDragging }, drag] = useDrag({
    item: { type: ItemTypes.THUMB, id },
    collect: monitor =&gt; ({
      isDragging: !!monitor.isDragging()
    })
  });
  const [, drop] = useDrop({
    accept: ItemTypes.THUMB,
    hover(item) {
      if (!Draggable.current) {
        return;
      }
      if (item.id !== id) {
        onMove({ sourceId: item.id, targetId: id });
      }
    }
  });

  return (
github MichelleWillaQu / ObjectViewGallery-Art-Showcase / static / user-gallery.js View on Github external
function Square(props){
  const [, drop] = useDrop({
    accept: [ItemTypes.TWOD, ItemTypes.THREED],
    drop: (item) =&gt; props.changeState(props.x, props.y, item.id),
  })
  return(<div style="{{width:">
            {props.children}
         </div>);
}
github Heigvd / Wegas / wegas-app / src / main / webapp / 2 / src / Editor / Components / FileBrowser / FileBrowserNode.tsx View on Github external
setModalState({ type: 'close' });
      })
      .catch(({ statusText }: Response) => {
        setModalState({
          type: 'error',
          label: statusText,
        });
      });
  };

  const openFile = (file: IAbstractContentDescriptor) => {
    const win = window.open(fileURL(generateAbsolutePath(file)), '_blank');
    win!.focus();
  };

  const [dropZoneProps, dropZone] = useDrop(
    dropSpecs(item => {
      const { files } = (item as unknown) as {
        files: FileList;
        items: DataTransferItemList;
      };
      if (dropZoneProps.isShallowOver) {
        insertFiles(files, newFiles => {
          if (newFiles.length > 0) {
            setOpen(true);
          }
        });
      }
    }),
  );

  const timeoutBeforeExpend = 1000;
github Heigvd / Wegas / wegas-app / src / main / webapp / 2 / src / Editor / Components / FileBrowser / TreeFileBrowser / FileBrowserNode.tsx View on Github external
insertFiles,
  uploadFiles,
  children,
  selected = false,
  defaultOpen = false,
}: React.PropsWithChildren) {
  const [open, setOpen] = React.useState(defaultOpen);

  const uploader = React.useRef(null);

  const openFile = (file: IFileDescriptor) =&gt; {
    const win = window.open(fileURL(generateAbsolutePath(file)), '_blank');
    win!.focus();
  };

  const [dropZoneProps, dropZone] = useDrop(
    dropSpecs(item =&gt; {
      const { files } = (item as unknown) as {
        files: FileList;
        items: DataTransferItemList;
      };
      insertFiles(files, generateAbsolutePath(file), newFiles =&gt; {
        if (newFiles.length &gt; 0) {
          setOpen(true);
        }
      });
    }),
  );

  const timeoutBeforeExpend = 1000;

  React.useEffect(() =&gt; {
github mozilla / Spoke / src / ui / viewport / ViewportPanelContainer.js View on Github external
editor.initializeRenderer(canvasRef.current);

    return () => {
      editor.removeListener("selectionChanged", onSelectionChanged);

      if (editor.spokeControls) {
        editor.spokeControls.removeListener("flyModeChanged", onFlyModeChanged);
      }

      if (editor.renderer) {
        editor.renderer.dispose();
      }
    };
  }, [editor, canvasRef, onEditorInitialized, onSelectionChanged, onFlyModeChanged]);

  const [{ canDrop, isOver }, dropRef] = useDrop({
    accept: [ItemTypes.Node, ...AssetTypes],
    drop(item, monitor) {
      const mousePos = monitor.getClientOffset();

      if (item.type === ItemTypes.Node) {
        if (item.multiple) {
          editor.reparentToSceneAtCursorPosition(item.value, mousePos);
        } else {
          editor.reparentToSceneAtCursorPosition([item.value], mousePos);
        }

        return;
      }

      addAssetAtCursorPositionOnDrop(editor, item, mousePos);
    },
github monjason23 / burger-dash / src / containers / GameDroppableArea.jsx View on Github external
);

  function serveBurgerCallback(res) {
    if (res) {
      playOnEveryInteraction();
    }
  }

  useEffect(() =&gt; {
    if (!ordersComplete) return;
    setTimeout(() =&gt; {
      dispatch(serveBurger(serveBurgerCallback));
    }, 200);
  }, [ordersComplete]);

  const [{ canDrop }, drop] = useDrop({
    accept: "BurgerIngredient",
    drop: () =&gt; ({ name: "Burger" })
  });

  return ;
}
github veritone / veritone-sdk / packages / veritone-react-common / src / components / FormBuilder / hooks / useSortable.js View on Github external
export default function useSortable(index, type, dropRef, addBlock, swapBlock) {
  const [{ isDragging }, drag, preview] = useDrag({
    item: {
      index,
      type,
    },
    collect: monitor => ({
      isDragging: monitor.isDragging(),
    })
  });

  const [{ isHovered }, drop] = useDrop({
    accept: type,
    hover: (item, monitor) => {
      if (!dropRef.current) {
        return;
      }

      if (isNaN(item.index)) {
        addBlock(index, item.id);
        item.index = index;
        return;
      }

      const dragIndex = item.index
      const hoverIndex = index

      if (dragIndex === hoverIndex) {
github lytc / react-sortly / packages / react-sortly / src / Item.tsx View on Github external
},
    collect: (monitor) => ({
      isDragging: monitor.isDragging(),
    }),
    isDragging: (monitor) => id === monitor.getItem().id,
    begin: (monitor) => {
      setInitialDepth(depth);
      setDragMonitor(monitor);
      setConnectedDragSource(connectedDragRef);
    },
    end: () => {
      setInitialDepth(undefined);
      setDragMonitor(undefined);
    },
  });
  const [{ hovered }, dndDrop] = useDrop({
    accept: t,
    collect: (monitor) => ({
      hovered: monitor.isOver({ shallow: true }),
    }),
  });

  React.useEffect(() => {
    if (hovered) {
      onHoverBegin(id, connectedDropRef);
      wasHoveredRef.current = true;
    } else if (wasHoveredRef.current === true) {
      onHoverEnd(id);
    }
  }, [hovered]);

  const drag = (connectable: ConnectableElement) => {