41 lines
1.2 KiB
Plaintext
41 lines
1.2 KiB
Plaintext
@implements IDisposable
|
|||
|
|
|
||
|
|
@* Shows ToastService's messages at the bottom end of the screen. Placed once, in MainLayout. *@
|
||
|
|
@if (Toast.Messages.Count > 0)
|
||
|
|
{
|
||
|
|
<DToast class="z-[1000]">
|
||
|
|
@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;
|
||
|
|
}
|