Skip to content

Commit 9b129dd

Browse files
committed
Update README
1 parent 5bf630f commit 9b129dd

File tree

1 file changed

+55
-18
lines changed

1 file changed

+55
-18
lines changed

README.md

Lines changed: 55 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,38 @@
11
# SortableJS-vue3
22

3-
This is a thin wrapper around the great [SortableJS](https://github.com/SortableJS/Sortable) library. I had many issues migrating from Vue.Draggable to vue.draggable.next, and after briefly investigating I decided that it was too complicated and a smaller solution was the answer. This wrapper tries to keep you as close to Sortable and vanilla JS as possible. Note that this library is small enough (see https://github.com/MaxLeiter/sortablejs-vue3/blob/main/src/components/Sortable.vue) that I recommend including it in your project without using npm and importing it as a local component. All you need is the linked file.
3+
[Demo](https://sortablejs-vue3.maxleiter.com)
4+
5+
6+
This is a thin wrapper around the great [SortableJS](https://github.com/SortableJS/Sortable) library. I had many issues migrating from Vue.Draggable to vue.draggable.next, and after briefly investigating I decided that it was too complicated and a smaller solution was the answer. This wrapper tries to keep you as close to Sortable as possible (wrapper libaries seem to re-implement or unnecessarily wrap a lot of code).
7+
8+
Note that this library is small enough (see [Sortable.vue](https://github.com/MaxLeiter/sortablejs-vue3/blob/main/src/components/Sortable.vue) for what you really need) that I recommend including it in your project without using npm and importing it as a local component. All you need is the linked file.
9+
10+
### Why not use \<other library\>?
11+
12+
- `Vue.Draggable` only supports Vue 2
13+
- `vue.draggable.next` uses the Options API, has multiple open (and afaict useful) pull requests, and had weird bugs/side-effects when I tried and used it
14+
- `shopify/draggable` and [`vue-shopify-dragable`](https://github.com/zjffun/vue-shopify-draggable) seemed promising but they don't supported nested components
415

516
## Usage
6-
You can see some demo usage at https://github.com/MaxLeiter/sortablejs-vue3/blob/main/src/components/HelloWorld.vue
17+
You can see a demo with more complete code at [https://sortablejs-vue3.maxleiter.com](https://sortablejs-vue3.maxleiter.com).
18+
19+
1. Install the package:
20+
21+
```bash
22+
yarn add sortablejs-vue3 sortablejs
23+
```
24+
25+
or
26+
27+
```bash
28+
npm install sortablejs-vue3 sortablejs
29+
```
30+
31+
2. Import the component in your `<script setup>` (or `<script>`):
32+
```typescript
33+
import { Sortable } from 'sortablejs-vue'
34+
```
735

8-
1. `yarn add sortablejs-vue3 sortablejs` or `npm install sortablejs-vue3 sortablejs`
9-
2. Import the component in your `<script setup>`: `import { Sortable } from 'sortablejs-vue'`
1036
3. Use the component:
1137

1238
```typescript
@@ -16,18 +42,6 @@ You can see some demo usage at https://github.com/MaxLeiter/sortablejs-vue3/blob
1642
:list="elements"
1743
item-key="id"
1844
:options="options"
19-
@change="logEvent"
20-
@choose="logEvent"
21-
@unchoose="logEvent"
22-
@start="logEvent"
23-
@end="logEvent"
24-
@add="logEvent"
25-
@update="logEvent"
26-
@sort="logEvent"
27-
@remove="logEvent"
28-
@filter="logEvent"
29-
@move="logEvent"
30-
@clone="logEvent"
3145
>
3246
<template #item="{element, index}">
3347
<div class="draggable" :key="element.id">
@@ -40,10 +54,33 @@ You can see some demo usage at https://github.com/MaxLeiter/sortablejs-vue3/blob
4054

4155
4. The `list` and `item-key` props are necessary. The `options` prop is an object that can contain any SortableJS option. You can find a full list of them here: https://github.com/SortableJS/Sortable#options
4256

57+
### Events
58+
You can listen to Sortable events by adding the listeners to the `Sortable` component. For example:
59+
60+
```typescript
61+
<Sortable
62+
:list="elements"
63+
item-key="id"
64+
@change="(event: Sortable.SortableEvent) => void"
65+
@choose="(event: Sortable.SortableEvent) => void"
66+
@unchoose="(event: Sortable.SortableEvent) => void"
67+
@start="(event: Sortable.SortableEvent) => void"
68+
@end="(event: Sortable.SortableEvent) => void"
69+
@add="(event: Sortable.SortableEvent) => void"
70+
@update="(event: Sortable.SortableEvent) => void"
71+
@sort="(event: Sortable.SortableEvent) => void"
72+
@remove="(event: Sortable.SortableEvent) => void"
73+
@filter="(event: Sortable.SortableEvent) => void"
74+
@move="(event: Sortable.MoveEvent, event2: Event) => void"
75+
@clone="(event: Sortable.SortableEvent) => void"
76+
>
77+
```
78+
4379
## Development
44-
1. Run `yarn`
80+
1. Run `yarn` to install dependencies
4581
2. `yarn dev` will start a web server with live reloading
46-
3. `yarn build` will build the production files
82+
3. `yarn build` will build the production library files
83+
4. `yarn build:site` will build the demo website
4784

4885
### Recommended IDE Setup
4986

0 commit comments

Comments
 (0)