|
|
@ -5,45 +5,36 @@ using Microsoft.AspNetCore.Components.Web;
|
|
|
|
using System.Numerics;
|
|
|
|
using System.Numerics;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Connected.Components;
|
|
|
|
namespace Connected.Components;
|
|
|
|
public partial class NumberInput<NumberType>:InputBase where NumberType : INumber<NumberType>
|
|
|
|
public partial class NumberInput<NumberType> : InputBase where NumberType : INumber<NumberType>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
private double _step =1;
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
[Parameter]
|
|
|
|
public double Step {
|
|
|
|
public double Step { get; set; } = 1;
|
|
|
|
get
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return _step;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
set
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_step=value;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
[Parameter]
|
|
|
|
public bool DisableMouseWheel
|
|
|
|
public bool DisableMouseWheel { get; set; } = false;
|
|
|
|
{
|
|
|
|
|
|
|
|
get;
|
|
|
|
|
|
|
|
set;
|
|
|
|
|
|
|
|
} = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private async Task StepUp()
|
|
|
|
private async Task StepUp()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
double num = (double)Convert.ChangeType(Value, typeof(double));
|
|
|
|
var num = (double)Convert.ChangeType(Value, typeof(double));
|
|
|
|
num += _step;
|
|
|
|
|
|
|
|
|
|
|
|
num += Step;
|
|
|
|
|
|
|
|
|
|
|
|
if (DecimalPlaces > 0)
|
|
|
|
if (DecimalPlaces > 0)
|
|
|
|
num = Math.Round(num, DecimalPlaces);
|
|
|
|
num = Math.Round(num, DecimalPlaces);
|
|
|
|
|
|
|
|
|
|
|
|
Value = (NumberType)Convert.ChangeType(num, typeof(NumberType));
|
|
|
|
Value = (NumberType)Convert.ChangeType(num, typeof(NumberType));
|
|
|
|
if (IsError) ErrorText = string.Empty;
|
|
|
|
|
|
|
|
|
|
|
|
if (IsError)
|
|
|
|
|
|
|
|
ErrorText = string.Empty;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch
|
|
|
|
catch
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ErrorText = "Error with step up!";
|
|
|
|
ErrorText = "Error with step up!";
|
|
|
|
Value = default(NumberType);
|
|
|
|
Value = default;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
await ValueChanged.InvokeAsync(Value);
|
|
|
|
await ValueChanged.InvokeAsync(Value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -51,96 +42,101 @@ public partial class NumberInput<NumberType>:InputBase where NumberType : INumbe
|
|
|
|
{
|
|
|
|
{
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
double num = (double)Convert.ChangeType(Value, typeof(double));
|
|
|
|
var num = (double)Convert.ChangeType(Value, typeof(double));
|
|
|
|
|
|
|
|
|
|
|
|
num -= _step;
|
|
|
|
num -= Step;
|
|
|
|
|
|
|
|
|
|
|
|
if (DecimalPlaces > 0)
|
|
|
|
if (DecimalPlaces > 0)
|
|
|
|
num = Math.Round(num, DecimalPlaces);
|
|
|
|
num = Math.Round(num, DecimalPlaces);
|
|
|
|
|
|
|
|
|
|
|
|
Value = (NumberType)Convert.ChangeType(num, typeof(NumberType));
|
|
|
|
Value = (NumberType)Convert.ChangeType(num, typeof(NumberType));
|
|
|
|
if (IsError) ErrorText = string.Empty;
|
|
|
|
|
|
|
|
} catch
|
|
|
|
if (IsError)
|
|
|
|
|
|
|
|
ErrorText = string.Empty;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ErrorText = "Error with step down!";
|
|
|
|
ErrorText = "Error with step down!";
|
|
|
|
Value = default(NumberType);
|
|
|
|
Value = default;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
await ValueChanged.InvokeAsync(Value);
|
|
|
|
await ValueChanged.InvokeAsync(Value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
protected async Task OnMouseWheel(WheelEventArgs args)
|
|
|
|
protected async Task OnMouseWheel(WheelEventArgs args)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (DisableMouseWheel == false)
|
|
|
|
if (DisableMouseWheel)
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (args.ShiftKey || Disabled || Readonly)
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (args.DeltaY >= 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (args.ShiftKey || Disabled || Readonly)
|
|
|
|
await StepDown();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (args.DeltaY >= 0)
|
|
|
|
else
|
|
|
|
{
|
|
|
|
|
|
|
|
await StepDown();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
await StepUp();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
await StepUp();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private string _value;
|
|
|
|
private string? _value;
|
|
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
[Parameter]
|
|
|
|
public NumberType? Value
|
|
|
|
public NumberType? Value
|
|
|
|
{
|
|
|
|
{
|
|
|
|
get
|
|
|
|
get
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (string.IsNullOrEmpty(_value)) return default(NumberType);
|
|
|
|
if (string.IsNullOrEmpty(_value))
|
|
|
|
|
|
|
|
return default;
|
|
|
|
|
|
|
|
|
|
|
|
return (NumberType)Convert.ChangeType(_value, typeof(NumberType));
|
|
|
|
return (NumberType)Convert.ChangeType(_value, typeof(NumberType));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
set
|
|
|
|
set
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_value = value.ToString();
|
|
|
|
_value = value?.ToString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
[Parameter]
|
|
|
|
public int DecimalPlaces { get; set; } =0;
|
|
|
|
public int DecimalPlaces { get; set; } = 0;
|
|
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
[Parameter]
|
|
|
|
public EventCallback<NumberType> ValueChanged { get; set; }
|
|
|
|
public EventCallback<NumberType> ValueChanged { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
public async Task GetValueAsync(ChangeEventArgs args)
|
|
|
|
public async Task GetValueAsync(ChangeEventArgs args)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (args.Value is not null)
|
|
|
|
if (args.Value is not null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
string newVal = args.Value.ToString();
|
|
|
|
var newVal = args.Value.ToString()!;
|
|
|
|
|
|
|
|
|
|
|
|
if (!newVal.Equals("0"))
|
|
|
|
if (!newVal.Equals("0"))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (newVal.ToString().Contains("-"))
|
|
|
|
if (newVal.ToString().Contains("-"))
|
|
|
|
newVal = "-" + newVal.ToString().Replace("-", "");
|
|
|
|
newVal = "-" + newVal.ToString().Replace("-", "");
|
|
|
|
|
|
|
|
|
|
|
|
if (newVal.ToString().ToLower().Contains("e"))
|
|
|
|
if (newVal.ToString().ToLower().Contains("e"))
|
|
|
|
newVal = "e" + newVal.ToString().Replace("e", "");
|
|
|
|
newVal = "e" + newVal.ToString().Replace("e", "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(newVal))
|
|
|
|
if (string.IsNullOrEmpty(newVal))
|
|
|
|
{
|
|
|
|
await ValueChanged.InvokeAsync(default);
|
|
|
|
await ValueChanged.InvokeAsync((NumberType)Convert.ChangeType((NumberType)Convert.ChangeType(null, typeof(NumberType)), typeof(NumberType)));
|
|
|
|
|
|
|
|
}
|
|
|
|
if (!newVal.Equals(_value))
|
|
|
|
else
|
|
|
|
await ValueChanged.InvokeAsync((NumberType)Convert.ChangeType(newVal, typeof(NumberType)));
|
|
|
|
{
|
|
|
|
|
|
|
|
if (!newVal.Equals(_value))
|
|
|
|
|
|
|
|
await ValueChanged.InvokeAsync((NumberType)Convert.ChangeType((NumberType)Convert.ChangeType(newVal, typeof(NumberType)), typeof(NumberType)));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task Change(ChangeEventArgs args)
|
|
|
|
public async Task Change(ChangeEventArgs args)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (args.Value is not null)
|
|
|
|
if (args.Value is not null)
|
|
|
|
{
|
|
|
|
|
|
|
|
Value = AdjustDecimalPlaces((NumberType)Convert.ChangeType(args.Value, typeof(NumberType)));
|
|
|
|
Value = AdjustDecimalPlaces((NumberType)Convert.ChangeType(args.Value, typeof(NumberType)));
|
|
|
|
}
|
|
|
|
|
|
|
|
ValueChanged.InvokeAsync(Value);
|
|
|
|
await ValueChanged.InvokeAsync(Value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Parameter] public EventCallback<KeyboardEventArgs> OnKeyDown { get; set; }
|
|
|
|
[Parameter]
|
|
|
|
|
|
|
|
public EventCallback<KeyboardEventArgs> OnKeyDown { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
private bool CheckKey(string key)
|
|
|
|
private bool CheckKey(string key)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -159,7 +155,7 @@ public partial class NumberInput<NumberType>:InputBase where NumberType : INumbe
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
{
|
|
|
|
result = false;
|
|
|
|
result = false;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -172,17 +168,19 @@ public partial class NumberInput<NumberType>:InputBase where NumberType : INumbe
|
|
|
|
private bool _preventDefaultAction = true;
|
|
|
|
private bool _preventDefaultAction = true;
|
|
|
|
public async Task ChangeValue(KeyboardEventArgs args)
|
|
|
|
public async Task ChangeValue(KeyboardEventArgs args)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_preventDefaultAction= true;
|
|
|
|
_preventDefaultAction = true;
|
|
|
|
if (args is not null)
|
|
|
|
if (args is not null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var key = args.Key.ToString().ToLower();
|
|
|
|
var key = args.Key.ToString().ToLower();
|
|
|
|
|
|
|
|
|
|
|
|
if (CheckKey(key))
|
|
|
|
if (CheckKey(key))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_preventDefaultAction = false;
|
|
|
|
_preventDefaultAction = false;
|
|
|
|
|
|
|
|
|
|
|
|
await OnKeyDown.InvokeAsync(args);
|
|
|
|
await OnKeyDown.InvokeAsync(args);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
args.Key = null;
|
|
|
|
args.Key = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -222,11 +220,13 @@ public partial class NumberInput<NumberType>:InputBase where NumberType : INumbe
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (typeof(NumberType).Name.ToLower().Contains("int"))
|
|
|
|
if (typeof(NumberType).Name.ToLower().Contains("int"))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (Step - (int)Step > 0) Step = (int)Step;
|
|
|
|
if (Step - (int)Step > 0)
|
|
|
|
if (Step < 1) Step = 1;
|
|
|
|
Step = (int)Step;
|
|
|
|
|
|
|
|
if (Step < 1)
|
|
|
|
|
|
|
|
Step = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
await base.OnParametersSetAsync();
|
|
|
|
await base.OnParametersSetAsync();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
|
|
{
|
|
|
|
{
|
|
|
|