Blazored/Toast

[Feature Request] Timeout Per Level

scottkuhl opened this issue ยท 9 comments

I would like to set the timeout value to a different default for each level. Some levels are arguably more important, so for example, warnings could be set a longer timeout and error messages never go away until manually closed.

Example:

If you set additional timeout values, they override the default timeout value.

Alternative:

ToastService.ShowInfo("Sample message", timeout: 10);

I think this makes a lot of sense and would definitely be something we can add to the library.

We have the concept of global and instance settings in Blazored Modal, we could implement this in a similar way.

Chris after you looking for a someone to help you maintain? I can donate some of my time as I use some of your extensions in projects.

Hi @dchupp. I'm always happy to have some help! :)

This feature would be a great addition

Just to add some weight to this, I too would find it very useful to be able to specify the timeout at the point of calling a Toast display method. It's a lovely little library, and per-call config would make it even better :)

The new custom toast option allows the timeout to be specified on a per toast basis.

The new custom toast option allows the timeout to be specified on a per toast basis.

Thank you - that worked a treat - I ended up writing an ICustomToastService as follows to encapsulate all of the param logic:

public class CustomToastService : ICustomToastService
{
   private readonly IToastService _toastService;

   public CustomToastService(IToastService toastService)
   {
      _toastService = toastService;
   }


   public void Show(string message, ToastLevel level, int timeout = 3)
   {
      var cssClass = "blazored-toast-" + level.ToString().ToLower();

      var toastParameters = new ToastParameters();
      toastParameters.Add("Title", level.ToString());
      toastParameters.Add("Message", message);
      toastParameters.Add("CssClass", cssClass);

      var settings = new ToastInstanceSettings(timeout, false);

      _toastService.ShowToast<CustomToastComponent>(toastParameters, settings);
   }
}

Then I simply injected that into the components instead. Then calling it is simply as follows:

CustomToastService.Show("This is a warning messahe with a 10 second timeout", ToastLevel.Warning, 10);

You have allowed the service to be integrated and configured really nicely. Great work, and thanks again for the guidance.

Thanks, @LaurenceFrost. Glad you got it all working ๐Ÿ™‚

Does this solution still require a non-zero timeout value?