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.
@@ -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}
@@ -1,6 +1,7 @@
1
1
  import { type SelectOption } from './types.ts';
2
2
  interface Props {
3
3
  id?: string;
4
+ className?: string;
4
5
  options: SelectOption[];
5
6
  selectedOptions: string[];
6
7
  placeholder?: string;
@@ -3,7 +3,7 @@
3
3
  import { type SelectOption } from './types.js';
4
4
 
5
5
  interface Props {
6
- label: string;
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>{label}</span>
48
+ <span>{displayLabel}</span>
42
49
  <i class="bi bi-chevron-{isOpen ? 'up' : 'down'}"></i>
43
50
  </button>
44
51
  {#if isOpen}
@@ -1,6 +1,6 @@
1
1
  import { type SelectOption } from './types.ts';
2
2
  interface Props {
3
- label: string;
3
+ label?: string;
4
4
  options: SelectOption[];
5
5
  selectedOptions: string[];
6
6
  multiple?: boolean;
@@ -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}
@@ -1,6 +1,7 @@
1
1
  import { type SelectOption } from './types.ts';
2
2
  interface Props {
3
3
  id?: string;
4
+ className?: string;
4
5
  options: SelectOption[];
5
6
  selectedOptions: string[];
6
7
  placeholder?: string;
@@ -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}
@@ -1,6 +1,7 @@
1
1
  import { type SelectOption } from './types.ts';
2
2
  interface Props {
3
3
  id?: string;
4
+ className?: string;
4
5
  options: SelectOption[];
5
6
  value?: string;
6
7
  placeholder?: string;
@@ -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
- <div class="menu dropdown-content flex-nowrap w-full max-h-46 overflow-auto bg-base-100 rounded-box z-1 p-2 shadow-sm gap-1">
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
- {#if multiple}
61
- <input
62
- bind:this={optionElements[index]}
63
- type="checkbox"
64
- class="btn"
65
- class:btn-primary={checked}
66
- {checked}
67
- aria-label={option.label}
68
- onclick={() => selectOption(option)}
69
- />
70
- {:else}
71
- <button
72
- bind:this={optionElements[index]}
73
- type="button"
74
- class="btn"
75
- class:btn-primary={checked}
76
- onclick={() => selectOption(option)}
77
- >
78
- {option.label}
79
- </button>
80
- {/if}
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
- </div>
91
+ </ul>
@@ -4,6 +4,7 @@ interface Props {
4
4
  selectedOptions: string[];
5
5
  multiple?: boolean;
6
6
  isOpen?: boolean;
7
+ highlightedIndex?: number;
7
8
  onSelected?: (value: string[]) => void;
8
9
  onOpenDropdown?: () => void;
9
10
  onCloseDropdown?: () => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ankiutils",
3
- "version": "0.0.10",
3
+ "version": "0.0.12",
4
4
  "license": "AGPL-3.0-or-later",
5
5
  "scripts": {
6
6
  "dev": "vite dev",