ankiutils 0.0.9 → 0.0.11
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.
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
disabled = false,
|
|
25
25
|
clearable = false,
|
|
26
26
|
multiple = false,
|
|
27
|
-
onSelected = () => {}
|
|
27
|
+
onSelected: onSelectedBase = () => {}
|
|
28
28
|
}: Props = $props();
|
|
29
29
|
|
|
30
30
|
let searchTerm = $state('');
|
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
}
|
|
70
70
|
searchTerm = '';
|
|
71
71
|
inputElement?.focus();
|
|
72
|
-
|
|
72
|
+
onSelectedBase(selectedOptions);
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
async function scrollHighlightedIntoView() {
|
|
@@ -124,6 +124,13 @@
|
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
+
function onSelected() {
|
|
128
|
+
if (!multiple) {
|
|
129
|
+
selectOptionsComponent?.closeDropdown();
|
|
130
|
+
}
|
|
131
|
+
onSelectedBase(selectedOptions);
|
|
132
|
+
}
|
|
133
|
+
|
|
127
134
|
$effect(() => {
|
|
128
135
|
if (isOpen) {
|
|
129
136
|
document.addEventListener('click', handleClickOutside);
|
|
@@ -184,6 +191,7 @@
|
|
|
184
191
|
options={filteredOptions}
|
|
185
192
|
bind:selectedOptions
|
|
186
193
|
{multiple}
|
|
194
|
+
{highlightedIndex}
|
|
187
195
|
{onSelected}
|
|
188
196
|
{onOpenDropdown}
|
|
189
197
|
{onCloseDropdown}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { type SelectOption } from './types.js';
|
|
4
4
|
|
|
5
5
|
interface Props {
|
|
6
|
-
label
|
|
6
|
+
label?: string;
|
|
7
7
|
options: SelectOption[];
|
|
8
8
|
selectedOptions: string[];
|
|
9
9
|
multiple?: boolean;
|
|
@@ -21,7 +21,14 @@
|
|
|
21
21
|
let isOpen = $state(false);
|
|
22
22
|
let containerElement: HTMLDivElement;
|
|
23
23
|
let selectOptionsComponent: SelectOptions | undefined = $state();
|
|
24
|
-
|
|
24
|
+
let displayLabel = $derived.by(() => {
|
|
25
|
+
if (label) {
|
|
26
|
+
return label;
|
|
27
|
+
} else if (selectedOptions.length) {
|
|
28
|
+
return selectedOptions.join(', ');
|
|
29
|
+
}
|
|
30
|
+
return 'Select';
|
|
31
|
+
});
|
|
25
32
|
function handleClickOutside(event: MouseEvent) {
|
|
26
33
|
if (containerElement && !containerElement.contains(event.target as Node)) {
|
|
27
34
|
selectOptionsComponent?.closeDropdown();
|
|
@@ -38,7 +45,7 @@
|
|
|
38
45
|
|
|
39
46
|
<div class="dropdown" bind:this={containerElement}>
|
|
40
47
|
<button class="btn" onclick={() => (isOpen = !isOpen)}>
|
|
41
|
-
<span>{
|
|
48
|
+
<span>{displayLabel}</span>
|
|
42
49
|
<i class="bi bi-chevron-{isOpen ? 'up' : 'down'}"></i>
|
|
43
50
|
</button>
|
|
44
51
|
{#if isOpen}
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
selectedOptions: string[];
|
|
7
7
|
multiple?: boolean;
|
|
8
8
|
isOpen?: boolean;
|
|
9
|
+
highlightedIndex?: number,
|
|
9
10
|
onSelected?: (value: string[]) => void;
|
|
10
11
|
onOpenDropdown?: () => void;
|
|
11
12
|
onCloseDropdown?: () => void;
|
|
@@ -16,6 +17,7 @@
|
|
|
16
17
|
selectedOptions = $bindable<string[]>([]),
|
|
17
18
|
multiple = false,
|
|
18
19
|
isOpen = $bindable(false),
|
|
20
|
+
highlightedIndex,
|
|
19
21
|
onSelected,
|
|
20
22
|
onOpenDropdown,
|
|
21
23
|
onCloseDropdown
|
|
@@ -50,34 +52,40 @@
|
|
|
50
52
|
}
|
|
51
53
|
</script>
|
|
52
54
|
|
|
53
|
-
<
|
|
55
|
+
<ul
|
|
56
|
+
class="menu dropdown-content flex-nowrap w-full overflow-auto bg-base-100 rounded-box z-1 p-2 shadow-sm gap-1"
|
|
57
|
+
>
|
|
54
58
|
{#if options.length === 0}
|
|
55
59
|
<div class="text-gray-400">No options found</div>
|
|
56
60
|
{:else}
|
|
57
61
|
{#each options as option, index (option.value)}
|
|
58
62
|
{@const checked = selectedOptions.includes(option.value)}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
63
|
+
{@const highlighted = !checked && highlightedIndex === index}
|
|
64
|
+
<li>
|
|
65
|
+
{#if multiple}
|
|
66
|
+
<input
|
|
67
|
+
bind:this={optionElements[index]}
|
|
68
|
+
type="checkbox"
|
|
69
|
+
class="btn"
|
|
70
|
+
class:btn-primary={checked}
|
|
71
|
+
class:btn-outline={highlighted}
|
|
72
|
+
{checked}
|
|
73
|
+
aria-label={option.label}
|
|
74
|
+
onclick={() => selectOption(option)}
|
|
75
|
+
/>
|
|
76
|
+
{:else}
|
|
77
|
+
<button
|
|
78
|
+
bind:this={optionElements[index]}
|
|
79
|
+
type="button"
|
|
80
|
+
class="btn"
|
|
81
|
+
class:btn-primary={checked}
|
|
82
|
+
class:btn-outline={highlighted}
|
|
83
|
+
onclick={() => selectOption(option)}
|
|
84
|
+
>
|
|
85
|
+
{option.label}
|
|
86
|
+
</button>
|
|
87
|
+
{/if}
|
|
88
|
+
</li>
|
|
81
89
|
{/each}
|
|
82
90
|
{/if}
|
|
83
|
-
</
|
|
91
|
+
</ul>
|