An open API service indexing awesome lists of open source software.

https://github.com/tarb/svelte-dnd-list

Simple and lightweight Svelte Drag and Drop library
https://github.com/tarb/svelte-dnd-list

Last synced: about 1 year ago
JSON representation

Simple and lightweight Svelte Drag and Drop library

Awesome Lists containing this project

README

          

# Svelte Dnd List

A very lightweight, dependency free and simple drag and drop library for Svelte. The library supports multiple types of lists, and moving items between lists.

> It's still currently in development and as such its API is not stable and might change as development continues.

## Getting Started

Install through npm with:

```terminal
npm i svelte-dnd-list
```

Below is a very simple example that shows reordering an array of numbers in a vertical list. [You can play with this example here.](https://tarb.github.io/svelte-dnd-list/simple)

```svelte

import DragDropList, { VerticalDropZone, reorder, type DropEvent } from 'svelte-dnd-list';

let items = [1, 2, 3, 4, 5];

function onDrop({ detail: { from, to } }: CustomEvent<DropEvent>) {
if (!to || from === to) {
return;
}

items = reorder(items, from.index, to.index);
}

Svelte Dnd List - Simple Example

{items[index]}

div {
display: flex;
justify-content: center;
align-items: center;
width: 50px;
height: 50px;
border: 1px solid black;
}

```

## Examples

- [Simple example](https://tarb.github.io/svelte-dnd-list/simple)
- [Scrollable container example](https://tarb.github.io/svelte-dnd-list/scroll)
- [Programatic control](https://tarb.github.io/svelte-dnd-list/programatic)
- [Multiple lists, item morphing and programmatic moving.](https://tarb.github.io/svelte-dnd-list/)