BlazorStart/Start/Client/Components/Shared/Alert.razor

50 lines
1.2 KiB
Plaintext
Raw Permalink Normal View History

2021-12-17 06:16:30 +00:00
<div class="toast @this.AlertTypeToClass(this.Type)" role="alert">
@this.AlertTypeToTitle(this.Type)
@ChildContent
</div>
@code {
[Parameter]
public AlertType Type { get; set; }
[Parameter]
public RenderFragment ChildContent { get; set; } = null!;
private string AlertTypeToClass(AlertType type)
{
switch (type)
{
case AlertType.Error: return "toast-error";
case AlertType.Warning: return "toast-warning";
case AlertType.Success: return "toast-success";
case AlertType.Info: return "toast-primary";
default: return "";
}
}
2021-12-17 06:16:30 +00:00
private RenderFragment? AlertTypeToTitle(AlertType type)
{
switch (type)
{
case AlertType.Error:
return @<b>Error</b>;
case AlertType.Warning:
return @<b>Warning</b>;
case AlertType.Success:
return @<b>Success</b>;
case AlertType.Info:
return @<b>Info</b>;
default:
return null;
}
}
public enum AlertType
{
Error,
Warning,
Success,
Info,
None
}
}