Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to pass Component into ToastBar? #15

Open
winston0410 opened this issue Nov 13, 2022 · 2 comments
Open

How to pass Component into ToastBar? #15

winston0410 opened this issue Nov 13, 2022 · 2 comments
Labels
bug Something isn't working documentation Improvements or additions to documentation
Milestone

Comments

@winston0410
Copy link

winston0410 commented Nov 13, 2022

Is ToastBar intended to be called separately, or is using Component in ToastBar an old API?

I have seen your blog post, which seems to suggest passing Component to ToastBar from Toaster, but from the current source it does not accepting a Component props:

export let reverseOrder = false;
export let position: ToastPosition = 'top-center';
export let toastOptions: ToastOptions | undefined = undefined;
export let gutter = 8;
export let containerStyle: string | undefined = undefined;
export let containerClassName: string | undefined = undefined;

If that is indeed an old API, how can I use custom component as the toast?

@kbrgl
Copy link
Owner

kbrgl commented Nov 15, 2022

The API isn't old, you're definitely on the right track. But I haven't really gotten around to documenting the more obscure use cases yet (sorry about that!). In this case, it looks like you found a mistake—I did not implement custom children for the Toaster, which React Hot Toast allows.

So if you're trying to do a custom component, it looks like you've got one option until a fix is out: useToaster(). The API is pretty close to React Hot Toast's useToaster hook, which you can find here.

Let me know if this makes sense, or if something doesn't work.

@kbrgl kbrgl added bug Something isn't working documentation Improvements or additions to documentation labels Nov 15, 2022
@winston0410
Copy link
Author

No worry it makes perfect sense. One of a simple improvement I can think of, is to use <slot> and $$slots here

<ToastWrapper {toast} setHeight={(height) => handlers.updateHeight(toast.id, height)} />

So user can still create a headless toast, but using the default toaster so there is one less step to take. It is a headless approach, so user will need to implement the position css themselves.

What do you think about this? if you are happy I can create a PR

@kbrgl kbrgl added this to the 2.0 milestone Jan 10, 2023
@kbrgl kbrgl pinned this issue Mar 6, 2023
@kbrgl kbrgl unpinned this issue Jun 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants