0.2.1 • Published 7 years ago

react-orderable v0.2.1

Weekly downloads
3
License
MIT
Repository
github
Last release
7 years ago

React Orderable

DEPRECATED - Recommend https://github.com/clauderic/react-sortable-hoc instead!

Checklist before 0.2.0 release

  • Improve demo page (add examples of different kinds of uses)
  • Make demo page responsive
  • The example code should be directly usable. There are pieces missing right now.

Demo

Try it

Features

  • Horizontal or vertical layout
  • Drag handle
  • Animation
  • Ghost item
  • Item movement is constrained to a single axis (x or y)
  • Touch support

Usage

import 'babel-polyfill'; // Orderable requires an ES6 polyfill
import 'react-orderable/react-orderable.css';
import Orderable from 'react-orderable';
import React from 'react';

// ...

<Orderable
  animated
  className={styles.songs}
  ghost
  itemSize={90}
  onChange={this.handleChange}
>
  {songs.map(song => {
    return (
      <Song
        className={styles.song}
        id={song.get('name')}
        key={song.get('name')}
        song={song}
      />
    );
  })}
</Orderable>

Full example

Orderable interface

PropertyRequiredDefaultDescription
animatedNfalseWhether to animate item position during a drag
childrenNThe items to order
classNameNClass name for the Orderable component's div
ghostNfalseWhether to show a ghost item when an item is being dragged
horizontalNfalseWhether this is a horizontal or vertical list
itemSizeYItem height for vertical lists, item width for horizontal lists
onChangeYCallback that receives an ordered array of item ids when a drag completes

Items inside an Orderable must have an id property (similar to key) which is used to keep track of item order.

Item interface

These are the props the item component must support.

PropertyRequiredDescription
classNameYClass name for the item's div
draggingNWhether this item is being dragged
ghostNWhether this is a ghost item
onDragStartYMouse down or touch start handler for the item's handle (this can be the item itself)
styleYStyle for the item's div

Candidates for improvements

  • Variable item size
  • Item size from element bounds
  • If I have variable item size, do I support changing item size during a drag?
  • Margin between items
  • Dragging items between groups
  • Touch cancel