42 lines
922 B
Svelte
42 lines
922 B
Svelte
<script>
|
|
import { fly } from 'svelte/transition';
|
|
import { onDestroy } from 'svelte';
|
|
|
|
export let message = '';
|
|
export let kind = 'info';
|
|
export let id = 0;
|
|
|
|
let visible = false;
|
|
let timer = null;
|
|
|
|
function reset() {
|
|
if (timer) clearTimeout(timer);
|
|
visible = !!message;
|
|
if (message) {
|
|
timer = setTimeout(() => {
|
|
visible = false;
|
|
}, 4200);
|
|
}
|
|
}
|
|
|
|
$: message, id, reset();
|
|
|
|
onDestroy(() => {
|
|
if (timer) clearTimeout(timer);
|
|
});
|
|
</script>
|
|
|
|
{#if visible}
|
|
<div class="fixed bottom-5 left-1/2 z-50 -translate-x-1/2 px-4" transition:fly={{ y: 8, duration: 160 }}>
|
|
<div
|
|
class="rounded-md border px-4 py-2.5 text-sm {kind === 'error'
|
|
? 'border-danger/40 bg-surface text-danger'
|
|
: kind === 'success'
|
|
? 'border-ok/40 bg-surface text-ok'
|
|
: 'border-edge bg-surface text-ink'}"
|
|
>
|
|
{message}
|
|
</div>
|
|
</div>
|
|
{/if}
|