Dieser Commit ist enthalten in:
Chaoscaot 2023-07-25 17:06:28 +02:00
Ursprung b869933c5e
Commit 5ba5a642e4
Signiert von: Chaoscaot
GPG-Schlüssel-ID: BDF8FADD7D5EDB7A
2 geänderte Dateien mit 18 neuen und 19 gelöschten Zeilen

Datei anzeigen

@ -17,7 +17,7 @@
$: selectPlayers = $players.map(player => {
return {
name: player.name,
value: player.id
value: player.id.toString()
}
}).sort((a, b) => a.name.localeCompare(b.name));

Datei anzeigen

@ -1,31 +1,30 @@
<script lang="ts">
import {Dropdown, DropdownItem, Search} from 'flowbite-svelte'
import {Button, Dropdown, DropdownItem, Search} from 'flowbite-svelte'
export let selected: string = ''
export let items: {name: string, value: string}[] = []
export let all = false
export let searchValue = items.find(item => item.value === selected)?.name || ''
let focus = false
let open = false
$: filteredItems = items.filter(item => item.name.toLowerCase().includes(searchValue.toLowerCase()))
$: openDropdown = filteredItems.length > 0 && searchValue.length >= 3 && focus || all && focus
$: filteredItems = items.filter(item => item.name.toLowerCase().includes(searchValue.toLowerCase())).filter((value, index) => index < 5)
$: console.log(selected)
function selectItem(item) {
function selectItem(item: {name: string, value: string}) {
selected = item.value
searchValue = item.name
focus = false
open = false
}
</script>
<Search bind:value={searchValue} on:focus={() => focus = true} on:keydown={() => focus = true}/>
{#if (openDropdown)}
<Dropdown open class="z-10 py-1 w-44">
{#each filteredItems as item}
<DropdownItem on:click={() => selectItem(item)}>
{item.name}
</DropdownItem>
{/each}
</Dropdown>
<div class="z-10"></div>
{/if}
<Button color="alternative" on:click={() => open = true}>{selected === null ? 'Auswählen' : items.find(value => value.value === selected)?.name}</Button>
<Dropdown bind:open class="w-60">
<div class="overflow-y-auto p-3 text-sm" slot="header">
<Search bind:value={searchValue} on:focus={() => open = true} on:keydown={() => open = true}/>
</div>
{#each filteredItems as item}
<button on:click={() => selectItem(item)} class="rounded p-2 hover:bg-gray-100 dark:hover:bg-gray-600 w-full cursor-pointer border-b border-b-gray-600">
{item.name}
</button>
{/each}
</Dropdown>