using System.Windows.Input; using Connected.Annotations; using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components.Web; namespace Connected.Components; public partial class MenuItem : UIComponent { [CascadingParameter] public Menu Menu { get; set; } [Parameter][Category(CategoryTypes.Menu.Behavior)] public RenderFragment ChildContent { get; set; } [Parameter][Category(CategoryTypes.Menu.Behavior)] public bool Disabled { get; set; } [Inject] public NavigationManager UriHelper { get; set; } [Inject] public IJsApiService JsApiService { get; set; } /// /// If set to a URL, clicking the button will open the referenced document. Use Target to specify where (Obsolete replaced by Href) /// [Obsolete("Use Href Instead.", false)] [Parameter] [Category(CategoryTypes.Menu.ClickAction)] public string Link { get => Href; set => Href = value; } /// /// If set to a URL, clicking the button will open the referenced document. Use Target to specify where /// [Parameter] [Category(CategoryTypes.Menu.ClickAction)] public string Href { get; set; } /// /// Icon to be used for this menu entry /// [Parameter] [Category(CategoryTypes.List.Behavior)] public string Icon { get; set; } /// /// The color of the icon. It supports the theme colors. /// [Parameter] [Category(CategoryTypes.List.Appearance)] public ThemeColor IconColor { get; set; } = ThemeColor.Inherit; /// /// The Icon Size. /// [Parameter] [Category(CategoryTypes.List.Appearance)] public Size IconSize { get; set; } = Size.Medium; [Parameter][Category(CategoryTypes.Menu.ClickAction)] public string Target { get; set; } [Parameter][Category(CategoryTypes.Menu.ClickAction)] public bool ForceLoad { get; set; } [Parameter][Category(CategoryTypes.Menu.ClickAction)] public ICommand Command { get; set; } [Parameter][Category(CategoryTypes.Menu.ClickAction)] public object CommandParameter { get; set; } [Parameter] public EventCallback OnClick { get; set; } [Parameter] public EventCallback OnTouch { get; set; } protected async Task OnClickHandler(MouseEventArgs ev) { if (Disabled) return; Menu.CloseMenu(); if (Href != null) { if (string.IsNullOrWhiteSpace(Target)) UriHelper.NavigateTo(Href, ForceLoad); else await JsApiService.Open(Href, Target); } else { await OnClick.InvokeAsync(ev); if (Command?.CanExecute(CommandParameter) ?? false) { Command.Execute(CommandParameter); } } } protected internal async Task OnTouchHandler(TouchEventArgs ev) { if (Disabled) return; Menu.CloseMenu(); if (Href != null) { if (string.IsNullOrWhiteSpace(Target)) UriHelper.NavigateTo(Href, ForceLoad); else await JsApiService.Open(Href, Target); } else { await OnTouch.InvokeAsync(ev); if (Command?.CanExecute(CommandParameter) ?? false) { Command.Execute(CommandParameter); } } } }