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

QUESTION: Passing an Icon to cancel's label property? #273

Closed
njdowdy opened this issue Dec 27, 2023 · 3 comments · Fixed by #280
Closed

QUESTION: Passing an Icon to cancel's label property? #273

njdowdy opened this issue Dec 27, 2023 · 3 comments · Fixed by #280

Comments

@njdowdy
Copy link

njdowdy commented Dec 27, 2023

Is there a way to use an icon for the cancel functionality's label property? From the types, it appears that only strings are allowed. But I am looking for something like this:

<Button variant="default" onClick={() => toast("Cancel Me: ", { cancel: { label: <MyIcon /> } })}>
        Send Toast!
</Button>

I can do the following:

const jsx = (t: string | number) => (
    <div className="flex flex-row justify-between">
      <h1>Cancel Me: </h1>
      <button onClick={() => toast.dismiss(t)}><MyIcon /></button>
    </div>
)
<Button variant="default" onClick={() => toast.custom((t) => jsx(t), { style: { display: "block" }})}> 
        Send Toast!
</Button>

But then I lose all the other default styles, which I want to keep.

The other method I found is this:

const jsx = (
    <div className="flex flex-row justify-between">
      <h1>Cancel Me: </h1>
      <button onClick={() => toast.dismiss()}><MyIcon /></button>
    </div>
)
<Button variant="default" onClick={() => toast(jsx, { style: { display: "block" }})}> 
        Send Toast!
</Button>

However, with this method I cannot be selective with the dismissing of toasts. I can only dismiss all toasts on click.

Is there another workaround that doesn't use toast.custom()?

Thanks!

@CanRau
Copy link
Contributor

CanRau commented Dec 29, 2023

You can just do

toast.success(`Toast text`, {
  action: {
    label: (
      <>
        <div className="text-red">custom label</div>
      </>
    ),
    onClick(event) {
      console.log("toast.action.onClick", event);
    },
  },
});

I opened #280 which would make it work with Typescript 🤞🏼

@njdowdy njdowdy closed this as completed Dec 29, 2023
@njdowdy
Copy link
Author

njdowdy commented Dec 29, 2023

Thanks, @CanRau!

@CanRau
Copy link
Contributor

CanRau commented Dec 31, 2023

Has been merged, now we only need to wait for the next release 🙌🏼

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants