NejBlazor/Parts/ButtonParts/ButtonBase.razor
2023-03-08 17:00:38 +01:00

66 lines
1.4 KiB
Plaintext

@using Microsoft.AspNetCore.Components.Web;
@using Nejcraft.Shared.Parts
@inherits NejComponentBase
<button @onclick="(x)=>OnClick.InvokeAsync(x)"
class="@Color @HoverColor @DisabledColor
m-2 outline-none focus:outline-none text-primary font-bold ease-linear transition-all duration-150 @GetCssClass()"
type="@HtmlButtonType">
@ChildContent
</button>
@code {
[Parameter]
public RenderFragment ChildContent { get; set; } = default!;
public enum ButtonType {
Normal,
Submit,
Danger
}
public static Dictionary<ButtonType, Colors.ColorType> ColorMap = new Dictionary<ButtonType, Colors.ColorType>(){
{ ButtonType.Submit, Colors.ColorType.Accent },
{ ButtonType.Danger, Colors.ColorType.Error }
};
string Color {
get {
if (!ColorMap.TryGetValue(Type, out Colors.ColorType col))
return "bg-secondary";
return Colors.BgColors[col];
}
}
string HoverColor
{
get
{
if (!ColorMap.TryGetValue(Type, out Colors.ColorType col))
return "hover:bg-trinary";
return Colors.BgColorsHover[col];
}
}
string DisabledColor
{
get
{
if (!ColorMap.TryGetValue(Type, out Colors.ColorType col))
return "disabled:bg-trinary";
return Colors.BgColorsDisabled[col];
}
}
[Parameter]
public ButtonType Type { get; set; }
[Parameter]
public string? HtmlButtonType { get; set; } = "button";
[Parameter]
public EventCallback<MouseEventArgs?> OnClick { get; set; }
}