# react-sortable-component

> Sortable component for ReactJS.

Latest version **1.0.0** (published 2016-04-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-sortable-component
pnpm add react-sortable-component
yarn add react-sortable-component
bun add react-sortable-component
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2016-04-19 |
| First published | 2015-06-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Your Name |
| Maintainers | vn38minhtran |
| Keywords | react-component, react, component, sortable, react-sortable |

## Links

- npm: https://www.npmjs.com/package/react-sortable-component
- Repository: https://github.com/yourname/react-component-starter
- Issues: https://github.com/yourname/react-component-starter/issues
- npm.io page: https://npm.io/package/react-sortable-component

## Dependencies (1)

- [classnames](https://npm.io/package/classnames.md) ^2.2.3

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2016-04-19
- 0.4.0 — 2016-03-04
- 0.3.0 — 2015-10-13
- 0.2.2 — 2015-09-07
- 0.2.1 — 2015-08-26
- 0.2.0 — 2015-08-25
- 0.1.1 — 2015-06-09
- 0.1.0 — 2015-06-05
- 0.0.3 — 2015-06-05
- 0.0.2 — 2015-06-05
- 0.0.1 — 2015-06-05

## README

# React Sortable Component

A simple sortable component for ReactJS.

## Installation

```bash
npm install --save react-sortable-component
```

## Usage

### JS

```js
var {SortableItems, SortableItem} = require('react-sortable-component');
...
state = {
  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'}
  ]
};

handleSort = (items) => {
  this.setState({
    items: items
  });
};

render() {
  let {items} = this.state;
  return (
    <Document title="Home | React sortable component" className="page-home">
      <SortableItems name="simple-sort"
        className="simple-sort-items"
        items={items}
        onSort={this.handleSort}>
        {
          items.map((item, index) => {
            return (
              <SortableItem key={item.src}
                draggable={index !== 3}
                className="simple-sort-item">
                <LazySizes className="pointer-events-none"
                  dataSrc={item.src}
                  width="126"
                  height="126"/>
              </SortableItem>
            );
          })
        }
      </SortableItems>
    </Document>
  );
}

```

### CSS

**Webpack:**

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

**Without Webpack:**

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

**or apply your style:**

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

.sortable-items {
  margin-left: -10px;
  &:before,
  &:after {
    content: " ";
    display: table;
  }
  &:after {
    clear: both;
  }
}

.sortable-item {
  height: 150px;
  width: 150px;
  padding: 10px;
  border-radius: 2px;
  float: left;
  margin-left: 10px;
  text-align: center;
  border: 1px solid #DDD;
  background-color: #fff;
  cursor: move;
  .pointer-events-none {
    pointer-events: none;
  }
}

.sortable-item-over {
  border: 1px dashed #DDD;
}

```

### UMD

```html
<link rel="stylesheet" type="text/css" href="path/to/react-sortable-component/dist/react-sortable-component.css">
<script src="path/to//react-sortable-component/dist/react-sortable-component.js"></script>
```

```js
var SortableItems = window.ReactSortableComponent.SortableItems;
var SortableItem = window.ReactSortableComponent.SortableItem;
```

## Props

### SortableItems

| Name | Type | Required | Default | Description |
|------|------|----------|---------|-------------|
| name | string | true |  |  |
| rootComponentType | string or ReactClass | false | `div` | EX: `ul` |
| children | node | true | | List of SortableItem |
| items | array | false | | List item need sort. |
| sort | function | false | [See](https://github.com/vn38minhtran/react-sortable-component/blob/master/src/SortableItems.js#L14) |  |
| onSort | function(arg) | false | | Callback when items sorted. If `items` prop is defined then `arg` is sorted items else `arg` is list index of sorted items. |
| className | string | false | | Your custom class name. |

### SortableItem

| Name | Type | Required | Default | Description |
|------|------|----------|---------|-------------|
| rootComponentType | string or ReactClass | false | `div` | EX: `li` |
| children | node | true | | Sortable item content. |
| draggable | bool | false | true | |
| className | string | false | | Your custom class name. |

## Example

View [demo](http://vn38minhtran.github.io/react-sortable-component) or example folder.

---
_Source: https://npm.io/package/react-sortable-component · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
