@coyalabs/bts-style 1.1.6 → 1.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import BaseContainer from '../Base/BaseContainer.svelte';
|
|
3
|
+
import BaseText from '../Base/BaseText.svelte';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @type {Array<{label: string, value: any, disabled?: boolean, type?: 'item' | 'separator'}>}
|
|
7
|
+
*/
|
|
8
|
+
export let items = [];
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @type {any}
|
|
12
|
+
*/
|
|
13
|
+
export let selectedValue = null;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @type {(value: any) => void}
|
|
17
|
+
*/
|
|
18
|
+
export let onSelect = () => {};
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Group items into categories based on separators
|
|
22
|
+
* @typedef {{label: string | null, items: Array<{item: {label: string, value: any, disabled?: boolean, type?: 'item' | 'separator'}, originalIndex: number}>}} Category
|
|
23
|
+
* @type {Category[]}
|
|
24
|
+
*/
|
|
25
|
+
$: categories = items.reduce((/** @type {Category[]} */ acc, item, index) => {
|
|
26
|
+
if (item.type === 'separator') {
|
|
27
|
+
acc.push({ label: item.label, items: [] });
|
|
28
|
+
} else {
|
|
29
|
+
if (acc.length === 0) {
|
|
30
|
+
acc.push({ label: null, items: [] });
|
|
31
|
+
}
|
|
32
|
+
acc[acc.length - 1].items.push({ item, originalIndex: index });
|
|
33
|
+
}
|
|
34
|
+
return acc;
|
|
35
|
+
}, /** @type {Category[]} */ ([]));
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @param {any} value
|
|
39
|
+
*/
|
|
40
|
+
function handleSelect(value) {
|
|
41
|
+
onSelect(value);
|
|
42
|
+
}
|
|
43
|
+
</script>
|
|
44
|
+
|
|
45
|
+
<BaseContainer theme="filled" padding="0.5rem" borderRadiusTopLeft="15px" borderRadiusTopRight="15px" borderRadiusBottomLeft="15px" borderRadiusBottomRight="15px">
|
|
46
|
+
{#each categories as category, catIndex}
|
|
47
|
+
{#if category.label}
|
|
48
|
+
<div class="separator" class:not-first={catIndex > 0}>
|
|
49
|
+
<BaseText variant="content">{category.label}</BaseText>
|
|
50
|
+
</div>
|
|
51
|
+
{/if}
|
|
52
|
+
<div class="category-items">
|
|
53
|
+
{#each category.items as {item}}
|
|
54
|
+
<button
|
|
55
|
+
class="context-item"
|
|
56
|
+
class:selected={item.value === selectedValue}
|
|
57
|
+
class:disabled={item.disabled}
|
|
58
|
+
disabled={item.disabled}
|
|
59
|
+
on:click={() => handleSelect(item.value)}
|
|
60
|
+
>
|
|
61
|
+
{item.label}
|
|
62
|
+
</button>
|
|
63
|
+
{/each}
|
|
64
|
+
</div>
|
|
65
|
+
{/each}
|
|
66
|
+
</BaseContainer>
|
|
67
|
+
|
|
68
|
+
<style>
|
|
69
|
+
.category-items {
|
|
70
|
+
display: flex;
|
|
71
|
+
flex-direction: column;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.separator {
|
|
75
|
+
opacity: 0.6;
|
|
76
|
+
padding-bottom: 0.5rem;
|
|
77
|
+
font-size: 0.85rem;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
.separator.not-first {
|
|
81
|
+
padding-top: 0.5rem;
|
|
82
|
+
border-top: 1px solid rgba(227, 216, 216, 0.1);
|
|
83
|
+
margin-top: 0.5rem;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.context-item {
|
|
87
|
+
width: 100%;
|
|
88
|
+
padding: 0.75rem 1rem;
|
|
89
|
+
background: none;
|
|
90
|
+
border: none;
|
|
91
|
+
color: #E3D8D8;
|
|
92
|
+
font-family: 'Satoshi', sans-serif;
|
|
93
|
+
font-size: 0.95rem;
|
|
94
|
+
font-weight: 500;
|
|
95
|
+
text-align: left;
|
|
96
|
+
cursor: pointer;
|
|
97
|
+
transition: background-color 0.15s ease;
|
|
98
|
+
border-radius: 10px;
|
|
99
|
+
white-space: nowrap;
|
|
100
|
+
overflow: hidden;
|
|
101
|
+
text-overflow: ellipsis;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
.context-item:hover:not(.disabled) {
|
|
105
|
+
background-color: rgba(227, 216, 216, 0.1);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
.context-item.selected {
|
|
109
|
+
background-color: rgba(255, 239, 246, 0.15);
|
|
110
|
+
font-weight: 700;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
.context-item.disabled {
|
|
114
|
+
opacity: 0.4;
|
|
115
|
+
cursor: not-allowed;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
.context-item:not(:last-child) {
|
|
119
|
+
margin-bottom: 4px;
|
|
120
|
+
}
|
|
121
|
+
</style>
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export default ContextMenu;
|
|
2
|
+
type ContextMenu = SvelteComponent<{
|
|
3
|
+
items?: {
|
|
4
|
+
label: string;
|
|
5
|
+
value: any;
|
|
6
|
+
disabled?: boolean | undefined;
|
|
7
|
+
type?: "separator" | "item" | undefined;
|
|
8
|
+
}[] | undefined;
|
|
9
|
+
selectedValue?: any;
|
|
10
|
+
onSelect?: ((value: any) => void) | undefined;
|
|
11
|
+
}, {
|
|
12
|
+
[evt: string]: CustomEvent<any>;
|
|
13
|
+
}, {}> & {
|
|
14
|
+
$$bindings?: string | undefined;
|
|
15
|
+
};
|
|
16
|
+
declare const ContextMenu: $$__sveltets_2_IsomorphicComponent<{
|
|
17
|
+
items?: {
|
|
18
|
+
label: string;
|
|
19
|
+
value: any;
|
|
20
|
+
disabled?: boolean;
|
|
21
|
+
type?: "item" | "separator";
|
|
22
|
+
}[] | undefined;
|
|
23
|
+
selectedValue?: any;
|
|
24
|
+
onSelect?: ((value: any) => void) | undefined;
|
|
25
|
+
}, {
|
|
26
|
+
[evt: string]: CustomEvent<any>;
|
|
27
|
+
}, {}, {}, string>;
|
|
28
|
+
interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
|
|
29
|
+
new (options: import("svelte").ComponentConstructorOptions<Props>): import("svelte").SvelteComponent<Props, Events, Slots> & {
|
|
30
|
+
$$bindings?: Bindings;
|
|
31
|
+
} & Exports;
|
|
32
|
+
(internal: unknown, props: Props & {
|
|
33
|
+
$$events?: Events;
|
|
34
|
+
$$slots?: Slots;
|
|
35
|
+
}): Exports & {
|
|
36
|
+
$set?: any;
|
|
37
|
+
$on?: any;
|
|
38
|
+
};
|
|
39
|
+
z_$$bindings?: Bindings;
|
|
40
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<script>
|
|
2
2
|
import Button from './Button.svelte';
|
|
3
|
-
import
|
|
3
|
+
import ContextMenu from './ContextMenu.svelte';
|
|
4
4
|
import { icons } from '../icons';
|
|
5
5
|
import { slide } from 'svelte/transition';
|
|
6
6
|
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
export let width = '200px';
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
|
-
* @type {Array<{label: string, value: any, disabled?: boolean}>}
|
|
28
|
+
* @type {Array<{label: string, value: any, disabled?: boolean, type?: 'item' | 'separator'}>}
|
|
29
29
|
*/
|
|
30
30
|
export let options = [];
|
|
31
31
|
|
|
@@ -111,19 +111,7 @@
|
|
|
111
111
|
|
|
112
112
|
{#if isOpen}
|
|
113
113
|
<div class="dropdown-menu" transition:slide={{ duration: 150 }}>
|
|
114
|
-
<
|
|
115
|
-
{#each options as option}
|
|
116
|
-
<button
|
|
117
|
-
class="dropdown-item"
|
|
118
|
-
class:selected={option.value === value}
|
|
119
|
-
class:disabled={option.disabled}
|
|
120
|
-
disabled={option.disabled}
|
|
121
|
-
on:click={() => selectOption(option.value)}
|
|
122
|
-
>
|
|
123
|
-
{option.label}
|
|
124
|
-
</button>
|
|
125
|
-
{/each}
|
|
126
|
-
</BaseContainer>
|
|
114
|
+
<ContextMenu items={options} selectedValue={value} onSelect={selectOption} />
|
|
127
115
|
</div>
|
|
128
116
|
{/if}
|
|
129
117
|
</div>
|
|
@@ -152,40 +140,4 @@
|
|
|
152
140
|
right: 0;
|
|
153
141
|
z-index: 1000;
|
|
154
142
|
}
|
|
155
|
-
|
|
156
|
-
.dropdown-item {
|
|
157
|
-
width: 100%;
|
|
158
|
-
padding: 0.75rem 1rem;
|
|
159
|
-
background: none;
|
|
160
|
-
border: none;
|
|
161
|
-
color: #E3D8D8;
|
|
162
|
-
font-family: 'Satoshi', sans-serif;
|
|
163
|
-
font-size: 0.95rem;
|
|
164
|
-
font-weight: 500;
|
|
165
|
-
text-align: left;
|
|
166
|
-
cursor: pointer;
|
|
167
|
-
transition: background-color 0.15s ease;
|
|
168
|
-
border-radius: 10px;
|
|
169
|
-
white-space: nowrap;
|
|
170
|
-
overflow: hidden;
|
|
171
|
-
text-overflow: ellipsis;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
.dropdown-item:hover:not(.disabled) {
|
|
175
|
-
background-color: rgba(227, 216, 216, 0.1);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
.dropdown-item.selected {
|
|
179
|
-
background-color: rgba(255, 239, 246, 0.15);
|
|
180
|
-
font-weight: 700;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
.dropdown-item.disabled {
|
|
184
|
-
opacity: 0.4;
|
|
185
|
-
cursor: not-allowed;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
.dropdown-item:not(:last-child) {
|
|
189
|
-
margin-bottom: 4px;
|
|
190
|
-
}
|
|
191
143
|
</style>
|
|
@@ -13,6 +13,7 @@ type Dropdown = SvelteComponent<{
|
|
|
13
13
|
label: string;
|
|
14
14
|
value: any;
|
|
15
15
|
disabled?: boolean | undefined;
|
|
16
|
+
type?: "separator" | "item" | undefined;
|
|
16
17
|
}[] | undefined;
|
|
17
18
|
onChange?: ((value: any) => void) | undefined;
|
|
18
19
|
}, {
|
|
@@ -34,6 +35,7 @@ declare const Dropdown: $$__sveltets_2_IsomorphicComponent<{
|
|
|
34
35
|
label: string;
|
|
35
36
|
value: any;
|
|
36
37
|
disabled?: boolean;
|
|
38
|
+
type?: "item" | "separator";
|
|
37
39
|
}[] | undefined;
|
|
38
40
|
onChange?: ((value: any) => void) | undefined;
|
|
39
41
|
}, {
|
package/dist/index.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ export { default as Toggle } from "./Components/Toggle.svelte";
|
|
|
15
15
|
export { default as Tooltip } from "./Components/Tooltip.svelte";
|
|
16
16
|
export { default as TabBar } from "./Components/TabBar.svelte";
|
|
17
17
|
export { default as Dropdown } from "./Components/Dropdown.svelte";
|
|
18
|
+
export { default as ContextMenu } from "./Components/ContextMenu.svelte";
|
|
18
19
|
export { default as Popup } from "./Components/Popup/Popup.svelte";
|
|
19
20
|
export { popupStore } from "./Components/popupStore.js";
|
|
20
21
|
export { default as SpecialAction } from "./Components/Special/SpecialAction.svelte";
|
package/dist/index.js
CHANGED
|
@@ -18,6 +18,7 @@ export { default as Toggle } from "./Components/Toggle.svelte";
|
|
|
18
18
|
export { default as Tooltip } from "./Components/Tooltip.svelte";
|
|
19
19
|
export { default as TabBar } from "./Components/TabBar.svelte";
|
|
20
20
|
export { default as Dropdown } from "./Components/Dropdown.svelte";
|
|
21
|
+
export { default as ContextMenu } from "./Components/ContextMenu.svelte";
|
|
21
22
|
export { default as Popup } from "./Components/Popup/Popup.svelte";
|
|
22
23
|
export { popupStore } from "./Components/popupStore.js";
|
|
23
24
|
export { default as SpecialAction } from "./Components/Special/SpecialAction.svelte";
|