namespace MudBlazor; internal sealed class MudLinkButton : MudComponentBase { private string Classname => new CssBuilder("mud-typography mud-link") .AddClass($"mud-{Color.ToDescriptionString()}-text") .AddClass($"mud-link-underline-{Underline.ToDescriptionString()}") .AddClass($"mud-typography-{Typo.ToDescriptionString()}") .AddClass("mud-link-disabled", IsDisabled) .AddClass(Class) .Build(); /// /// The color of the component. It supports the theme colors. /// [Parameter] public Color Color { get; set; } = Color.Primary; /// /// Typography variant to use. /// [Parameter] public Typo Typo { get; set; } = Typo.body1; /// /// Controls when the link should have an underline. /// [Parameter] public Underline Underline { get; set; } = Underline.Hover; /// /// If true, the navlink will be disabled. /// [Parameter] public bool IsDisabled { get; set; } /// /// Child content of component. /// [Parameter] public RenderFragment? ChildContent { get; set; } /// /// Command executed on click /// [Parameter] public ICommand? Command { get; set; } /// /// Parameter passed to the command /// [Parameter] public object? CommandParameter { get; set; } protected override void BuildRenderTree(RenderTreeBuilder builder) { var i = 0; builder.OpenElement(i++, "span"); builder.AddAttribute(i++, "class", Classname); builder.AddAttribute(i++, "style", Style); builder.AddAttribute(i++, "onclick", EventCallback.Factory.Create(this, OnClick)); builder.AddContent(i++, ChildContent); builder.CloseElement(); } private void OnClick() { if (IsDisabled) return; if (Command?.CanExecute(CommandParameter) ?? false) Command.Execute(CommandParameter); } }