StreakYC / react-draggable-list

React component for a list of draggable collapsible items
MIT License
319 stars 48 forks source link

react-draggable-list

GitHub license npm version Node.js CI

This component lets you make a user re-orderable list that animates nicely so that the user can easily move large items:

Example

The above example can be tried here:

https://streakyc.github.io/react-draggable-list/example/

You can find its code in the example directory. The example may be compiled by running:

npm i --force
npm run example-build
# or use this to auto-rebuild on changes:
npm run example-watch

DraggableList

This module exports the DraggableList React component, which takes the following props:

A DraggableList instance has the following methods:

Template

The template component is passed the following props:

The template component should be styled with max-height set to "100%" for best results.

The template component will have its props updated many times quickly during the animation, so implementing shouldComponentUpdate in its children is highly recommended.

The template component may have a getDragHeight method which may return a number to set the height in pixels of the item while the user is dragging it. If the method returns null or is not present, then the drag height will be equal to the element's natural height.

Bundling Note

To use this module in browsers, a CommonJS bundler such as Parcel, Browserify, or Webpack should be used.

This project relies on the javascript Map object being available globally. A global polyfill such as Babel's polyfill is required to support older browsers that don't implement these.

Types

Both TypeScript and Flow type definitions for this module are included! The type definitions won't require any configuration to use.