A UI Razor component for a menu option. Renders an optional IconPanel and a Label, exposes Text, Icon, and Value parameters, and on Tick checks its ancestor VerticalMenu to set an "active" CSS class when the menu's selected value equals this option's Value.
@using Sandbox;
@using Sandbox.UI;
@inherits Panel
@namespace Sandbox
<root>
@if ( !string.IsNullOrWhiteSpace( Icon ) )
{
<IconPanel Text="@Icon"></IconPanel>
}
<Label Text="@Text"></Label>
</root>
@code
{
[Parameter, EditorRequired]
public string Text { get; set; }
[Parameter]
public string Icon { get; set; }
[Parameter]
public object Value { get; set; }
public override void Tick()
{
base.Tick();
if ( Value is null )
return;
var menu = Ancestors.OfType<VerticalMenu>().FirstOrDefault();
if (menu is not null)
{
SetClass( "active", menu.Value == Value );
}
}
}