using Connected.Annotations; using Connected.Extensions; using Connected.Utilities; using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components.Web; namespace Connected.Components; public partial class Link : UIComponent { protected string Classname => new CssBuilder("mud-typography mud-link") .AddClass($"mud-{Color.ToDescriptionString()}-text") .AddClass($"mud-link-underline-{Underline.ToDescriptionString()}") .AddClass($"mud-typography-{Typo.ToDescriptionString()}") // When Href is empty, link's hover cursor is text "I beam" even when OnClick has a delegate. // To change this for more expected look change hover cursor to a pointer: .AddClass("cursor-pointer", Href == default && OnClick.HasDelegate && !Disabled) .AddClass($"mud-link-disabled", Disabled) .AddClass(Class) .Build(); private Dictionary Attributes { get => Disabled ? UserAttributes : new Dictionary(UserAttributes) { { "href", Href }, { "target", Target } }; } /// /// The color of the component. It supports the theme colors. /// [Parameter] [Category(CategoryTypes.Link.Appearance)] public ThemeColor Color { get; set; } = ThemeColor.Primary; /// /// Typography variant to use. /// [Parameter] [Category(CategoryTypes.Link.Appearance)] public Typo Typo { get; set; } = Typo.body1; /// /// Controls when the link should have an underline. /// [Parameter] [Category(CategoryTypes.Link.Appearance)] public Underline Underline { get; set; } = Underline.Hover; /// /// The URL, which is the actual link. /// [Parameter] [Category(CategoryTypes.Link.Behavior)] public string Href { get; set; } /// /// The target attribute specifies where to open the link, if Link is specified. Possible values: _blank | _self | _parent | _top | framename /// [Parameter] [Category(CategoryTypes.Link.Behavior)] public string Target { get; set; } /// /// Link click event. /// [Parameter] public EventCallback OnClick { get; set; } protected async Task OnClickHandler(MouseEventArgs ev) { if (Disabled) return; await OnClick.InvokeAsync(ev); } /// /// Child content of component. /// [Parameter] [Category(CategoryTypes.Link.Behavior)] public RenderFragment ChildContent { get; set; } /// /// If true, the navlink will be disabled. /// [Parameter] [Category(CategoryTypes.Link.Behavior)] public bool Disabled { get; set; } }