Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/lewis-wow/svelte-sortable


https://github.com/lewis-wow/svelte-sortable

Last synced: about 1 month ago
JSON representation

Awesome Lists containing this project

README

        

# Svelte Sortlist

## Installation

```bash
npm i svelte-sortlist
```

List must be `let`, it cannot be `const` if you bind it. Cause inside `SortList` component it will change.

```svelte

import SortList from 'svelte-sortlist'

let items = [
{ id: 1, value: 'A' },
{ id: 2, value: 'B' },
{ id: 3, value: 'C' },
]

{index} -> {item.value}

```

## Customize element

You can customize `SortList` element with element prop. It cannot be component.

```svelte



{item.value}


```

## Customize class

You can specify class of SortList. So you can use it with Tailwind.

```svelte

{item.value}

```

## Reorder event

With bindings you don't need this event, cause your items will be synced thanks to bind. But if you want for example sync it with backend server, you can use the reorder event and request the server on each reorder.

```svelte
console.log(e.detail.source, e.detail.target)}>

{item.value}

```

## If is over the item

You can for example apply styles on element that you are hovering over.

```svelte

{isOver ? 'over' : 'not over'} - {item.value}

```

## Rest props

`SortList` can be extended by any props. For example `id="my-id"`.