2024-01-28 01:54:31 +01:00
|
|
|
<script lang="ts">
|
|
|
|
|
import { mdiClose, mdiMagnify } from '@mdi/js';
|
2024-02-22 15:04:43 +01:00
|
|
|
import Icon from './icon.svelte';
|
2024-01-28 01:54:31 +01:00
|
|
|
import { createEventDispatcher } from 'svelte';
|
|
|
|
|
import type { SearchOptions } from '$lib/utils/dipatch';
|
|
|
|
|
import LoadingSpinner from '../shared-components/loading-spinner.svelte';
|
|
|
|
|
|
|
|
|
|
export let name: string;
|
2024-02-24 01:42:37 +01:00
|
|
|
export let roundedBottom = true;
|
2024-02-22 15:04:43 +01:00
|
|
|
export let isSearching: boolean;
|
|
|
|
|
export let placeholder: string;
|
2024-01-28 01:54:31 +01:00
|
|
|
|
|
|
|
|
const dispatch = createEventDispatcher<{ search: SearchOptions; reset: void }>();
|
|
|
|
|
|
|
|
|
|
const resetSearch = () => {
|
|
|
|
|
name = '';
|
|
|
|
|
dispatch('reset');
|
|
|
|
|
};
|
|
|
|
|
</script>
|
|
|
|
|
|
2024-02-24 01:42:37 +01:00
|
|
|
<div
|
|
|
|
|
class="flex items-center text-sm {roundedBottom
|
|
|
|
|
? 'rounded-lg'
|
|
|
|
|
: 'rounded-t-lg'} bg-gray-100 p-2 dark:bg-gray-700 gap-2 place-items-center h-full"
|
|
|
|
|
>
|
2024-01-28 01:54:31 +01:00
|
|
|
<button on:click={() => dispatch('search', { force: true })}>
|
|
|
|
|
<div class="w-fit">
|
|
|
|
|
<Icon path={mdiMagnify} size="24" />
|
|
|
|
|
</div>
|
|
|
|
|
</button>
|
|
|
|
|
<!-- svelte-ignore a11y-autofocus -->
|
|
|
|
|
<input
|
|
|
|
|
autofocus
|
|
|
|
|
class="w-full gap-2 bg-gray-100 dark:bg-gray-700 dark:text-white"
|
|
|
|
|
type="text"
|
2024-02-22 15:04:43 +01:00
|
|
|
{placeholder}
|
2024-01-28 01:54:31 +01:00
|
|
|
bind:value={name}
|
|
|
|
|
on:input={() => dispatch('search', { force: false })}
|
|
|
|
|
/>
|
2024-02-22 15:04:43 +01:00
|
|
|
{#if isSearching}
|
2024-01-28 01:54:31 +01:00
|
|
|
<div class="flex place-items-center">
|
|
|
|
|
<LoadingSpinner />
|
|
|
|
|
</div>
|
|
|
|
|
{/if}
|
|
|
|
|
{#if name}
|
|
|
|
|
<button on:click={resetSearch}>
|
|
|
|
|
<Icon path={mdiClose} />
|
|
|
|
|
</button>
|
|
|
|
|
{/if}
|
|
|
|
|
</div>
|