Initial commit - Common.RCL
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
@using global::Common.Services
|
||||
@implements IDisposable
|
||||
@inject IToastService ToastService
|
||||
|
||||
<div class="toast toast-start toast-bottom fixed"
|
||||
style="bottom: 1rem !important; left: 1rem !important; top: auto !important; right: auto !important; z-index: 2147483647 !important;">
|
||||
@foreach (var toast in ToastService.Toasts)
|
||||
{
|
||||
<div
|
||||
class="alert @GetAlertClass(toast.Level) shadow-lg mb-2 flex justify-between items-center min-w-[300px] animate-in slide-in-from-bottom duration-300 @(toast.Level == ToastLevel.Error ? "bg-error text-error-content" : "")">
|
||||
<div class="flex items-center gap-2">
|
||||
@switch (toast.Level)
|
||||
{
|
||||
case ToastLevel.Success:
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="stroke-current shrink-0 h-6 w-6" fill="none"
|
||||
viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
|
||||
d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" />
|
||||
</svg>
|
||||
break;
|
||||
case ToastLevel.Error:
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="stroke-current shrink-0 h-6 w-6" fill="none"
|
||||
viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
|
||||
d="M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z" />
|
||||
</svg>
|
||||
break;
|
||||
case ToastLevel.Warning:
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="stroke-current shrink-0 h-6 w-6" fill="none"
|
||||
viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
|
||||
d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z" />
|
||||
</svg>
|
||||
break;
|
||||
default:
|
||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"
|
||||
class="stroke-current shrink-0 w-6 h-6">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
|
||||
d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path>
|
||||
</svg>
|
||||
break;
|
||||
}
|
||||
<span>@toast.Message</span>
|
||||
</div>
|
||||
<button class="btn btn-ghost btn-xs" @onclick="() => ToastService.RemoveToast(toast.Id)">✕</button>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
@code {
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
ToastService.OnChange += StateHasChanged;
|
||||
}
|
||||
|
||||
private string GetAlertClass(ToastLevel level) => level switch
|
||||
{
|
||||
ToastLevel.Success => "alert-success",
|
||||
ToastLevel.Error => "alert-error",
|
||||
ToastLevel.Warning => "alert-warning",
|
||||
_ => "alert-info"
|
||||
};
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
ToastService.OnChange -= StateHasChanged;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user