-
Notifications
You must be signed in to change notification settings - Fork 1
/
List.svelte
76 lines (64 loc) · 1.64 KB
/
List.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
<!--
Copyright © 2022 The Radicle Design System Contributors
This file is part of radicle-design-system, distributed under the GPLv3
with Radicle Linking Exception. For full terms see the included
LICENSE file.
-->
<script lang="ts">
import { createEventDispatcher } from "svelte";
const dispatch = createEventDispatcher();
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export let items: any[];
export let style: string | undefined = undefined;
export let styleHoverState: boolean = true;
export let key: string | undefined = undefined;
</script>
<style>
.list-container {
min-width: var(--content-min-width);
max-width: var(--content-max-width);
}
ul {
width: 100%;
border: 1px solid var(--color-foreground-level-2);
border-radius: 0.5rem;
}
li {
display: flex;
width: 100%;
flex: 1;
border-bottom: 1px solid var(--color-foreground-level-2);
user-select: none;
overflow: hidden;
}
li:last-child {
border-bottom: 0;
}
.hover {
cursor: pointer;
}
.hover:hover {
background-color: var(--color-foreground-level-1);
}
.hover:hover:first-child {
border-top-left-radius: 0.5rem;
border-top-right-radius: 0.5rem;
}
.hover:hover:last-child {
border-bottom-left-radius: 0.5rem;
border-bottom-right-radius: 0.5rem;
}
</style>
<div class="list-container" {style}>
{#if items.length > 0}
<ul>
{#each items as item, index (key ? item[key] : index)}
<li
class:hover={styleHoverState}
on:click={() => dispatch("select", item)}>
<slot {item} />
</li>
{/each}
</ul>
{/if}
</div>