diff --git a/src/components/tools/DonationCreate.svelte b/src/components/tools/DonationCreate.svelte index c681a0bc..898da443 100644 --- a/src/components/tools/DonationCreate.svelte +++ b/src/components/tools/DonationCreate.svelte @@ -12,235 +12,99 @@ // let options = [ - "Bulbasaur", - "Ivysaur", - "Venusaur", - "Charmander", - "Charmeleon", - "Charizard", - "Squirtle", - "Wartortle", - "Blastoise", - "Caterpie", - "Metapod", - "Butterfree", - "Weedle", - "Kakuna", - "Beedrill", - "Pidgey", - "Pidgeotto", - "Pidgeot", - "Rattata", - "Raticate", - "Spearow", - "Fearow", - "Ekans", - "Arbok", - "Pikachu", - "Raichu", - "Sandshrew", - "Sandslash", - "Nidoran♀", - "Nidorina", - "Nidoqueen", - "Nidoran♂", - "Nidorino", - "Nidoking", - "Clefairy", - "Clefable", - "Vulpix", - "Ninetales", - "Jigglypuff", - "Wigglytuff", - "Zubat", - "Golbat", - "Oddish", - "Gloom", - "Vileplume", - "Paras", - "Parasect", - "Venonat", - "Venomoth", - "Diglett", - "Dugtrio", - "Meowth", - "Persian", - "Psyduck", - "Golduck", - "Mankey", - "Primeape", - "Growlithe", - "Arcanine", - "Poliwag", - "Poliwhirl", - "Poliwrath", - "Abra", - "Kadabra", - "Alakazam", - "Machop", - "Machoke", - "Machamp", - "Bellsprout", - "Weepinbell", - "Victreebel", - "Tentacool", - "Tentacruel", - "Geodude", - "Graveler", - "Golem", - "Ponyta", - "Rapidash", - "Slowpoke", - "Slowbro", - "Magnemite", - "Magneton", - "Farfetch'd", - "Doduo", - "Dodrio", - "Seel", - "Dewgong", - "Grimer", - "Muk", - "Shellder", - "Cloyster", - "Gastly", - "Haunter", - "Gengar", - "Onix", - "Drowzee", - "Hypno", - "Krabby", - "Kingler", - "Voltorb", - "Electrode", - "Exeggcute", - "Exeggutor", - "Cubone", - "Marowak", - "Hitmonlee", - "Hitmonchan", - "Lickitung", - "Koffing", - "Weezing", - "Rhyhorn", - "Rhydon", - "Chansey", - "Tangela", - "Kangaskhan", - "Horsea", - "Seadra", - "Goldeen", - "Seaking", - "Staryu", - "Starmie", - "Mr. Mime", - "Scyther", - "Jynx", - "Electabuzz", - "Magmar", - "Pinsir", - "Tauros", - "Magikarp", - "Gyarados", - "Lapras", - "Ditto", - "Eevee", - "Vaporeon", - "Jolteon", - "Flareon", - "Porygon", - "Omanyte", - "Omastar", - "Kabuto", - "Kabutops", - "Aerodactyl", - "Snorlax", - "Articuno", - "Zapdos", - "Moltres", - "Dratini", - "Dragonair", - "Dragonite", - "Mewtwo", - "Mew", - "Chikorita", - "Bayleef", - "Meganium", - "Cyndaquil", - "Quilava", - "Typhlosion", - "Totodile", - "Croconaw", - "Feraligatr", - "Sentret", - "Furret", - "Hoothoot", - "Noctowl", - "Ledyba", - "Ledian", - "Spinarak", - "Ariados", - "Crobat", - "Chinchou", - "Lanturn", - "Pichu", - "Cleffa", - "Igglybuff", - "Togepi", - "Togetic", - "Natu", - "Xatu", - "Mareep", - "Flaaffy", - "Ampharos", - "Bellossom", - "Marill", - "Azumarill", - "Sudowoodo", - "Politoed", - "Hoppip", - "Skiploom", - "Jumpluff", - "Aipom", - "Sunkern", - "Sunflora", - "Yanma", - "Wooper", - "Quagsire", - "Espeon", - "Umbreon", - "Murkrow", - "Slowking", - "Misdreavus", - "Unown", - "Wobbuffet", - "Girafarig", - "Pineco", - "Forretress", - "Dunsparce", - "Gligar", - "Steelix", - "Snubbull", - "Granbull", - "Qwilfish", - "Scizor", - "Shuckle", - "Heracross", - "Sneasel", - "Teddiursa", - "Ursaring", - "Slugma", - "Magcargo", - "Swinub", - "Piloswine", - "Corsola", - "Remoraid", - "Octillery", - "Delibird", - "Mantine", - "Skarmory", - "Houndour", - "Houndoom", + { label: "Bulbasaur", value: { id: 456 } }, + { label: "Ivysaur", value: { id: 456 } }, + { label: "Venusaur", value: { id: 456 } }, + { label: "Charmander", value: { id: 456 } }, + { label: "Charmeleon", value: { id: 456 } }, + { label: "Charizard", value: { id: 456 } }, + { label: "Squirtle", value: { id: 456 } }, + { label: "Wartortle", value: { id: 456 } }, + { label: "Blastoise", value: { id: 456 } }, + { label: "Caterpie", value: { id: 456 } }, + { label: "Metapod", value: { id: 456 } }, + { label: "Butterfree", value: { id: 456 } }, + { label: "Weedle", value: { id: 456 } }, + { label: "Kakuna", value: { id: 456 } }, + { label: "Beedrill", value: { id: 456 } }, + { label: "Pidgey", value: { id: 456 } }, + { label: "Pidgeotto", value: { id: 456 } }, + { label: "Pidgeot", value: { id: 456 } }, + { label: "Rattata", value: { id: 456 } }, + { label: "Raticate", value: { id: 456 } }, + { label: "Spearow", value: { id: 456 } }, + { label: "Fearow", value: { id: 456 } }, + { label: "Ekans", value: { id: 456 } }, + { label: "Arbok", value: { id: 456 } }, + { label: "Pikachu", value: { id: 456 } }, + { label: "Raichu", value: { id: 456 } }, + { label: "Sandshrew", value: { id: 456 } }, + { label: "Sandslash", value: { id: 456 } }, + { label: "Nidoran♀", value: { id: 456 } }, + { label: "Nidorina", value: { id: 456 } }, + { label: "Nidoqueen", value: { id: 456 } }, + { label: "Nidoran♂", value: { id: 456 } }, + { label: "Nidorino", value: { id: 456 } }, + { label: "Nidoking", value: { id: 456 } }, + { label: "Clefairy", value: { id: 456 } }, + { label: "Clefable", value: { id: 456 } }, + { label: "Vulpix", value: { id: 456 } }, + { label: "Ninetales", value: { id: 456 } }, + { label: "Jigglypuff", value: { id: 456 } }, + { label: "Wigglytuff", value: { id: 456 } }, + { label: "Zubat", value: { id: 456 } }, + { label: "Golbat", value: { id: 456 } }, + { label: "Oddish", value: { id: 456 } }, + { label: "Gloom", value: { id: 456 } }, + { label: "Vileplume", value: { id: 456 } }, + { label: "Paras", value: { id: 456 } }, + { label: "Parasect", value: { id: 456 } }, + { label: "Venonat", value: { id: 456 } }, + { label: "Venomoth", value: { id: 456 } }, + { label: "Diglett", value: { id: 456 } }, + { label: "Dugtrio", value: { id: 456 } }, + { label: "Meowth", value: { id: 456 } }, + { label: "Persian", value: { id: 456 } }, + { label: "Psyduck", value: { id: 456 } }, + { label: "Golduck", value: { id: 456 } }, + { label: "Mankey", value: { id: 456 } }, + { label: "Primeape", value: { id: 456 } }, + { label: "Growlithe", value: { id: 456 } }, + { label: "Arcanine", value: { id: 456 } }, + { label: "Poliwag", value: { id: 456 } }, + { label: "Poliwhirl", value: { id: 456 } }, + { label: "Poliwrath", value: { id: 456 } }, + { label: "Abra", value: { id: 456 } }, + { label: "Kadabra", value: { id: 456 } }, + { label: "Alakazam", value: { id: 456 } }, + { label: "Machop", value: { id: 456 } }, + { label: "Machoke", value: { id: 456 } }, + { label: "Machamp", value: { id: 456 } }, + { label: "Bellsprout", value: { id: 456 } }, + { label: "Weepinbell", value: { id: 456 } }, + { label: "Victreebel", value: { id: 456 } }, + { label: "Tentacool", value: { id: 456 } }, + { label: "Tentacruel", value: { id: 456 } }, + { label: "Geodude", value: { id: 456 } }, + { label: "Graveler", value: { id: 456 } }, + { label: "Golem", value: { id: 456 } }, + { label: "Ponyta", value: { id: 456 } }, + { label: "Rapidash", value: { id: 456 } }, + { label: "Slowpoke", value: { id: 456 } }, + { label: "Slowbro", value: { id: 456 } }, + { label: "Magnemite", value: { id: 456 } }, + { label: "Magneton", value: { id: 456 } }, + { label: "Farfetch'd", value: { id: 456 } }, + { label: "Doduo", value: { id: 456 } }, + { label: "Dodrio", value: { id: 456 } }, + { label: "Seel", value: { id: 456 } }, + { label: "Dewgong", value: { id: 456 } }, + { label: "Grimer", value: { id: 456 } }, + { label: "Muk", value: { id: 456 } }, + { label: "Shellder", value: { id: 456 } }, + { label: "Cloyster", value: { id: 456 } }, + { label: "Gastly", value: { id: 456 } }, + { label: "Haunter", value: { id: 456 } }, ]; let selectedOption; @@ -351,14 +215,14 @@ {options} filterFn={(option, searchTerm) => { // Example: Match if option starts with search term (case-insensitive) - return option.toLowerCase().startsWith(searchTerm.toLowerCase()); + return option.label.toLowerCase().startsWith(searchTerm.toLowerCase()); }} bind:selected={selectedOption} placeholder="Search fruits..." on:select={handleSelect} /> {#if selectedOption} -
Selected: {selectedOption}
+Selected: {JSON.stringify(selectedOption)}
{/if} diff --git a/src/components/tools/VirtualSelect.svelte b/src/components/tools/VirtualSelect.svelte index 9e7f2de7..f1f31d04 100644 --- a/src/components/tools/VirtualSelect.svelte +++ b/src/components/tools/VirtualSelect.svelte @@ -4,7 +4,11 @@ // Props export let options = []; export let selected = null; - export let placeholder = "Search options..."; + export let inputPlaceholder = "Search options..."; + export let noOptionsText = "No options found"; + export let inputAriaLabel = "Search and select an option"; + export let toggleAriaLabel = "Toggle dropdown"; + export let clearAriaLabel = "Clear selection"; export let filterFn = null; // Custom filter function // Internal state @@ -26,7 +30,7 @@ ? filterFn ? options.filter((option) => filterFn(option, searchTerm)) : options.filter((option) => - option.toLowerCase().includes(searchTerm.toLowerCase()) + option.label.toLowerCase().includes(searchTerm.toLowerCase()) ) : options; // Reset scroll and focus when filtered options change @@ -63,11 +67,19 @@ // Handle option selection function selectOption(option) { - selected = option; + selected = option.value; isOpen = false; searchTerm = ""; focusedIndex = -1; - dispatch("onSelected", option); + dispatch("onSelected", option.value); + } + + // Handle clear selection + function clearSelection() { + selected = null; + searchTerm = ""; + focusedIndex = -1; + dispatch("onSelected", null); } // Toggle dropdown @@ -147,6 +159,13 @@ return () => resizeObserver.disconnect(); } }); + + // Get display text for the input + function getDisplayText() { + if (!selected) return inputPlaceholder; + const selectedOption = options.find((option) => option.value === selected); + return selectedOption ? selectedOption.label : inputPlaceholder; + }