Files
sbox-public/game/addons/base/code/UI/Components/NavLinkPanel.cs
s&box team 71f266059a Open source release
This commit imports the C# engine code and game files, excluding C++ source code.

[Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
2025-11-24 09:05:18 +00:00

40 lines
786 B
C#

namespace Sandbox.UI.Navigation;
/// <summary>
/// A panel that will navigate to an href but also have .active class if href is active
/// </summary>
[ClassName( "a" )]
[Alias( "navlink" )]
public class NavLinkPanel : Panel
{
NavigationHost Navigator;
public string HRef { get; set; }
public string Match { get; set; }
public override void OnParentChanged()
{
base.OnParentChanged();
Navigator = Ancestors.OfType<NavigationHost>().FirstOrDefault();
}
protected override void OnClick( MousePanelEvent e )
{
if ( e.Button == "mouseleft" )
{
this.Navigate( HRef );
}
}
public override void Tick()
{
base.Tick();
if ( HRef == null )
return;
var active = Navigator?.CurrentUrlMatches( Match ?? HRef ) ?? false;
SetClass( "active", active );
}
}