-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Jeffrey T. Fritz <csharpfritz@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
6495d82
commit f49ccfc
Showing
19 changed files
with
217 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace TagzApp.Blazor.Client.Bootstrap; | ||
|
||
public enum MessageSeverity | ||
{ | ||
Normal = 0, | ||
Info, | ||
Success, | ||
Warning, | ||
Danger | ||
} |
45 changes: 45 additions & 0 deletions
45
src/TagzApp.Blazor.Client/Bootstrap/MessageSeverityExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
namespace TagzApp.Blazor.Client.Bootstrap; | ||
|
||
public static class MessageSeverityExtensions | ||
{ | ||
|
||
public static string ToBackgroundColorCss(this MessageSeverity severity) | ||
=> severity switch | ||
{ | ||
MessageSeverity.Info => "bg-info", | ||
MessageSeverity.Success => "bg-success", | ||
MessageSeverity.Warning => "bg-warning", | ||
MessageSeverity.Danger => "bg-danger", | ||
_ => string.Empty | ||
}; | ||
|
||
public static string ToTextColorCss(this MessageSeverity severity) | ||
=> severity switch | ||
{ | ||
MessageSeverity.Info => "text-info", | ||
MessageSeverity.Success => "text-success", | ||
MessageSeverity.Warning => "text-warning", | ||
MessageSeverity.Danger => "text-danger", | ||
_ => string.Empty | ||
}; | ||
|
||
public static string ToHeaderText(this MessageSeverity severity) | ||
=> severity switch | ||
{ | ||
MessageSeverity.Info => "Info", | ||
MessageSeverity.Success => "Success", | ||
MessageSeverity.Danger => "Error", | ||
MessageSeverity.Warning => "Warning", | ||
_ => "Message" | ||
}; | ||
|
||
public static string ToHeaderIconCss(this MessageSeverity severity) | ||
=> severity switch | ||
{ | ||
MessageSeverity.Warning => "bi-exclamation-circle-fill", | ||
MessageSeverity.Danger => "bi-x-circle-fill", | ||
MessageSeverity.Success => "bi-check-circle-fill", | ||
MessageSeverity.Normal => "bi-envelope", | ||
_ => "bi-info-circle-fill", | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
@namespace TagzApp.Blazor.Client.Components | ||
@inject ToastService ToastService | ||
@implements IDisposable | ||
|
||
<div class="toast fade @_DisplayCssClass" role="alert" aria-live="assertive" aria-atomic="true" style="z-index: 999"> | ||
<div class="toast-header"> | ||
<i class="bi @Message.Severity.ToHeaderIconCss() @Message.Severity.ToTextColorCss() px-2"/> | ||
<strong class="me-auto">@Message.Severity.ToHeaderText()</strong> | ||
@* <small class="text-muted">just now</small> *@ | ||
<button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close" | ||
@onclick="@(() => ToastService.Remove(Message))"></button> | ||
</div> | ||
<div class="toast-body @Message.Severity.ToBackgroundColorCss() @BodyTextCss fw-bold"> | ||
@Message.Message | ||
</div> | ||
</div> | ||
|
||
@code { | ||
[Parameter] public ToastMessage Message { get; set; } | ||
|
||
private System.Timers.Timer _Timer; | ||
private System.Timers.Timer _DestroyTimer; | ||
private string _DisplayCssClass = "show"; | ||
|
||
private string BodyTextCss => Message.Severity == MessageSeverity.Normal | ||
? "text-white-50" | ||
: "text-black-50"; | ||
|
||
protected override void OnInitialized() | ||
{ | ||
base.OnInitialized(); | ||
_Timer = new(Message.Duration); | ||
_Timer.Elapsed += (_, _) => Destroy(); | ||
_Timer.AutoReset = false; | ||
_Timer.Enabled = true; | ||
} | ||
|
||
private void Destroy() | ||
{ | ||
ToastService.Remove(Message); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
_Timer?.Dispose(); | ||
_DestroyTimer?.Dispose(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
@inject ToastService ToastService | ||
@using TagzApp.Blazor.Client.Services | ||
@implements IDisposable | ||
@rendermode InteractiveAuto | ||
|
||
<div class="toast-container position-fixed top-0 end-0 p-3"> | ||
@foreach (var message in ToastService.Messages) | ||
{ | ||
<Toast Message="@message"/> | ||
} | ||
</div> | ||
|
||
@code { | ||
|
||
protected override void OnInitialized() | ||
{ | ||
base.OnInitialized(); | ||
|
||
ToastService.OnUpdate += Update; | ||
} | ||
|
||
private void Update() | ||
{ | ||
InvokeAsync(StateHasChanged); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
ToastService.OnUpdate -= StateHasChanged; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.