-
Notifications
You must be signed in to change notification settings - Fork 9
/
index.svelte
318 lines (285 loc) · 8.69 KB
/
index.svelte
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
<script lang="ts">
import Slider from '@bulatdashiev/svelte-slider';
import { SortableList } from '$lib/index';
import { FontAwesomeIcon } from 'fontawesome-svelte';
import { library } from '@fortawesome/fontawesome-svg-core';
import { faArrowsAlt } from '@fortawesome/free-solid-svg-icons';
//@ts-expect-error FA Bug
library.add(faArrowsAlt);
type ItemList = { item: string; filtered?: boolean }[];
type SelectOption = { isHorizontal: boolean; text: 'horizontal' | 'vertical' };
let invertSwap = false;
let selectOptions: SelectOption[] = [
{ isHorizontal: true, text: 'horizontal' },
{ isHorizontal: false, text: 'vertical' }
];
let sliderValue: [number, number] = [0.5, 1];
$: selected = selectOptions[0];
$: boxWidth = 200 * sliderValue[0];
const exampleItems = ['Item 1', 'Item 2', 'Item 3', 'Item 4', 'Item 5', 'Item 6'];
const exampleItemsFilter: ItemList = [
{ item: 'Item 1' },
{ item: 'Item 2' },
{ item: 'Item 3' },
{ item: 'Item 4 - Filtered', filtered: true },
{ item: 'Item 5' },
{ item: 'Item 6' }
];
</script>
<div class="container mb-4">
<div class="border-b pb-2">
<h1 class="font-bold text-xl">Welcome to Svelte-SortableJS.</h1>
<div id="intro-text">This is the sandbox. Examples.</div>
</div>
<div id="simple-list" class="mt-4 border rounded p-6">
<h2 class="font-bold">Example 1 - Simple List</h2>
<SortableList class="list-group col" animation={150} ghostClass="bg-info">
{#each exampleItems as item}
<div class="list-group-item">
{item}
</div>
{/each}
</SortableList>
</div>
<div id="shared-list" class="mt-4 border rounded p-6">
<h2 class="font-bold">Example 2 - Shared Lists</h2>
<div class="flex">
<SortableList class="list-group col mr-6" group="shared2" animation={150}>
{#each exampleItems as item}
<div class="list-group-item bg-secondary text-white">{item} - Group 1</div>
{/each}
</SortableList>
<SortableList class="list-group col" group="shared2" animation={150}>
{#each exampleItems as item}
<div class="list-group-item">{item} - Group 2</div>
{/each}
</SortableList>
</div>
</div>
<div id="clone-list" class="mt-4 border rounded p-6">
<h2 class="font-bold">Example 3 - Cloning Lists</h2>
<div class="flex">
<SortableList
class="list-group col mr-6"
group={{ name: 'shared3', pull: 'clone' }}
animation={150}
>
{#each exampleItems as item}
<div class="list-group-item bg-secondary text-white">{item} - Group 1</div>
{/each}
</SortableList>
<SortableList
class="list-group col"
group={{ name: 'shared3', pull: 'clone' }}
animation={150}
>
{#each exampleItems as item}
<div class="list-group-item">{item} - Group 2</div>
{/each}
</SortableList>
</div>
</div>
<div id="disable-list" class="mt-4 border rounded p-6">
<h2 class="font-bold">Example 4 - Disable Sort/Clone on Left</h2>
<div class="flex">
<SortableList
class="list-group col mr-6"
group={{ name: 'shared4', pull: 'clone', put: false }}
animation={150}
sort={false}
>
{#each exampleItems as item}
<div class="list-group-item bg-secondary text-white">{item} - Group 1</div>
{/each}
</SortableList>
<SortableList class="list-group col" group="shared4" animation={150}>
{#each exampleItems as item}
<div class="list-group-item">{item} - Group 2</div>
{/each}
</SortableList>
</div>
</div>
<div id="handle-list" class="mt-4 border rounded p-6">
<h2 class="font-bold">Example 5 - Handle</h2>
<SortableList class="list-group col" handle=".cursor-grab" animation={150}>
{#each exampleItems as item}
<div class="list-group-item">
<FontAwesomeIcon icon={faArrowsAlt} class="cursor-grab" />
{item}
</div>
{/each}
</SortableList>
</div>
<div id="filter-list" class="mt-4 border rounded p-6">
<h2 class="font-bold">Example 6 - Filter</h2>
<SortableList class="list-group col" filter=".filtered" animation={150}>
{#each exampleItemsFilter as item}
<div
class="list-group-item"
class:handle={!item.filtered}
class:filtered={item.filtered}
class:bg-danger={item.filtered}
>
{item.item}
</div>
{/each}
</SortableList>
</div>
<div id="threshold-list" class="mt-4 border rounded p-6">
<div class="-mb-4">
<h2 class="font-bold">Example 7 - Thresholds</h2>
Current Threshold: {sliderValue[0]}
<Slider min="0" max="1" step=".01" bind:value={sliderValue} />
<div>
Invert Swap ({invertSwap}): <input type="checkbox" bind:checked={invertSwap} />
</div>
<div>
Is Horizontal?:
<select bind:value={selected}>
{#each selectOptions as option}
<option value={option}>
{option.text}
</option>
{/each}
</select>
</div>
</div>
{#key [sliderValue, invertSwap, selected]}
<SortableList
class={selected?.isHorizontal ? 'flex' : ''}
swapThreshold={sliderValue[0]}
animation={150}
{invertSwap}
direction={selected?.text}
>
<div
class="{selected?.isHorizontal
? ''
: 'mx-auto'} h-[200px] w-[200px] border border-solid mr-4 mt-4"
>
{#if !invertSwap}
<div class="bg-red-500 m-auto h-full" style="width: {boxWidth}px;" />
{:else}
<div class="h-full flex justify-between">
<div class="bg-red-500 h-full" style="width: {boxWidth / 2}px;" />
<div class="bg-red-500 h-full" style="width: {boxWidth / 2}px;" />
</div>
{/if}
</div>
<div
class="{selected?.isHorizontal
? ''
: 'mx-auto'} h-[200px] w-[200px] border border-solid mr-4 mt-4"
>
{#if !invertSwap}
<div class="bg-blue-500 m-auto h-full" style="width: {boxWidth}px;" />
{:else}
<div class="h-full flex justify-between">
<div class="bg-blue-500 h-full" style="width: {boxWidth / 2}px;" />
<div class="bg-blue-500 h-full" style="width: {boxWidth / 2}px;" />
</div>
{/if}
</div>
</SortableList>
{/key}
</div>
<div id="nested-lists" class="mt-4 border rounded p-6">
<h2 class="font-bold">Example 7 - Nesting</h2>
<SortableList
class="list-group col nested-sortable"
group="nested"
animation={150}
forceFallback={true}
swapThreshold={0.65}
>
<div class="list-group-item nested-1">
Item 1.1
<SortableList
class="list-group col nested-sortable"
group="nested"
animation={150}
forceFallback={true}
swapThreshold={0.65}
>
<div class="list-group-item nested-2">Item 2.1</div>
<div class="list-group-item nested-2">
Item 2.2
<SortableList
class="list-group col nested-sortable"
group="nested"
animation={150}
forceFallback={true}
swapThreshold={0.65}
>
<div class="list-group-item nested-3">Item 3.1</div>
<div class="list-group-item nested-3">Item 3.2</div>
<div class="list-group-item nested-3">Item 3.3</div>
<div class="list-group-item nested-3">Item 3.4</div>
</SortableList>
</div>
<div class="list-group-item nested-2">Item 2.3</div>
<div class="list-group-item nested-2">Item 2.4</div>
</SortableList>
</div>
<div class="list-group-item nested-1">Item 1.2</div>
<div class="list-group-item nested-1">Item 1.3</div>
<div class="list-group-item nested-1">
Item 1.4
<SortableList
class="list-group col nested-sortable"
group="nested"
animation={150}
forceFallback={true}
swapThreshold={0.65}
>
<div class="list-group-item nested-2">Item 2.1</div>
<div class="list-group-item nested-2">Item 2.2</div>
<div class="list-group-item nested-2">Item 2.3</div>
<div class="list-group-item nested-2">Item 2.4</div>
</SortableList>
</div>
<div class="list-group-item nested-1">Item 1.5</div>
</SortableList>
</div>
<div id="handle-list" class="mt-4 border rounded p-6">
<h2 class="font-bold">Example 8 - MultiDrag</h2>
<SortableList class="list-group col" multiDragClass="selected" animation={150}>
{#each exampleItems as item}
<div class="list-group-item">
{item}
</div>
{/each}
</SortableList>
</div>
<div id="handle-list" class="mt-4 border rounded p-6">
<h2 class="font-bold">Example 8 - Swap</h2>
<SortableList class="list-group col" swapClass="highlight" animation={150}>
{#each exampleItems as item}
<div class="list-group-item">
{item}
</div>
{/each}
</SortableList>
</div>
</div>
<style>
.nested-1 {
margin-bottom: 8px;
background-color: rgb(241, 241, 241);
}
.nested-2 {
margin-bottom: 8px;
background-color: rgb(221, 221, 221);
}
.nested-3 {
margin-bottom: 8px;
background-color: rgb(201, 201, 201);
}
:global(.selected) {
background-color: #f9c7c8;
border: solid red 1px;
}
:global(.highlight) {
background-color: #9ab6f1;
}
</style>