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,9 +1,5 @@
|
||||
<script lang="ts">
|
||||
import {
|
||||
ToastType,
|
||||
type Toast,
|
||||
toasts,
|
||||
} from '$lib/components/ui/toasts/toasts'
|
||||
import { type Toast, toasts } from '$lib/components/ui/toasts/toasts'
|
||||
import {
|
||||
InformationCircle,
|
||||
ExclamationTriangle,
|
||||
@@ -29,13 +25,13 @@
|
||||
size="20"
|
||||
solid
|
||||
class="relative m-2 ml-4 flex-shrink-0"
|
||||
src={toast.type == ToastType.info
|
||||
src={toast.type == 'info'
|
||||
? InformationCircle
|
||||
: toast.type == ToastType.success
|
||||
: toast.type == 'success'
|
||||
? CheckCircle
|
||||
: toast.type == ToastType.warning
|
||||
: toast.type == 'warning'
|
||||
? ExclamationTriangle
|
||||
: toast.type == ToastType.error
|
||||
: toast.type == 'error'
|
||||
? ExclamationCircle
|
||||
: ExclamationCircle}
|
||||
/>
|
||||
|
||||
@@ -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