# droplite

> Fat free react drag and drop lists

Latest version **0.0.3** (published 2019-08-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install droplite
pnpm add droplite
yarn add droplite
bun add droplite
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.3 |
| Published | 2019-08-27 |
| First published | 2019-08-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 12.7 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 9 |
| Author | Juan Torres |
| Maintainers | juanto121 |
| Keywords | Drag, Drop, react, list, light |

## Links

- npm: https://www.npmjs.com/package/droplite
- Repository: https://github.com/juanto121/Droplite
- Homepage: https://github.com/juanto121/Droplite#readme
- Issues: https://github.com/juanto121/Droplite/issues
- npm.io page: https://npm.io/package/droplite

## Dependencies (2)

- [react](https://npm.io/package/react.md) ^16.9.0
- [node-sass](https://npm.io/package/node-sass.md) ^4.12.0

## 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

- 0.0.3 (latest) — 2019-08-27
- 0.0.2 — 2019-08-27
- 0.0.1 — 2019-08-26

## README

# Droplite


![](https://juantorres-personal-bucket.s3.amazonaws.com/Droplite/Droplite.svg)


Light react component to add drag and drop functionality to your lists.


### Usage

Install the package with ```npm install droplite```

There are four basic requirements

```js
const MyComponent = (props) => {
  const [items, setItems] = useState(["A", "B", "C", "D"])

  // Requirement 1: add unique key
  const listItems = items.map(item =><li key={item}>{item}</li>)

  // Requirement 2: Implement on new order Handler
  const onNewOrder = (draggedItem, dropOntoItem) => {
    const newItemOrder = [...items]
    const draggedItemIndex = items.indexOf(draggedItem) 
    newItemOrder.splice(draggedItemIndex, 1)
    newItemOrder.splice(items.indexOf(dropOntoItem), 0, items[draggedItemIndex])
    setItems(newItemOrder)
  }

  // Requirement 3: Wrap the list with DragList HOC
  // Requirement 4: pass onNewOrder handler as prop
  return (
    <div>
      <DragList onNewOrder={onNewOrder}>
        {listItems}
      </DragList>
    </div>
  )
}
```


### Samples

See [Storybooks](https://juanto121.github.io/Droplite/?path=/story/simple-draglist--plain-list)


### Under the hood

Droplite depends on the [HTML Drag and Drop API](https://developer.mozilla.org/en-US/docs/Web/API/HTML_Drag_and_Drop_API).

`DragList` component manages internal state of the drag and drop operation.
The key function in `DragList` is the `dragOverHandler` that takes care of which element is being dragged over that can later be displaced. Once the `onDragEndHandler` is triggered, the current dragged element and the one below it (the draggedOver) are passed onto the `onNewOrder` handler.

`Draggable` is just a wrapper for your custom defined components that injects props and css classes that are required to start managing the drag and drop event listeners.

Support for mobile devices is not considered.

### Todo

Smooth animations

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