Added toast component
This commit is contained in:
parent
e2c77a2d0a
commit
b82187a799
35
Wave/Components/ToastComponent.razor
Normal file
35
Wave/Components/ToastComponent.razor
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
<div class="toast toast-start z-10" role="alert">
|
||||||
|
@foreach (var message in Messages) {
|
||||||
|
<div class="alert @message.Type" @onclick="() => Messages.Remove(message)">
|
||||||
|
@if (message.Title is null) {
|
||||||
|
@message.Body
|
||||||
|
} else {
|
||||||
|
<span class="font-bold">@message.Title</span>
|
||||||
|
<span><small>@message.Body</small></span>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@code {
|
||||||
|
private List<Message> Messages { get; } = [];
|
||||||
|
|
||||||
|
public void ShowInfo(string message, string? title = null) {
|
||||||
|
Messages.Add(new Message(message, "alert-info", title, DateTimeOffset.UtcNow));
|
||||||
|
StateHasChanged();
|
||||||
|
}
|
||||||
|
public void ShowSuccess(string message, string? title = null) {
|
||||||
|
Messages.Add(new Message(message, "alert-success", title, DateTimeOffset.UtcNow));
|
||||||
|
StateHasChanged();
|
||||||
|
}
|
||||||
|
public void ShowWarning(string message, string? title = null) {
|
||||||
|
Messages.Add(new Message(message, "alert-warning", title, DateTimeOffset.UtcNow));
|
||||||
|
StateHasChanged();
|
||||||
|
}
|
||||||
|
public void ShowError(string message, string? title = null) {
|
||||||
|
Messages.Add(new Message(message, "alert-error", title, DateTimeOffset.UtcNow));
|
||||||
|
StateHasChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
private sealed record Message(string Body, string Type, string? Title, DateTimeOffset Created);
|
||||||
|
}
|
Loading…
Reference in a new issue