sveltekit-flash-message
sveltekit-flash-message copied to clipboard
Feature Request: More properties to work better with svelte-sonner
I love this library especially with forms. Thanks
I have recently started using svelte-sonner and it would be really cool if we could send down the properties of description and action. and add the enums for type ie: warning, info, promise, etc..
I mean it already works, but I get type errors, so i guess you just need to add more types
if (!session) {
throw redirect(
302,
'/auth/login',
{
// @ts-ignore
type: 'warning',
message: 'Not Authorized',
description: 'You need to be logged in to Create event',
action: {
label: 'Back',
onClick: () => goto(url.searchParams.get('from') ?? '')
}
},
cookies
)
}
const flash = getFlash(page) as any
$: if ($flash) {
toast[$flash.type]($flash.message, {
description: $flash.description,
action: $flash.action
})
}
EDIT: Actually i think this would make it work better with svelte french toast as well
You cannot serialize functions, only JSON-friendly structures are allowed. Therefore you need to make the action/onClick property serializable and add the function on the client instead. When you have fixed that, adding the type to src/app.d.ts should make it type-safe: https://github.com/ciscoheat/sveltekit-flash-message?tab=readme-ov-file#1-add-the-flash-message-to-appdts-typescript-only
Oh ya I totally forgot that was part of the set up. Thanks