feat: switch to a string instead of enum
This commit is contained in:
1 parent
aeb727ae3b
commit
87612d6507
23 files changed
+92
-128
No files matched your search
@@ -1,10 +1,12 @@
|
||||
import { writable } from 'svelte/store'
|
||||
|
||||
export enum ToastType {
|
||||
'error' = 'bg-red-500 text-white border border-red-600',
|
||||
'warning' = 'bg-yellow-400 text-black border border-yellow-500',
|
||||
'success' = 'bg-green-400 text-black border border-green-500',
|
||||
'info' = 'dark:bg-zinc-900 bg-white border border-slate-200 dark:border-zinc-800 shadow-lg',
|
||||
type ToastType = keyof typeof toastColors
|
||||
|
||||
const toastColors = {
|
||||
error: 'bg-red-500 text-white border border-red-600',
|
||||
warning: 'bg-yellow-400 text-black border border-yellow-500',
|
||||
success: 'bg-green-400 text-black border border-green-500',
|
||||
info: 'dark:bg-zinc-900 bg-white border border-slate-200 dark:border-zinc-800 shadow-lg',
|
||||
}
|
||||
|
||||
export interface Toast {
|
||||
@@ -19,7 +21,7 @@ export const toasts = writable<Toast[]>([])
|
||||
export function toast({
|
||||
title,
|
||||
content,
|
||||
type = ToastType.info,
|
||||
type = 'info',
|
||||
duration = 5000,
|
||||
}: {
|
||||
title?: string
|
||||
@@ -47,32 +49,3 @@ export function toast({
|
||||
toasts.update((toasts) => toasts.filter((toast) => toast.id != id))
|
||||
}, duration)
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use @function toast
|
||||
*/
|
||||
export function addToast(
|
||||
title: string | undefined,
|
||||
content: string,
|
||||
type: ToastType
|
||||
) {
|
||||
let id = 0
|
||||
|
||||
toasts.update((toasts) => {
|
||||
id = Math.floor(Math.random() * 10000)
|
||||
|
||||
return [
|
||||
{
|
||||
id: id,
|
||||
content: content,
|
||||
title: title,
|
||||
type: type,
|
||||
},
|
||||
...toasts,
|
||||
]
|
||||
})
|
||||
|
||||
setTimeout(() => {
|
||||
toasts.update((toasts) => toasts.filter((toast) => toast.id != id))
|
||||
}, 5000)
|
||||
}
|
||||
Reference in new issue
Block a user