ankiutils 0.0.10 → 0.0.12
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.
- package/dist/components/BaseSelect.svelte +4 -1
- package/dist/components/BaseSelect.svelte.d.ts +1 -0
- package/dist/components/Dropdown.svelte +10 -3
- package/dist/components/Dropdown.svelte.d.ts +1 -1
- package/dist/components/MultiSelect.svelte +3 -0
- package/dist/components/MultiSelect.svelte.d.ts +1 -0
- package/dist/components/Select.svelte +3 -0
- package/dist/components/Select.svelte.d.ts +1 -0
- package/dist/components/SelectOptions.svelte +32 -24
- package/dist/components/SelectOptions.svelte.d.ts +1 -0
- package/package.json +1 -1
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import { filterSelectOptions } from './utils.js';
|
|
6
6
|
interface Props {
|
|
7
7
|
id?: string;
|
|
8
|
+
className?: string,
|
|
8
9
|
options: SelectOption[];
|
|
9
10
|
selectedOptions: string[];
|
|
10
11
|
placeholder?: string;
|
|
@@ -17,6 +18,7 @@
|
|
|
17
18
|
|
|
18
19
|
let {
|
|
19
20
|
id,
|
|
21
|
+
className = "",
|
|
20
22
|
options,
|
|
21
23
|
selectedOptions = $bindable<string[]>([]),
|
|
22
24
|
placeholder = 'Select an option...',
|
|
@@ -139,7 +141,7 @@
|
|
|
139
141
|
});
|
|
140
142
|
</script>
|
|
141
143
|
|
|
142
|
-
<div class="dropdown w-full" bind:this={containerElement}>
|
|
144
|
+
<div class="{className} dropdown w-full" bind:this={containerElement}>
|
|
143
145
|
<div class="flex gap-2">
|
|
144
146
|
<input
|
|
145
147
|
bind:this={inputElement}
|
|
@@ -191,6 +193,7 @@
|
|
|
191
193
|
options={filteredOptions}
|
|
192
194
|
bind:selectedOptions
|
|
193
195
|
{multiple}
|
|
196
|
+
{highlightedIndex}
|
|
194
197
|
{onSelected}
|
|
195
198
|
{onOpenDropdown}
|
|
196
199
|
{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}
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
interface Props {
|
|
6
6
|
id?: string;
|
|
7
|
+
className?: string,
|
|
7
8
|
options: SelectOption[];
|
|
8
9
|
selectedOptions: string[];
|
|
9
10
|
placeholder?: string;
|
|
@@ -15,6 +16,7 @@
|
|
|
15
16
|
|
|
16
17
|
let {
|
|
17
18
|
id,
|
|
19
|
+
className,
|
|
18
20
|
options,
|
|
19
21
|
selectedOptions = $bindable<string[]>([]),
|
|
20
22
|
placeholder,
|
|
@@ -27,6 +29,7 @@
|
|
|
27
29
|
|
|
28
30
|
<BaseSelect
|
|
29
31
|
{id}
|
|
32
|
+
{className}
|
|
30
33
|
{options}
|
|
31
34
|
bind:selectedOptions
|
|
32
35
|
{placeholder}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import { type SelectOption } from './types.js';
|
|
4
4
|
interface Props {
|
|
5
5
|
id?: string;
|
|
6
|
+
className?: string,
|
|
6
7
|
options: SelectOption[];
|
|
7
8
|
value?: string;
|
|
8
9
|
placeholder?: string;
|
|
@@ -14,6 +15,7 @@
|
|
|
14
15
|
|
|
15
16
|
let {
|
|
16
17
|
id,
|
|
18
|
+
className,
|
|
17
19
|
options,
|
|
18
20
|
value = $bindable(''),
|
|
19
21
|
placeholder,
|
|
@@ -32,6 +34,7 @@
|
|
|
32
34
|
|
|
33
35
|
<BaseSelect
|
|
34
36
|
{id}
|
|
37
|
+
{className}
|
|
35
38
|
{options}
|
|
36
39
|
bind:selectedOptions
|
|
37
40
|
{placeholder}
|
|
@@ -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 w-full"
|
|
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 w-full"
|
|
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>
|