Files
decePubClient/Components/ToastHost.razor
T

42 lines
1.3 KiB
Plaintext
Raw Normal View History

@implements IDisposable
@* Shows ToastService's messages at the bottom end of the screen. Placed once, in MainLayout. *@
@if (Toast.Messages.Count > 0)
{
@* (on a phone above the round New post button) *@
<DToast class="z-[1000] max-md:bottom-20">
@foreach (var message in Toast.Messages)
{
<DAlert @key="message.Id" Color="ColorOf(message.Severity)" class="max-w-sm">
<ChildContent>
<span class="break-words">@message.Text</span>
</ChildContent>
<Actions>
<DButton Size="DSize.Xs" Shape="DButtonShape.Circle" Variant="DButtonVariant.Ghost" aria-label="@Localizer["Close"]"
OnClick="() => Toast.Close(message.Id)">
<i class="ion-md-close"></i>
</DButton>
</Actions>
</DAlert>
}
</DToast>
}
@code {
[Inject] ToastService Toast { get; set; }
[Inject] CoalescingStringLocalizer Localizer { get; set; }
protected override void OnInitialized() => Toast.Changed += OnChanged;
void OnChanged() => _ = InvokeAsync(StateHasChanged);
static DAlertColor ColorOf(ToastSeverity severity) => severity switch
{
ToastSeverity.Success => DAlertColor.Success,
ToastSeverity.Warning => DAlertColor.Warning,
ToastSeverity.Error => DAlertColor.Error,
_ => DAlertColor.Info
};
public void Dispose() => Toast.Changed -= OnChanged;
}