Package Exports
- react-dnd
- react-dnd/modules/backends/HTML5
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (react-dnd) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
react-dnd
Drag and drop for React with full DOM control.
Currently works on top of HTML5 drag-and-drop API, but is moving towards a swappable implementation. Support for touch events is on the roadmap but not currently implemented.
Philosophy
- Keep user in full control over rendering;
- Don't make assumptions about consuming components and their structure;
- Hide underlying implementation and its quirks;
- Make 80% easy, 20% possible.
Live Demo
See it in action!
Demo contains a variety of things you can implement with this library, including:
- Reacting to hover and dropping;
- Dropping files;
- Dragging a box around with snapping;
- Drawing a custom drag layer;
- Making cards sortable.
You can do much more, but these examples will help you get started!
Features
- Emits zero DOM or CSS of its own;
- Like original HTML5 API, emphasizes dragging data and not just “draggable views”;
- Support dropping files using the same API;
- Lets components register as “drag sources” or “drop targets” for different kinds of data;
- Lets a single component contain several drag sources and drop targets;
- Lets you provide a custom drag handle, whether DOM subnode or an image;
- Takes the best from HTML5 API but hides its many quirks:
- doesn't require you to
preventDefault
anything to start working; - emits
enter
andleave
as you'd expect instead of doing it for every child node; - lets you read drag state from
render()
; - consistently fires events even if source DOM node was removed;
- doesn't require you to
- Includes a helper to preload images for drag thumbnails;
- Lets you render a custom drag layer if you'd rather draw your own drag preview.
Documentation
API Reference
Complete API reference is available here.
Walkthrough
If you don't feel comfortable diving into examples source code just yet, you can start with the walkthrough.
Examples
Have you played with live demo yet? Here's the source code for it.
To try it locally, clone the project and run:
npm install
npm start
open http://localhost:8080/
Examples use ES6 syntax.
Installation
The library can be used separately (dist/ReactDND.min.js
) or with a bundler such as Webpack or Browserify.
npm install --save react-dnd
Future Roadmap
- Touch support;
- Support for mouse events instead of HTML5 drag-and-drop events;
- Dragging multiple items at once.
Production Usage
- Stampsy, where it was originally developed, is using react-dnd for the post editor.
- Add your company!
See Also
Thanks
This library is a React port of an API, parts of which were originally written by Andrew Kuznetsov.
A lot of recent progress is due to Nathan Hutchison's contributions and effort.