Added toast component

This commit is contained in:
Mia Rose Winter 2024-01-16 17:35:30 +01:00
parent e2c77a2d0a
commit b82187a799
Signed by: miawinter
GPG key ID: 4B6F6A83178F595E

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