-
Notifications
You must be signed in to change notification settings - Fork 1
/
ThreeDotsMenu.svelte
133 lines (118 loc) · 3 KB
/
ThreeDotsMenu.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
<!--
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" context="module">
export interface MenuItem {
title: string;
icon: typeof SvelteComponent;
event: () => void;
tooltip?: string;
disabled?: boolean;
}
</script>
<script lang="ts">
import type { SvelteComponent } from "svelte";
import { fade } from "svelte/transition";
import EllipsisIcon from "./icons/Ellipsis.svelte";
import Overlay from "./Overlay.svelte";
import Tooltip from "./Tooltip.svelte";
export let menuItems: MenuItem[];
export let style: string | undefined = undefined;
let expanded = false;
</script>
<style>
.container {
position: relative;
height: 2.5rem;
width: 2.5rem;
}
button {
height: 100%;
width: 100%;
display: flex;
justify-content: center;
align-items: center;
border-radius: 0.5rem;
cursor: pointer;
outline-style: none;
border: 1px solid var(--color-foreground-level-3);
}
button :global(svg) {
fill: var(--color-foreground-level-6);
}
button:hover {
background-color: var(--color-foreground-level-2);
}
.modal {
background-color: var(--color-background);
border-radius: 0.5rem;
border: 1px solid var(--color-foreground-level-3);
box-shadow: var(--elevation-medium);
cursor: pointer;
margin-top: 1rem;
position: absolute;
right: 0;
top: 100%;
user-select: none;
width: 15rem;
z-index: 10;
/* Round corners of child elements. */
overflow: hidden;
}
.item {
cursor: pointer;
display: flex;
padding: 0.5rem 0.75rem;
color: var(--color-foreground-level-6);
}
.item:hover {
background-color: var(--color-foreground-level-1);
}
.item.disabled {
color: var(--color-foreground-level-4);
cursor: not-allowed;
}
.item.disabled :global(svg) {
fill: var(--color-foreground-level-4);
}
</style>
<Overlay
{expanded}
on:hide={() => {
expanded = false;
}}>
<div class="container" {style}>
<button
class="button-transition"
on:click|stopPropagation={() => {
expanded = !expanded;
}}>
<EllipsisIcon />
</button>
{#if expanded && menuItems.length > 0}
<div out:fade|local={{ duration: 100 }} class="modal">
{#each menuItems as item}
<Tooltip value={item.tooltip} position="left">
<div
class="item"
class:disabled={item.disabled}
on:click={!item.disabled
? () => {
expanded = false;
item.event();
}
: undefined}>
<svelte:component
this={item.icon}
style="margin-right: 0.75rem;" />
<div>{item.title}</div>
</div>
</Tooltip>
{/each}
</div>
{/if}
</div>
</Overlay>