Coder Social home page Coder Social logo

lofiinterstate / react-anything-sortable Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jasonslyvia/react-anything-sortable

0.0 2.0 0.0 5.86 MB

A ReactJS component that can sort any children with IE8 compatibility

License: MIT License

JavaScript 95.53% HTML 1.47% CSS 2.99%

react-anything-sortable's Introduction

react-anything-sortable is a ReactJS component that can sort any component passed as this.props.children. It is compatible with IE8 and all modern browsers.

It has no external dependencies but React itself. (In upcoming releases, it will add two more dependencies since React has split addons into separate npm modules.)

Build Status npm version Bower version

Quick Demo

Sort custom style children

react-anything-sortable

Sort images

react-anything-sortable

Children with custom event handler

react-anything-sortable

Installation

$ npm install --save react-anything-sortable
//
// or use bower
$ bower install --save react-anything-sortable
//
// or just include `lib/index.js` in a <script> tag and
// use it by `window['react-anything-sortable']`;
//
// technically AMD is supported too, but seriously you gonna stick with it in late 2015?

How to use

You can check the straight-forward demo by examining demo folder, or here's a brief example.

In YourComponent.js

var React = require('react');
var Sortable = require('react-anything-sortable');
var YourSortableItem = require('./YourItem');

ReactDOM.render(
<Sortable onSort={handleSort}>
  <YourItem sortData="1" />
  <YourItem sortData="2" />
</Sortable>
, document.body);

and in YourItem.js

Notice: There's a breaking change for requring SortableItemMixin since 0.2.0

ES6 import is recommended.

import React from 'react';
import {SortableItemMixin} from 'react-anything-sortable';

const YourItem = React.createClass({
  mixins: [SortableItemMixin],

  render() {
    return this.renderWithSortable(     // <= this.renderWithSortable is important
      <div>your item</div>
    );
  }
});

Or if your favor the old fashion way

var React = require('react');
var SortableItemMixin = require('react-anything-sortable').SortableItemMixin;

var YourItem = React.createClass({
  mixins: [SortableItemMixin],

  render: function(){
    return this.renderWithSortable(
      <div>your item</div>
    );
  }
});

Notice

  1. Specify your style for Sortable and Sortable Items, check demo/style.css, it is NOT optional!
  2. Don't forget the this.renderWithSortable call in YourItem.js
  3. Specify sortData in YourItem.js so that Sortable can return the sorted array
  4. Add onSort props to Sortable to be noticed when a sort operation finished
  5. Since we can't track any children modification in Sortable, you have to use key to force update Sortable when adding/removing children.

Scripts

$ npm run test
$ npm run watch
$ npm run build

Contributors

  1. stayradiated
  2. vizath

react-anything-sortable's People

Contributors

jasonslyvia avatar vizath avatar stayradiated avatar

Watchers

James Cloos avatar Ian 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.