wobsoriano/svelte-sonner

Is there a way to pass properties to custom components?

Closed this issue · 4 comments

enyo commented

The docs show this:

import HeadlessToast from './HeadlessToast.svelte'
toast.custom(HeadlessToast)

But in the example provided, what if I want the time + description to be provided to the HeadlessToast component? Is that possible?

enyo commented

I've looked at the source and found this:

 {#if toast.component}
    <svelte:component this={toast.component} on:closeToast={deleteToast}></svelte:component>
 {:else ...}

so it doesn't seem to be possible to provide data.

How about adding an additional configuration option here:

export interface ToastT {
id: number | string
title?: string | ComponentType
type?: ToastTypes
icon?: ComponentType
component?: ComponentType

I would suggest componentProps. This could then be applied to <svelte:component when instantiating.

@wobsoriano does this sound good to you? If so, I can create a PR.

enyo commented

Since I need this feature I went ahead and created a PR #22

Hey, will take a look tomorrow. Thanks!

Fixed in #22