• Stars
    star
    220
  • Rank 179,402 (Top 4 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 9 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Drag & drop, touch enabled, reorderable / sortable list, React component

React Reorder (v2)

Drag & drop, touch enabled, reorder / sortable list, React component

If you are using v3 alpha, please refer to this documentation.

About

React Reorder is a React component that allows the user to drag-and-drop items in a list (horizontal / vertical) or a grid.

It fully supports touch devices and auto-scrolls when a component is being dragged (check out the demo, link below).

It also allows the user to set a hold time (duration before drag begins) allowing additional events like clicking / tapping to be applied.

Although this project is very new, it has been thoroughly tested in all modern browsers (see supported browsers).

Demo

Installation

  • Using npm

    npm install react-reorder

    Add --save or -S to update your package.json

  • Using bower

    bower install react-reorder

    Add --save or -S to update your bower.json

Example

  1. If using requirejs: add react-reorder to your require.config

    paths:
      // <name> : <path/to/module>
      'react-reorder': 'react-reorder/reorder'
    }
  2. If using a module loader (requirejs / browserfiy / commonjs): require react-reorder where it will be used in your project

    var Reorder = require('react-reorder');

    If using requirejs you'll probably want to wrap your module e.g.

    define(function (require) {
      // Require react-reorder here
    });
  3. Configuration

    Note: If your array is an array of primitives (e.g. strings) then itemKey is not required as the string itself will be used as the key, however item keys must be unique in any case

    1. Using JSX

      <Reorder
        // The key of each object in your list to use as the element key
        itemKey='name'
        // Lock horizontal to have a vertical list
        lock='horizontal'
        // The milliseconds to hold an item for before dragging begins
        holdTime='500'
        // The list to display
        list={[
          {name: 'Item 1'},
          {name: 'Item 2'},
          {name: 'Item 3'}
        ]}
        // A template to display for each list item
        template={ListItem}
        // Function that is called once a reorder has been performed
        callback={this.callback}
        // Class to be applied to the outer list element
        listClass='my-list'
        // Class to be applied to each list item's wrapper element
        itemClass='list-item'
        // A function to be called if a list item is clicked (before hold time is up)
        itemClicked={this.itemClicked}
        // The item to be selected (adds 'selected' class)
        selected={this.state.selected}
        // The key to compare from the selected item object with each item object
        selectedKey='uuid'
        // Allows reordering to be disabled
        disableReorder={false}
      />
    2. Using standard Javascript

      React.createElement(Reorder, {
        // The key of each object in your list to use as the element key
        itemKey: 'name',
        // Lock horizontal to have a vertical list
        lock: 'horizontal',
        // The milliseconds to hold an item for before dragging begins
        holdTime: '500',
        // The list to display
        list: [
          {name: 'Item 1'},
          {name: 'Item 2'},
          {name: 'Item 3'}
        ],
        // A template to display for each list item
        template: ListItem,
        // Function that is called once a reorder has been performed
        callback: this.callback,
        // Class to be applied to the outer list element
        listClass: 'my-list',
        // Class to be applied to each list item's wrapper element
        itemClass: 'list-item',
        // A function to be called if a list item is clicked (before hold time is up)
        itemClicked: this.itemClicked,
        // The item to be selected (adds 'selected' class)
        selected: this.state.selected,
        // The key to compare from the selected item object with each item object
        selectedKey: 'uuid',
        // Allows reordering to be disabled
        disableReorder: false
      })
  4. Callback functions

    1. The callback function that is called once a reorder has been performed

      function callback(event, itemThatHasBeenMoved, itemsPreviousIndex, itemsNewIndex, reorderedArray) {
        // ...
      }
    2. The itemClicked function that is called when an item is clicked before any dragging begins

      function itemClicked(event, itemThatHasBeenClicked, itemsIndex) {
        // ...
      }

      Note: event will be the synthetic React event for either mouseup or touchend, and both contain clientX & clientY values (for ease of use)

Compatibility / Requirements

  • Version 2.x tested and working with React 0.14

  • Versions 1.x tested and working with React 0.12 - 0.13

  • requirejs / commonjs / browserify (Optional, but recommended*)

* Has only been tested with requirejs & browserify

Supported Browsers

Desktop

  • Internet Explorer 9+ (may support IE8**)

  • Google Chrome (tested in version 39.0.2171.95(64-bit))

  • Mozilla Firefox (tested in version 33.0)

  • Opera (tested in version 26.0.1656.60)

  • Safari (tested in version 7.1.2 (9537.85.11.5))

** Have not had a chance to test in IE8, but IE8 is supported by React

Mobile

  • Chrome (tested in version 40.0.2214.89)

  • Safari (tested on iOS 8)

Untested Browsers

  • Internet Explorer 8*** (the lowest version that React supports)

*** If anyone could confirm that this works in IE8, that'd be awesome

More Repositories

1

react-fastclick

Fast Touch Events for React
JavaScript
487
star
2

canvasimo

An HTML5 canvas drawing library, with 150+ useful methods, jQuery-like fluent interface, and cross-browser compatibility enhancements.
TypeScript
16
star
3

react-monkey-patching

Some useful examples of monkey patching React
JavaScript
9
star
4

react-highlight-updates

Visually highlight when React components are updated
TypeScript
8
star
5

slik

Animation / tweening library, ideal for use with HTML5 canvas and or React
JavaScript
7
star
6

istanbul-no-coverage

Demonstrate "No coverage information was collected" issue
JavaScript
6
star
7

antler

Directory structure linter
TypeScript
5
star
8

tsurl

Type safe URL construction and deconstruction
TypeScript
4
star
9

tsb

Dead simple TypeScript bundler, watcher, dev server, transpiler, and polyfiller
TypeScript
3
star
10

abc

DEPRECATED: Angular Bound Charts
JavaScript
3
star
11

jargs

Simple node arg parser with explicit tree structure schema
JavaScript
3
star
12

async-2023-08-03-the-power-of-typescript

Various demos to show the true power of TypeScript
TypeScript
2
star
13

react-shallow-renderer

A shallow renderer for React components
TypeScript
2
star
14

react-canvas-spark-line

Simple canvas SparkLine React component
TypeScript
2
star
15

e-liquid-calculator

Calculate the e-liquid that you can make from base components
JavaScript
2
star
16

licons

A group of icons made from HTML & CSS that can transition between each other
CSS
2
star
17

sentry-events

CLI to list Sentry events
JavaScript
1
star
18

jsdoodle

Simple javascript editor with preview & console
JavaScript
1
star
19

csscraft

Minecraft with CSS
JavaScript
1
star
20

crabs

🦀🦀 Run multiple crab processes with a single command
TypeScript
1
star
21

the-speed-of-write

Demo project for Async talk: The Speed of Write
TypeScript
1
star
22

eslint-config-jakesidsmith

A collection of my common eslint configurations
JavaScript
1
star
23

watch-less-do-more

Watch less files and their dependency tree for changes & automatically recompile
JavaScript
1
star
24

3d-canvas-renderer

Messing around with rendering 3D objects on a 2D canvas
JavaScript
1
star