New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

react-sortable-component

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-sortable-component

Sortable component for ReactJS.

Source
npmnpm
Version
0.2.1
Version published
Weekly downloads
21
-47.5%
Maintainers
1
Weekly downloads
 
Created
Source

React Sortable Component

A simple sortable component for ReactJS.

Installation

npm install --save react-sortable-component

Usage

JS

var {SortableItems, SortableItem} = require('react-sortable-component');
...
getInitialState: function () {
    return {
      items: [
        {src: 'http://lorempixel.com/400/400/sports/1'},
        {src: 'http://lorempixel.com/400/400/sports/2'},
        {src: 'http://lorempixel.com/400/400/sports/3'},
        {src: 'http://lorempixel.com/400/400/sports/4'},
        {src: 'http://lorempixel.com/400/400/sports/5'},
        {src: 'http://lorempixel.com/400/400/sports/6'},
        {src: 'http://lorempixel.com/400/400/sports/7'}
      ]
    };
  },
  handleSort: function (items) {
    this.setState({
      items: items
    });
  },
  render: function () {
    var items = this.state.items.map(function (item) {
      return (
        <SortableItem key={item.src} className='sort-sample-item'>
          <LazySizes className='pointer-events-none' dataSrc={item.src}
            width='126'
            height='126'/>
        </SortableItem>
      );
    });
    return (
      <div>
        <SortableItems name='sort-sample' className='sort-sample-items'
          items={this.state.items} onSort={this.handleSort}>
          {items}
        </SortableItems>
      </div>
    );
  }

CSS

Webpack:

require('react-sortable-component/lib/sortable.css');

Without Webpack:

<link rel="stylesheet" type="text/css" href="path/to/react-sortable-component/lib/sortable.css">

or apply your style:

[draggable] {
  -moz-user-select: none;
  -webkit-user-select: none;
  -ms-user-select: none;
      user-select: none;
  -webkit-user-drag: element;
}

.sortable-items:before,
.sortable-items:after {
  content: " ";
  display: table;
}

.sortable-items:after {
  clear: both;
}

.sortable-item {
  height: 150px;
  width: 150px;
  padding: 10px;
  border-radius: 5px;
  float: left;
  margin-left: 10px;
  text-align: center;
  border: 2px solid #000;
  background-color: #eee;
  cursor: move;
}

.sortable-item .point-events-none {
  pointer-events: none;
}

.sortable-item-over {
  border: 2px dashed #000;
}

Props

SortableItems

NameTypeRequiredDefaultDescription
namestringtrue
childrennodetrueList of SortableItem
itemsarrayfalseList item need sort.
sortfunctionfalseSee
onSortfunction(arg)falseCallback when items sorted. If items prop is defined then arg is sorted items else arg is list index of sorted items.
classNamestringfalseYour custom class name.

SortableItem

NameTypeRequiredDefaultDescription
childrennodetrueSortable item content.
draggableboolfalsetrue
classNamestringfalseYour custom class name.

Example

View demo or example folder.

Keywords

react-component

FAQs

Package last updated on 26 Aug 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts