Animations on the toast messages and remove on click.

This commit is contained in:
Bradley Shellnut 2021-07-28 16:04:44 -07:00
parent 6af33c27d2
commit b1fd5a59af
3 changed files with 20 additions and 5 deletions

View file

@ -1,12 +1,20 @@
<script>
import { fly, fade } from 'svelte/transition';
import { flip } from 'svelte/animate';
import Portal from '../Portal.svelte';
import { toast } from './toast';
</script>
<Portal>
<div class="toast-wrapper">
{#each $toast as message}
<div class="toast">
{#each $toast as message (message)}
<div
on:click={toast.remove}
animate:flip
out:fade
in:fly={{ opacity: 0, x: 100 }}
class="toast"
>
<p>{message}</p>
</div>
{/each}

View file

@ -6,10 +6,17 @@ const newToast = () => {
function send(message) {
update((state) => {
return [...state, message];
})
});
}
return { subscribe, send };
function remove() {
update((state) => {
let [first, ...rest] = state;
return [...rest];
});
}
return { subscribe, send, remove };
}
export const toast = newToast();

View file

@ -27,7 +27,7 @@
</Modal>
<Toast />
<button on:click={() => toast.send('New Message')}>New Toast</button>
<button on:click={() => toast.send('New Message' + Math.random())}>New Toast</button>
<!-- <button on:click={() => (isModalOpen = true)}>Open Modal Form</button> -->