sveltekit-flash-message icon indicating copy to clipboard operation
sveltekit-flash-message copied to clipboard

Feature Request: More properties to work better with svelte-sonner

Open Schmell opened this issue 1 year ago • 2 comments

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

Schmell avatar Mar 15 '24 15:03 Schmell

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

ciscoheat avatar Mar 15 '24 16:03 ciscoheat

Oh ya I totally forgot that was part of the set up. Thanks

Schmell avatar Mar 16 '24 12:03 Schmell