Updates
This commit is contained in:
1 parent
9faa49daa1
commit
08eefe2973
20 files changed
+572
-142
No files matched your search
@@ -0,0 +1,51 @@
|
||||
@inject ToastService ToastService
|
||||
@implements IDisposable
|
||||
@rendermode InteractiveServer
|
||||
|
||||
<div class="toast-stack">
|
||||
@foreach (var toast in toasts)
|
||||
{
|
||||
<div class="toast-item @(toast.Dismissing ? "toast-dismiss" : "")">
|
||||
<span class="toast-icon">⚠</span>
|
||||
<span class="toast-message">@toast.Message</span>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
@code {
|
||||
private readonly List<ToastItem> toasts = [];
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
ToastService.OnShow += ShowToast;
|
||||
}
|
||||
|
||||
private async void ShowToast(string message)
|
||||
{
|
||||
var toast = new ToastItem { Message = message };
|
||||
toasts.Add(toast);
|
||||
await InvokeAsync(StateHasChanged);
|
||||
_ = DismissAfterDelay(toast);
|
||||
}
|
||||
|
||||
private async Task DismissAfterDelay(ToastItem toast)
|
||||
{
|
||||
await Task.Delay(3500);
|
||||
toast.Dismissing = true;
|
||||
await InvokeAsync(StateHasChanged);
|
||||
await Task.Delay(300);
|
||||
toasts.Remove(toast);
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
ToastService.OnShow -= ShowToast;
|
||||
}
|
||||
|
||||
private sealed class ToastItem
|
||||
{
|
||||
public string Message { get; set; } = "";
|
||||
public bool Dismissing { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user