|
|
|
|
using Connected.Annotations;
|
|
|
|
|
using Connected.Utilities;
|
|
|
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
|
using Microsoft.AspNetCore.Components.Routing;
|
|
|
|
|
|
|
|
|
|
namespace Connected.Components;
|
|
|
|
|
|
|
|
|
|
public partial class NavLink : SelectItemBase
|
|
|
|
|
{
|
|
|
|
|
protected string Classname =>
|
|
|
|
|
new CssBuilder("mud-nav-item")
|
|
|
|
|
.AddClass($"mud-ripple", !DisableRipple && !Disabled)
|
|
|
|
|
.AddClass(Class)
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
protected string LinkClassname =>
|
|
|
|
|
new CssBuilder("mud-nav-link")
|
|
|
|
|
.AddClass($"mud-nav-link-disabled", Disabled)
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
protected string IconClassname =>
|
|
|
|
|
new CssBuilder("mud-nav-link-icon")
|
|
|
|
|
.AddClass($"mud-nav-link-icon-default", IconColor == ThemeColor.Default)
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
protected Dictionary<string, object> Attributes
|
|
|
|
|
{
|
|
|
|
|
get => Disabled ? null : new Dictionary<string, object>()
|
|
|
|
|
{
|
|
|
|
|
{ "href", Href },
|
|
|
|
|
{ "target", Target },
|
|
|
|
|
{ "rel", !string.IsNullOrWhiteSpace(Target) ? "noopener noreferrer" : string.Empty }
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Icon to use if set.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Parameter]
|
|
|
|
|
[Category(CategoryTypes.NavMenu.Behavior)]
|
|
|
|
|
public string Icon { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The color of the icon. It supports the theme colors, default value uses the themes drawer icon color.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Parameter]
|
|
|
|
|
[Category(CategoryTypes.NavMenu.Appearance)]
|
|
|
|
|
public ThemeColor IconColor { get; set; } = ThemeColor.Default;
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
[Category(CategoryTypes.NavMenu.Behavior)]
|
|
|
|
|
public NavLinkMatch Match { get; set; } = NavLinkMatch.Prefix;
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
[Category(CategoryTypes.NavMenu.ClickAction)]
|
|
|
|
|
public string Target { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// User class names when active, separated by space.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Parameter]
|
|
|
|
|
[Category(CategoryTypes.ComponentBase.Common)]
|
|
|
|
|
public string ActiveClass { get; set; } = "active";
|
|
|
|
|
|
|
|
|
|
[CascadingParameter] INavigationEventReceiver NavigationEventReceiver { get; set; }
|
|
|
|
|
|
|
|
|
|
protected Task HandleNavigation()
|
|
|
|
|
{
|
|
|
|
|
if (!Disabled && NavigationEventReceiver != null)
|
|
|
|
|
{
|
|
|
|
|
return NavigationEventReceiver.OnNavigation();
|
|
|
|
|
}
|
|
|
|
|
return Task.CompletedTask;
|
|
|
|
|
}
|
|
|
|
|
}
|