forked from jwlarocque/svelte-dragdroplist
-
Notifications
You must be signed in to change notification settings - Fork 1
/
DefaultItem.svelte
92 lines (80 loc) · 2.45 KB
/
DefaultItem.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
<script>
import { createEventDispatcher } from 'svelte';
export let data;
export let index;
export let allItems;
const dispatch = createEventDispatcher();
</script>
<div class="item" class:last-child={index === allItems.length - 1}>
<div class="buttons">
<button
class="up"
style={"visibility: " + (index > 0 ? "" : "hidden") + ";"}
on:click={() => dispatch('moveup')}>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="16px" height="16px"><path d="M0 0h24v24H0V0z" fill="none"/><path d="M7.41 15.41L12 10.83l4.59 4.58L18 14l-6-6-6 6 1.41 1.41z"/></svg>
</button>
<button
class="down"
style={"visibility: " + (index < allItems.length - 1 ? "" : "hidden") + ";"}
on:click={() => dispatch('movedown')}>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="16px" height="16px"><path d="M0 0h24v24H0V0z" fill="none"/><path d="M7.41 8.59L12 13.17l4.59-4.58L18 10l-6 6-6-6 1.41-1.41z"/></svg>
</button>
</div>
<div class="content">
{#if data.html}
{@html data.html}
{:else if data.text}
<p>{data.text}</p>
{:else}
<p>{data}</p>
{/if}
</div>
<div class="buttons delete">
<button
on:click={() => dispatch('remove')}>
<svg xmlns="http://www.w3.org/2000/svg" height="16" viewBox="0 0 24 24" width="16"><path d="M0 0h24v24H0z" fill="none"/><path d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"/></svg>
</button>
</div>
</div>
<style>
.item {
cursor: grab;
box-sizing: border-box;
display: inline-flex;
width: 100%;
min-height: 3em;
margin-bottom: 0.5em;
background-color: white;
border: 1px solid rgb(190, 190, 190);
border-radius: 2px;
user-select: none;
}
.item.last-child {
margin-bottom: 0;
}
.item > * {
margin: auto;
}
.buttons {
width: 32px;
min-width: 32px;
margin: auto 0;
display: flex;
flex-direction: column;
}
.buttons button {
cursor: pointer;
width: 18px;
height: 18px;
margin: 0 auto;
padding: 0;
border: 1px solid rgba(0, 0, 0, 0);
background-color: inherit;
}
.buttons button:focus {
border: 1px solid black;
}
.delete {
width: 32px;
}
</style>