using System.Windows.Input; using Connected.Annotations; using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components.Web; namespace Connected.Components; public abstract class SelectItemBase : UIComponent { /// /// If true, the input element will be disabled. /// [Parameter] [Category(CategoryTypes.General.Behavior)] public bool Disabled { get; set; } /// /// If true, disables ripple effect. /// [Parameter] [Category(CategoryTypes.General.Appearance)] public bool DisableRipple { get; set; } /// /// Link to a URL when clicked. /// [Parameter] [Category(CategoryTypes.General.ClickAction)] public string Href { get; set; } /// /// If true, force browser to redirect outside component router-space. /// [Parameter] [Category(CategoryTypes.General.ClickAction)] public bool ForceLoad { get; set; } /// /// Child content of component. /// [Parameter] [Category(CategoryTypes.General.Behavior)] public RenderFragment ChildContent { get; set; } /// /// Command parameter. /// [Parameter] [Category(CategoryTypes.General.ClickAction)] public object CommandParameter { get; set; } /// /// Command executed when the user clicks on an element. /// [Parameter] [Category(CategoryTypes.General.ClickAction)] public ICommand Command { get; set; } [Inject] private NavigationManager UriHelper { get; set; } [Parameter] public EventCallback OnClick { get; set; } protected async Task OnClickHandler(MouseEventArgs ev) { if (Disabled) return; if (Href != null) { UriHelper.NavigateTo(Href, ForceLoad); } else { await OnClick.InvokeAsync(ev); if (Command?.CanExecute(CommandParameter) ?? false) { Command.Execute(CommandParameter); } } } }