Files
decePubClient/Components/Daisy/Actions/DButton.razor
T

77 lines
2.4 KiB
Plaintext
Raw Normal View History

@inherits DComponentBase
@* daisyUI Button: https://daisyui.com/components/button/ . Renders an <a> when Href is set. *@
@if (Href is null)
{
<button @attributes="AdditionalAttributes" type="@Type" class="@CssClass" disabled="@Disabled" @onclick="OnClick"
@onmousedown:preventDefault="KeepFocus">
@ChildContent
</button>
}
else
{
<a @attributes="AdditionalAttributes" href="@(Disabled ? null : Href)" class="@CssClass" role="button"
aria-disabled="@(Disabled ? "true" : null)" tabindex="@(Disabled ? "-1" : null)" @onclick="OnClick">
@ChildContent
</a>
}
@code {
[Parameter] public RenderFragment ChildContent { get; set; }
[Parameter] public DColor Color { get; set; }
[Parameter] public DButtonVariant Variant { get; set; }
[Parameter] public DSize Size { get; set; }
[Parameter] public DButtonShape Shape { get; set; }
/// <summary>Pressed look (btn-active); the neo theme renders it inset.</summary>
[Parameter] public bool Active { get; set; }
[Parameter] public bool Disabled { get; set; }
[Parameter] public string Type { get; set; } = "button";
[Parameter] public string Href { get; set; }
[Parameter] public EventCallback<MouseEventArgs> OnClick { get; set; }
/// <summary>Pressing it doesn't take the focus from where it is (a chip that writes into a focused textarea).</summary>
[Parameter] public bool KeepFocus { get; set; }
string CssClass => Cx("btn", ColorClass, VariantClass, SizeClass, ShapeClass,
Active ? "btn-active" : null, Disabled && Href is not null ? "btn-disabled" : null, Class);
string ColorClass => Color switch
{
DColor.Neutral => "btn-neutral",
DColor.Primary => "btn-primary",
DColor.Secondary => "btn-secondary",
DColor.Accent => "btn-accent",
DColor.Info => "btn-info",
DColor.Success => "btn-success",
DColor.Warning => "btn-warning",
DColor.Error => "btn-error",
_ => null
};
string VariantClass => Variant switch
{
DButtonVariant.Outline => "btn-outline",
DButtonVariant.Dash => "btn-dash",
DButtonVariant.Soft => "btn-soft",
DButtonVariant.Ghost => "btn-ghost",
DButtonVariant.Link => "btn-link",
_ => null
};
string SizeClass => Size switch
{
DSize.Xs => "btn-xs",
DSize.Sm => "btn-sm",
DSize.Lg => "btn-lg",
DSize.Xl => "btn-xl",
_ => null
};
string ShapeClass => Shape switch
{
DButtonShape.Wide => "btn-wide",
DButtonShape.Block => "btn-block",
DButtonShape.Square => "btn-square",
DButtonShape.Circle => "btn-circle",
_ => null
};
}