Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Commit

Permalink
allow the toast auto hide to be disabled setting the VisibleStepDurat…
Browse files Browse the repository at this point in the history
…ion = 0
  • Loading branch information
ghidello committed Aug 15, 2018
1 parent 44a97c6 commit 27c1db4
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 5 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ The transitions are implemented using `System.Threading.Timer` instances (at lea

## Changes

- version 0.5.3
- Setting **VisibleStepDuration** to zero disables the toast auto fade out

- version 0.5.2
- upgraded to blazor 0.5.1

Expand Down
5 changes: 5 additions & 0 deletions global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"sdk": {
"version": "2.1.300"
}
}
2 changes: 1 addition & 1 deletion src/Sample/Shared/NavMenu.cshtml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="top-row pl-4 navbar navbar-dark">
<a class="navbar-brand" href="">Toaster (0.5.2)</a>
<a class="navbar-brand" href="">Toaster (0.5.3)</a>
<button class="navbar-toggler" onclick=@ToggleNavMenu>
<span class="navbar-toggler-icon"></span>
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public abstract class CommonToastOptions
public int ShowStepDuration { get; set; } = 100;

/// <summary>
/// How long the toast remain visible without user interaction. Defaults to 5000 ms.
/// How long the toast remain visible without user interaction. A value of 0 disables the auto hide and forces the user to interact with the toast. Defaults to 5000 ms.
/// </summary>
public int VisibleStateDuration { get; set; } = 5000;

Expand Down
12 changes: 9 additions & 3 deletions src/Sotsera.Blazor.Toaster/Core/Toast.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ namespace Sotsera.Blazor.Toaster.Core
/// </summary>
public class Toast : IDisposable
{
public ToastState State { get; set; }
private Opacity Opacity { get; set; }
public decimal TransitionPercentage { get; set; }
private bool UserHasInteracted { get; set; }
private bool RequiresInteraction => Options.VisibleStateDuration == 0;

private TransitionTimer Timer { get; }
public ToastState State { get; set; }
private Opacity Opacity { get; set; }

public ToastOptions Options { get; }
public string Title { get; }
Expand Down Expand Up @@ -64,6 +67,7 @@ private void TimerElapsed(decimal transitionPercentage)
public void MouseLeave()
{
if (State == ToastState.Hiding) return;
if (RequiresInteraction && !UserHasInteracted) return;
TransitionTo(ToastState.Hiding);
}

Expand All @@ -73,6 +77,7 @@ public void Clicked(bool fromCloseIcon)

if (fromCloseIcon || !Options.ShowCloseIcon)
{
UserHasInteracted = true;
TransitionTo(ToastState.Hiding);
}
}
Expand All @@ -96,7 +101,8 @@ private void TransitionTo(ToastState state)
break;
case ToastState.Visible:
ResetPercentage(100);
if (Options.VisibleStateDuration <= 0) TransitionTo(ToastState.Hiding);
if (RequiresInteraction) break;
if (Options.VisibleStateDuration < 0) TransitionTo(ToastState.Hiding);
else if (Options.ShowProgressBar) Timer.Start(Options.VisibleStateDuration, Options.ProgressBarStepDuration);
else Timer.Start(Options.VisibleStateDuration);
break;
Expand Down

0 comments on commit 27c1db4

Please sign in to comment.