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 Request] Timeout Per Level #96

Closed scottkuhl closed 2 years ago

scottkuhl commented 3 years ago

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);

chrissainty commented 3 years ago

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.

dchupp commented 3 years ago

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.

chrissainty commented 3 years ago

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

titobf commented 3 years ago

This feature would be a great addition

LaurenceFrost commented 2 years ago

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 :)

chrissainty commented 2 years ago

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

LaurenceFrost commented 2 years ago

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.

chrissainty commented 2 years ago

Thanks, @LaurenceFrost. Glad you got it all working 🙂

HolisticDeveloper commented 2 years ago

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