Code Monkey home page Code Monkey logo

react-dnd-sortable's Introduction

React Sortable

Render drag/drop sortable collections using React Dnd

Provides a thin wrapper around React Dnd so you don't have to worry about the inner workings of that lib. Allows for live sorting with a callback on 'drop' with the newly sorted collection

Usage

( See example/app.jsx for another working example )

var React       = require('react'),
    Sortable    = require('react-sortable'),
    classnames  = require('classnames');

var Template = React.createClass({
  propTypes: {
    isOver: React.PropTypes.boolean // injected by ReactSortable
  },

  render: function () {
    return (
      <li classname={classnames({item: true, over: this.props.isOver)}}>
        <p>Item {this.props.x} for {this.props.y}</p>
      </li>
    );
  }
});

// Get from some store
var collection = [
  {x: 1, y: 2},
  {x: 3, y: 4},
  {x: 5, y: 6},
  {x: 7, y: 8}
];

var SortableCollection = React.createClass({
  getInitialState: function () {
    return {
      collection: collection
    };
  },

  render: function () {
    return (
      <Sortable collection={this.state.collection}
        onSorted={this._handleSorted}
        template={<Template />} />
    );
  },
  _handleSorted: function (sortedCollection) {
    this.setState({collection: sortedCollection});
  }
});

TODO

  1. More classes on draggin/dropping for better behaviours
  2. Sortable "type" is random, meaning you can't drag/drop onto other containers. It'd be nice to support dragging between different sortables
  3. Support a customizable "handle" that a user can drag within template so the whole item doesn't have to be draggable

react-dnd-sortable's People

Contributors

seethruhead avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.