Blazored / Toast

A JavaScript free toast library for Blazor and Razor Component applications
https://blazored.github.io/Toast/
MIT License
663 stars 92 forks source link

[Feature] Support for infinite timeout #193

Closed macias closed 1 year ago

macias commented 1 year ago

Many thanks for very useful Blazor library.

Describe the solution you'd like

Support for infinite timeout (preferable value = -1 to be in sync with Timeout.Infinite). This would mean toast would not close itself, but user would have to manually close it.

Describe alternatives you've considered

Using old-fashion JS alert in such cases.

Additional context

Infinite timeout is pretty trivial to add, the question is should progress AND infinite timeout be supported at the same time. If no, this would mean skipping countdown timer entirely (?) but if "yes" it is no longer trivial, because it would mean some animated progress (e.g. like bouncing left and right).

Cvijo commented 1 year ago

I think this would require some more changes as discussed here

Main question is how to close toast without timeout?

I guess simple solution would be if you set unlimited timeout that Toast should have close button always rendered on top even on your custom component over your ChildContent and you can't remove or change it.

Or another maybe dirty solution to override timeout to Int.MaxValue in that case, so it doesn't break other things

chrissainty commented 1 year ago

Having had some time to noodle on this, I don't think giving Timeout a special value to indicate infinite is the right way to go. If you think about it, It's not an infinite timeout, you're choosing to disable or remove the timeout.

I think the better API is something more obvious, a new option along the lines of NoTimeout. When true, we would omit all of the CountdownTimer code and the toast would display until it was manually closed.

@Cvijo brings up valid questions regarding the presence of a close button. For the default toasts, it should be fine. As suggested, when NoTimeout is true, we can always show the close x on the default toasts. But for custom toasts, we'll have to have faith the developer provides a close button. They do have access to a Close method on the cascaded BlazoredToast instance.