|
4 | 4 | import type { SelectOption } from '$lib/combobox/types';
|
5 | 5 | import type { ComboboxSearchEvent } from '$lib/combobox/types';
|
6 | 6 | import type { ComboboxChangeEvent } from '$lib/combobox/types';
|
| 7 | + import type { ChipListChangeEvent } from '$lib/chiplist/types'; |
7 | 8 |
|
8 | 9 | import { COLOR_MODE, FILL_MODE } from '$lib/types';
|
9 | 10 |
|
|
16 | 17 | import Menu from '$lib/menu/Menu.svelte';
|
17 | 18 | import Paginator from '$lib/paginator/Paginator.svelte';
|
18 | 19 | import Combobox from '$lib/combobox/Combobox.svelte';
|
| 20 | + import ChipList from '$lib/chiplist/ChipList.svelte'; |
19 | 21 |
|
20 | 22 | export let data: PageData;
|
21 | 23 |
|
|
84 | 86 | }
|
85 | 87 | ];
|
86 | 88 |
|
| 89 | + let comboboxValue: SelectOption | undefined = undefined; |
| 90 | +
|
87 | 91 | let filteredComboboxOptions = comboboxOptions;
|
88 | 92 |
|
| 93 | + let selectedComboboxOptions: SelectOption[] = []; |
| 94 | +
|
89 | 95 | function filterComboboxOptions(searchText: string) {
|
90 |
| - const filteredOptions = comboboxOptions.filter((x) => { |
91 |
| - return x.text.toLocaleLowerCase().includes(searchText); |
| 96 | + const selectedValues = selectedComboboxOptions.map((x) => { |
| 97 | + return x.value; |
92 | 98 | });
|
93 | 99 |
|
| 100 | + const filteredOptions = comboboxOptions |
| 101 | + .filter((x) => { |
| 102 | + return !selectedValues.includes(x.value); |
| 103 | + }) |
| 104 | + .filter((x) => { |
| 105 | + return x.text.toLocaleLowerCase().includes(searchText); |
| 106 | + }); |
| 107 | +
|
94 | 108 | return filteredOptions;
|
95 | 109 | }
|
96 | 110 |
|
|
101 | 115 | }
|
102 | 116 |
|
103 | 117 | function handleComboboxChange(e: ComboboxChangeEvent) {
|
104 |
| - const searchText = ''; |
| 118 | + selectedComboboxOptions = [...selectedComboboxOptions, e.detail.value]; |
105 | 119 |
|
106 |
| - filteredComboboxOptions = filterComboboxOptions(searchText); |
| 120 | + filteredComboboxOptions = filterComboboxOptions(''); |
| 121 | +
|
| 122 | + comboboxValue = undefined; |
| 123 | + } |
| 124 | +
|
| 125 | + function handleChipListChange(e: ChipListChangeEvent) { |
| 126 | + selectedComboboxOptions = [...e.detail.value]; |
107 | 127 | }
|
108 | 128 | </script>
|
109 | 129 |
|
|
187 | 207 | <section>
|
188 | 208 | <h1 class="mb-4 text-2xl">Combobox</h1>
|
189 | 209 |
|
190 |
| - <div class="w-1/4"> |
| 210 | + <div class="flex w-1/4 flex-col gap-2"> |
191 | 211 | <Combobox
|
| 212 | + bind:value={comboboxValue} |
192 | 213 | options={filteredComboboxOptions}
|
193 | 214 | on:search={handleComboboxSearch}
|
194 | 215 | on:change={handleComboboxChange}
|
195 | 216 | />
|
| 217 | + |
| 218 | + <ChipList value={selectedComboboxOptions} on:change={handleChipListChange} /> |
196 | 219 | </div>
|
197 | 220 | </section>
|
198 | 221 |
|
|
0 commit comments