# tiny-sortable-list

> React tiny sortable list

Latest version **1.1.2** (published 2023-09-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install tiny-sortable-list
pnpm add tiny-sortable-list
yarn add tiny-sortable-list
bun add tiny-sortable-list
```

## Health

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

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.2 |
| Published | 2023-09-24 |
| First published | 2023-08-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=18 |
| Dependencies | 0 |
| Unpacked size | 23.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 13 |
| Maintainers | xufocoder |
| Keywords | react, sortable, list |

## Links

- npm: https://www.npmjs.com/package/tiny-sortable-list
- Repository: https://github.com/ufocoder/tiny-sortable-list
- Issues: https://github.com/ufocoder/tiny-sortable-list/issues
- npm.io page: https://npm.io/package/tiny-sortable-list

## 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.1.2 (latest) — 2023-09-24
- 1.1.1 — 2023-09-03
- 1.0.1 — 2023-08-28
- 1.0.0 — 2023-08-27

## README

Tiny sortable list
==================

![Build](https://github.com/ufocoder/tiny-sortable-list/actions/workflows/build.yml/badge.svg)

React component for sortable list based on HTML [Drag and Drop API](https://developer.mozilla.org/en-US/docs/Web/API/HTML_Drag_and_Drop_API)


## Features

- No dependencies
- Mobile touch support
- Horizonal and vertical lists

## Usage

Minimal working example

```typescript
import { useState } from 'react'
import { SortableList, SortableItemProps } from 'tiny-sortable-list'

interface Item {
  title: string
}

const itemStyle = {
  padding: '20px 10px',
  background: 'white',
  border: '2px black solid'
};

function ItemVerticalComponent(props: SortableItemProps<Item>) {
  const { item, isDragged, isDragItemInsertAfter, isDragItemInsertBefore } = props

  return (
    <div
      style={{
        ...itemStyle,
        opacity: isDragged ? '0.3' : undefined,
        borderTopColor: isDragItemInsertBefore ? 'yellow' : 'black',
        borderBottomColor: isDragItemInsertAfter ? 'yellow' : 'black',
      }}>
        {item.title}
    </div>
  )
}

function App() {
  const [items, setItems] = useState<Item[]>([
    { title: 'item #1'},
    { title: 'item #2'},
    { title: 'item #3'},
    { title: 'item #4'},
    { title: 'item #5'},
  ])

  return (
    <SortableList items={items} setItems={setItems}>
      {props => <ItemVerticalComponent {...props} />}
    </SortableList>
  )
};
```

## Demo

![demo](./demo.gif)

## Note

Component use [dragdroptouch](https://github.com/Bernardo-Castilho/dragdroptouch) pollyfill source under the hood

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