GitXplorerGitXplorer
h

react-sortable-mixin

public
25 stars
18 forks
3 issues

Commits

List of commits on branch master.
Verified
384a942ffd1ed9e4b2dcad67c4c896e4be65e454

Merge pull request #7 from gpetrica/master

hhulufei committed 5 years ago
Unverified
725c34cab90eff05c1bc70f1aaa42b52dcb5800d

update to support React 14 ReactDOM.findDOMNode instead of this.getDOMNode

ggpetrica committed 9 years ago
Unverified
b23d68d313dc516b2fe15597f5c315f14bea95a9

Add to react-components.com

hhulufei committed 10 years ago
Unverified
8a57252f88ba5a15b56c812a309aad0546c4af43

Clean

hhulufei committed 10 years ago
Unverified
01f9804590c2a71349ad6d35e71f697d4bee7d11

Demo link

hhulufei committed 10 years ago
Unverified
a7240873c2073d337960d5f3fb1d4626eaf1eb4c

Update doc

hhulufei committed 10 years ago

README

The README file for this repository.

react-sortable-mixin

A mixin for React to creat a sortable(drag and move) List Component. Demo

Install

npm install --save-dev react-sortable-mixin

Usage

  • Define a List Component use ListMixin contains Item Components use ItemMixin.
  • List Component required state items to set items' data.
  • Item Component required props: key / index / movableProps.

That's it!

Example code:

var React = require('react');
var sortable = require('react-sortable-mixin');

// Item Component use `ItemMixin`
var Item = React.createClass({
  mixins: [sortable.ItemMixin],
  render: function() {
    return <li>item {this.props.item}</li>;
  }
});

// List Component use `ListMixin`
var List = React.createClass({
  mixins: [sortable.ListMixin],
  componentDidMount: function() {
    // Set items' data, key name `items` required
    this.setState({ items: this.props.items });
  },
  render: function() {
    var items = this.state.items.map(function(item, i) {
      // Required props in Item (key/index/movableProps)
      return <Item key={item} item={item} index={i} {...this.movableProps}/>;
    }, this);

    return <ul>{items}</ul>;
  }
});

module.exports = List;

Hook Events (On List)

  • onMoveBefore: after mousedown before mousemove
  • onResorted: if items not resorted (drop at same position) will not trigger
  • onMoveEnd