UNPKG

@fefade/svelte

Version:

Reusable Svelte UI components powered by the FEFADE core system.

25 lines (24 loc) 697 B
import { Constants } from "@fefade/core"; import { SvelteMap } from "svelte/reactivity"; let data = new SvelteMap(); export default function toastState() { return { get data() { return data; }, add(toast) { const id = crypto.randomUUID(); const duration = toast.duration ?? Constants.TOAST_DEFAULT_DURATION; const position = toast.position ?? "bottom-right"; data.set(id, { ...toast, duration, position }); return id; }, remove(id) { data.delete(id); } }; } export function toast(toast) { const _toastState = toastState(); _toastState.add(toast); }