npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

flexible-dnd

v0.1.0

Published

A lightweight React drag-and-drop library

Downloads

8

Readme

flexible-dnd

A lightweight React drag-and-drop library

flexible-dnd is a lightweight drag-and-drop library for React components. Some inspiration is drawn from Dan Abramov's react-dnd. The most major departures from the react-dnd approach include:

  • No configurable backend or HTML5 drag-and-drop; touch-enabled custom drag-handling only
  • Drag hint rendering left entirely to the consumer

These departures are made largely in order to create a lightweight and flexible implementation that is capable of rendering a wider variety of drag-and-drop behaviors. Specifically, the library was created to give the author the ability to enable drag-and-drop of SVG elements, including specialized SVG rendering situations, such as dragging only one endpoint of a line.

DragDropContext

flexible-dnd tracks movement and drops in the context of a container component. Begin by applying the DragDropContext composable to your container element. The function connectDragDropContext will become available to your container via props. Apply this function to the element which you want to use to track dragging.

import React from 'react';
import { DragDropContext } from 'flexible-dnd';

class App extends React.Component {
  render() {
    const { connectDragDropContext } = this.props;

    return connectDragDropContext(
      <div>
        <DraggableComponent />
      </div>
    );
  }
}

App = DragDropContext(App);

DragSource

Apply the DragSource composable to any components that will render draggable elements. The function connectDragSource will be available on props, and should be applied to any elements that should be draggable.

You must handle rendering dragged elements yourself. If a DragSource currently has a dragged element, props.isDragging will be true. Mouse movement that has occurred is available via props.dragDeltaX and props.dragDeltaY.

import React from 'react';
import { DragSource } from 'flexible-dnd';

class DraggableComponent extends React.Component {
  render() {
    var x = 20,
        y = 20,
        style;

    const { connectDragSource } = this.props;

    if (this.props.isDragging) {
      x += this.props.dragDeltaX;
      y += this.props.dragDeltaY;
    }

    style = {
      position: 'absolute',
      left: x,
      top: y,
      width: 20,
      height: 20,
      backgroundColor: 'blue'
    };

    return connectDragSource(<div key="source" style={style} />);
  }
}

DraggableComponent = DragSource(DraggableComponent);

If the DragSource component contains multiple draggable elements, you can apply the key property to those elements, and the value corresponding to the dragged element will be passed down as props.dragKey.

DropTarget

Apply the DropTarget composable to any components that will render elements that can receive draggable elements. The function connectDropTarget will be available on props, and should be applied to any elements that should be capable of receiving draggables.

When the mouse is above a drop target during a drag operation, props.isHovering will be true.

The DropTarget composable takes as a second parameter a configuration object. This object must define two functions, canDrop and drop. Each function is called with the original component instance as this and is passed the dragged component instance and dragKey. The drop function additionally receives a dropKey parameter.

import React from 'react';
import { DropTarget } from 'flexible-dnd';

class DroppableComponent extends React.Component {
  render() {
    var style = {
      position: 'absolute',
      left: 50,
      top: 50,
      width: 20,
      height: 20,
      backgroundColor: 'green'
    };;

    const { connectDropTarget } = this.props;
    const { dropped } = this.state;

    if (this.props.isHovering) {
      style.borderColor = 'red';
      style.borderStyle = 'solid';
      style.borderWidth = 2;
    }

    if (dropped) {
      style.backgroundColor = 'orange';
    }

    return connectDropTarget(<div key="target" style={style} />);
  }
}

function canDrop(source, dragKey) {
  return source.displayName === 'Draggable';
}

function drop(source, dragKey, dropKey) {
  this.setState({
    dropped: true
  });
}

DroppableComponent = DropTarget(DroppableComponent, {
  canDrop,
  drop
});

If the DropTarget component contains multiple elements capable of receiving a draggable, you can apply the key property to those elements, and the value corresponding to the element being hovered over will be passed down as props.dropKey.

Examples

Example usage can be found in the example folder. Run gulp example to build the example files.