react-hot-toast
react-hot-toast copied to clipboard
Feature: configurable dismiss timer duration
The dismiss operation had a hardcoded delay value of 1000 milliseconds which was not configurable. Made some changes to the store.ts file so that a value for the dismiss delay could be passed like so:
toast.custom(
(t) => (
// custom jsx here.
),
{ dismissDelay: 500 }
);
*Also added the new type to the associated types.ts file.
Closes issue https://github.com/timolins/react-hot-toast/issues/74 These are non-breaking changes (backward-compatible)
This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.
🔍 Inspect: https://vercel.com/timo/react-hot-toast/BxJ7hRyCg1dWRkn95eMrx2hw14pH
✅ Preview: https://react-hot-toast-git-fork-nfuad-main-timo1.vercel.app
Updated the docs too now :)
I use react-hot-toast in headless mode and handle the animation with framer-motion, this option will be really useful to be able to dismiss the toast instantly and let framer-motion remove it with AnimatePresence
Thanks a lot for this PR, @nfuad. Much appreciated. Also thanks to @efflam for clarifying why this is needed.
One thing I'd like to change before merging is renaming the option to removeDelay (as well as the docs).
There is toast.dismiss() which starts the timeout, and toast.remove() which actually removes it. I think it would be more consistent this way, as this option delays the remove, not the dismiss.
Edit: One more thought on the docs: I'd assume that (if you're using headless-mode + framer-motion) you'd want to extend the delay for all toasts, not just one. Maybe showing how to apply to all via the Toaster would be a more fitting example.
Thank you, @efflam for clarifying the use case. In my case though, I just want to show an exit animation that is less than 1 second.
Thank you, @timolins for taking a look. Agreed that removeDelay is a much more fitting name so I've renamed the option now and updated the docs too. Also added an example using the option in the <Toaster /> component in the docs. Let me know if this is good or you want me to make some other changes. :)
Thanks a lot! I'll review the PR shorty.
@nfuad Because you mentioned you need this for shorter animations: The default exit animation is also just 0.4s long. You can preserve the final state of the animation by using animation-fill-mode: forwards;. This way the toast stays invisible and it doesn't need to be remove at an exact time.
@timolins, ah yeah, that would work as well. Thanks for letting me know :)
Hello guys, any update on this PR, with our team we have the exact same usecase as @efflam and this PR would be indeed very useful ! Thanks for your work @nfuad and @timolins for this lib we use in every of our projects !
It will be merged someday? Why it's still open?
This would be a useful addition. The current default makes it feel a little unresponsive for the user.
@nfuad I'm new to open source. Please can you provide me a setup guide I will like to contribute. When I tried in my local the src is getting bundled and after running sites, it is picking from dist.
is this going to me merged soon? Would be really helpful.
would love to see this PR merged :)
The latest updates on your projects. Learn more about Vercel for Git ↗︎
| Name | Status | Preview | Comments | Updated (UTC) |
|---|---|---|---|---|
| react-hot-toast | ❌ Failed (Inspect) | Jan 13, 2024 2:18pm |
@cquanu I'm not sure if I can see why the vercel build is failing - please feel free to take over and merge the PR.
@nfuad Sorry I'm not the maintainer - won't be able to do this.