A UI Razor component for a menu option. It renders an optional IconPanel and a Label, exposes Text, Icon, Value and Enabled parameters, updates a disabled CSS class when Enabled changes, and sets an active class each Tick if its Value matches the parent VerticalMenu'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 bool Enabled
{
get => field;
set
{
field = value;
SetClass( "disabled", !value );
}
} = true;
[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 );
}
}
}