Wave/Wave/Components/Alert.razor

64 lines
3.2 KiB
Plaintext

@using System.Globalization
<div class="alert @GetClass shadow" role="alert">
<div>
@* ReSharper disable once SwitchStatementMissingSomeEnumCasesNoDefault *@
@switch (Type) {
case MessageType.Information:
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6">
<path stroke-linecap="round" stroke-linejoin="round" d="m11.25 11.25.041-.02a.75.75 0 0 1 1.063.852l-.708 2.836a.75.75 0 0 0 1.063.853l.041-.021M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0Zm-9-3.75h.008v.008H12V8.25Z" />
</svg>
break;
case MessageType.Success:
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6">
<path stroke-linecap="round" stroke-linejoin="round" d="M9 12.75 11.25 15 15 9.75M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z" />
</svg>
break;
case MessageType.Warning:
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6">
<path stroke-linecap="round" stroke-linejoin="round" d="M12 9v3.75m-9.303 3.376c-.866 1.5.217 3.374 1.948 3.374h14.71c1.73 0 2.813-1.874 1.948-3.374L13.949 3.378c-.866-1.5-3.032-1.5-3.898 0L2.697 16.126ZM12 15.75h.007v.008H12v-.008Z" />
</svg>
break;
case MessageType.Error:
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6">
<path stroke-linecap="round" stroke-linejoin="round" d="M12 9v3.75m0-10.036A11.959 11.959 0 0 1 3.598 6 11.99 11.99 0 0 0 3 9.75c0 5.592 3.824 10.29 9 11.622 5.176-1.332 9-6.03 9-11.622 0-1.31-.21-2.57-.598-3.75h-.152c-3.196 0-6.1-1.25-8.25-3.286Zm0 13.036h.008v.008H12v-.008Z" />
</svg>
break;
}
</div>
<div class="w-full hyphens-auto text-justify" lang="@CultureInfo.CurrentCulture">
@ChildContent
</div>
@if (CanRemove) {
<button class="btn btn-sm btn-square btn-ghost" onclick="this.parentElement.remove();">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6">
<path stroke-linecap="round" stroke-linejoin="round" d="M6 18 18 6M6 6l12 12"/>
</svg>
</button>
} else {
<div> </div>
}
</div>
@code {
[Parameter]
public required RenderFragment ChildContent { get; set; }
[Parameter]
public MessageType Type { get; set; } = MessageType.None;
[Parameter]
public bool CanRemove { get; set; } = true;
private string GetClass => Type switch {
MessageType.None => string.Empty,
MessageType.Information => "alert-info",
MessageType.Success => "alert-success",
MessageType.Warning => "alert-warning",
MessageType.Error => "alert-error",
_ => throw new ArgumentOutOfRangeException()
};
public enum MessageType {
None, Information, Success, Warning, Error
}
}