-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathbasic.svelte
More file actions
42 lines (38 loc) · 992 Bytes
/
basic.svelte
File metadata and controls
42 lines (38 loc) · 992 Bytes
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
<script lang="ts">
import {DragDropProvider} from '@dnd-kit-svelte/svelte';
import {sensors} from '$lib';
import Droppable from '../../droppable.svelte';
import Draggable from './draggable.svelte';
const targets = ['A', 'B', 'C'];
let target = $state<string | number>();
</script>
<DragDropProvider
{sensors}
onDragEnd={(event) => {
if (event.canceled) return;
target = event.operation.target?.id;
}}
>
<div class="flex-s-center h-20">
{#if !target}
{@render draggable()}
{:else}
<div class="text-neutral-4 fw-semibold">Drop here</div>
{/if}
</div>
<div class="grid md:grid-cols-3 gap-8">
{#each targets as id}
<Droppable {id} class="flex-s-center h-100px bg-#F9F9F9 rd-3xl">
{#if target === id}
{@render draggable()}
{:else}
<div class="text-neutral-4 fw-semibold">Drop here</div>
{/if}
</Droppable>
{/each}
</div>
</DragDropProvider>
<!-- Whatever draggable markup u want -->
{#snippet draggable()}
<Draggable />
{/snippet}