|
|
|
@ -1,33 +1,32 @@
|
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
using Connected.Annotations;
|
|
|
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
|
using Microsoft.AspNetCore.Components.Web;
|
|
|
|
|
using static System.String;
|
|
|
|
|
|
|
|
|
|
namespace Connected.Components;
|
|
|
|
|
|
|
|
|
|
public abstract class ButtonBase : UIComponent
|
|
|
|
|
{
|
|
|
|
|
#region EventCallbacks
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Button click event.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Parameter]
|
|
|
|
|
public EventCallback<MouseEventArgs> OnClick { get; set; }
|
|
|
|
|
public EventCallback<MouseEventArgs> Clicked { get; set; }
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Content placeholders
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Potential activation target for this button. This enables RenderFragments with user-defined
|
|
|
|
|
/// buttons which will automatically activate the intended functionality.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[CascadingParameter]
|
|
|
|
|
protected IActivatable Activateable { get; set; }
|
|
|
|
|
protected IActivatable? Activateable { get; set; }
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The HTML element that will be rendered in the root by the component
|
|
|
|
|
/// By default, is a button
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Parameter]
|
|
|
|
|
public string HtmlTag { get; set; } = "button";
|
|
|
|
|
#region Styling properties
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Behavior properties
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The button Type (Button, Submit, Refresh)
|
|
|
|
|
/// </summary>
|
|
|
|
@ -35,49 +34,41 @@ public abstract class ButtonBase : UIComponent
|
|
|
|
|
public ButtonType ButtonType { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// If true, the button will be disabled.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Parameter]
|
|
|
|
|
public bool Disabled { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The higher the number, the heavier the drop-shadow. 0 for no shadow.
|
|
|
|
|
/// Command executed when the user clicks on an element.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Parameter]
|
|
|
|
|
public int Elevation { set; get; } = 0;
|
|
|
|
|
public ICommand? Command { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// If true, disables ripple effect.
|
|
|
|
|
/// Command parameter.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Parameter]
|
|
|
|
|
public bool CanRipple { get; set; }
|
|
|
|
|
public object? CommandParameters { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Command executed when the user clicks on an element.
|
|
|
|
|
/// If true, the button will be disabled.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Parameter]
|
|
|
|
|
public ICommand? Command { get; set; }
|
|
|
|
|
public bool Disabled { get; set; }
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Command parameter.
|
|
|
|
|
/// The HTML element that will be rendered in the root by the component
|
|
|
|
|
/// By default, is a button
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Parameter]
|
|
|
|
|
public object? CommandParameters { get; set; }
|
|
|
|
|
protected string HtmlTag => ButtonType.ToString().ToLower();
|
|
|
|
|
|
|
|
|
|
protected async Task OnClickHandler(MouseEventArgs e)
|
|
|
|
|
protected async Task OnClick(MouseEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (Disabled)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
await OnClick.InvokeAsync(e);
|
|
|
|
|
if (Clicked.HasDelegate)
|
|
|
|
|
await Clicked.InvokeAsync(e);
|
|
|
|
|
|
|
|
|
|
if (Command?.CanExecute(CommandParameters) ?? false)
|
|
|
|
|
Command.Execute(CommandParameters);
|
|
|
|
|
|
|
|
|
|
Activateable?.Activate(this, e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected ElementReference _elementReference;
|
|
|
|
|
|
|
|
|
|
public ValueTask FocusAsync() => _elementReference.FocusAsync();
|
|
|
|
|
}
|
|
|
|
|