Progress
This commit is contained in:
parent
dea04afcd4
commit
77a30b5cfe
@ -8,20 +8,20 @@
|
||||
|
||||
<InputNumber
|
||||
Clearable="false"
|
||||
DisableMouseWheel="true"
|
||||
Disabled="true"
|
||||
Readonly="true"
|
||||
DisableMouseWheel="false"
|
||||
Disabled="false"
|
||||
Readonly="false"
|
||||
Placeholder="Double"
|
||||
Label="Double"
|
||||
Required="true"
|
||||
Step="0.001"
|
||||
DecimalPlaces="2"
|
||||
Required="false"
|
||||
Step="0.000516"
|
||||
DecimalPlaces=5
|
||||
Class="m-2"
|
||||
@bind-Value="@inputValueDouble">
|
||||
</InputNumber>
|
||||
|
||||
<InputNumber
|
||||
Clearable="false"
|
||||
Clearable="true"
|
||||
DisableMouseWheel="false"
|
||||
Disabled="false"
|
||||
Readonly="false"
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
<div class="@InputFieldClassList">
|
||||
<input type="number"
|
||||
value="@Value"
|
||||
value="@_value"
|
||||
placeholder="@Placeholder"
|
||||
step="@_step"
|
||||
disabled="@Disabled"
|
||||
@ -14,6 +14,7 @@
|
||||
@onmousewheel="@OnMouseWheel"
|
||||
@oninput=@ChangeValueAsync
|
||||
@attributes="@InputAttributes">
|
||||
</input>
|
||||
|
||||
<span class="highlight"></span>
|
||||
<span class="bar"></span>
|
||||
|
@ -3,8 +3,6 @@ using Connected.Utilities;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.AspNetCore.Components.Web;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using static Connected.Colors;
|
||||
|
||||
namespace Connected.Components;
|
||||
public partial class InputNumber<NumberType>:InputBase where NumberType : INumber<NumberType>
|
||||
@ -18,7 +16,7 @@ public partial class InputNumber<NumberType>:InputBase where NumberType : INumbe
|
||||
}
|
||||
set
|
||||
{
|
||||
_step = CalculateStep(value);
|
||||
_step=value;
|
||||
}
|
||||
}
|
||||
|
||||
@ -29,7 +27,7 @@ public partial class InputNumber<NumberType>:InputBase where NumberType : INumbe
|
||||
{
|
||||
double num = (double)Convert.ChangeType(Value, typeof(double));
|
||||
num += _step;
|
||||
Value = (NumberType)Convert.ChangeType(num, typeof(NumberType));
|
||||
Value = AdjustDecimalPlaces((NumberType)Convert.ChangeType(num, typeof(NumberType)));
|
||||
await ValueChanged.InvokeAsync(Value);
|
||||
}
|
||||
|
||||
@ -37,12 +35,12 @@ public partial class InputNumber<NumberType>:InputBase where NumberType : INumbe
|
||||
{
|
||||
double num = (double)Convert.ChangeType(Value, typeof(double));
|
||||
num -= _step;
|
||||
Value = (NumberType)Convert.ChangeType(num, typeof(NumberType));
|
||||
Value = AdjustDecimalPlaces((NumberType)Convert.ChangeType(num, typeof(NumberType)));
|
||||
await ValueChanged.InvokeAsync(Value);
|
||||
}
|
||||
protected async Task OnMouseWheel(WheelEventArgs obj)
|
||||
{
|
||||
if (DisableMouseWheel==false)
|
||||
if (!DisableMouseWheel)
|
||||
{
|
||||
if (!obj.ShiftKey || Disabled || Readonly)
|
||||
return;
|
||||
@ -57,8 +55,20 @@ public partial class InputNumber<NumberType>:InputBase where NumberType : INumbe
|
||||
}
|
||||
}
|
||||
|
||||
private NumberType _value;
|
||||
|
||||
[Parameter]
|
||||
public NumberType Value { get; set; }
|
||||
public NumberType Value
|
||||
{
|
||||
get
|
||||
{
|
||||
return _value;
|
||||
}
|
||||
set
|
||||
{
|
||||
_value = AdjustDecimalPlaces(value);
|
||||
}
|
||||
}
|
||||
|
||||
[Parameter]
|
||||
public int DecimalPlaces { get; set; } =0;
|
||||
@ -67,45 +77,20 @@ public partial class InputNumber<NumberType>:InputBase where NumberType : INumbe
|
||||
[Parameter]
|
||||
public EventCallback<NumberType> ValueChanged { get; set; }
|
||||
|
||||
public async Task ChangeValueAsync(ChangeEventArgs args)
|
||||
public async Task ChangeValueAsync(ChangeEventArgs args)
|
||||
{
|
||||
if (args.Value is not null)
|
||||
{
|
||||
NumberType value = (NumberType)Convert.ChangeType(args.Value, typeof(NumberType));
|
||||
if (value.ToString().Length > 0)
|
||||
if (value.ToString().Length <= 0)
|
||||
{
|
||||
|
||||
value = AdjustDecimalPlaces(value);
|
||||
//await ValueChanged.InvokeAsync((NumberType)Convert.ChangeType(value, typeof(NumberType)));
|
||||
}
|
||||
else
|
||||
{
|
||||
value = (NumberType)Convert.ChangeType(0, typeof(NumberType));
|
||||
//await ValueChanged.InvokeAsync((NumberType)Convert.ChangeType(0, typeof(NumberType)));
|
||||
}
|
||||
Value = value;
|
||||
await ValueChanged.InvokeAsync((NumberType)Convert.ChangeType(Value, typeof(NumberType)));
|
||||
await ValueChanged.InvokeAsync((NumberType)Convert.ChangeType(AdjustDecimalPlaces(value), typeof(NumberType)));
|
||||
}
|
||||
}
|
||||
|
||||
private double CalculateStep(double step)
|
||||
{
|
||||
double CalculatedStep = 1;
|
||||
if (DecimalPlaces > 0)
|
||||
{
|
||||
var CurrentStepDecmalPlaces = Helper.GetDecimalPlaces(step);
|
||||
|
||||
if (CurrentStepDecmalPlaces > DecimalPlaces)
|
||||
{
|
||||
for (int i = 0; i < DecimalPlaces; i++)
|
||||
{
|
||||
CalculatedStep = CalculatedStep / 10;
|
||||
}
|
||||
}
|
||||
}
|
||||
return CalculatedStep;
|
||||
}
|
||||
|
||||
private NumberType AdjustDecimalPlaces(NumberType value)
|
||||
{
|
||||
NumberType result = value;
|
||||
|
@ -5,25 +5,14 @@
|
||||
<div class="@InputFieldClassList">
|
||||
@if (NumOfRows==1)
|
||||
{
|
||||
@if (!IsPassword)
|
||||
{
|
||||
<input type="text"
|
||||
<input type="@inputType"
|
||||
value="@Value"
|
||||
placeholder="@Placeholder"
|
||||
disabled="@Disabled"
|
||||
readonly="@Readonly"
|
||||
@oninput=@ChangeValueAsync
|
||||
@attributes="@InputAttributes" />
|
||||
} else
|
||||
{
|
||||
<input type="password"
|
||||
value="@Value"
|
||||
placeholder="@Placeholder"
|
||||
disabled="@Disabled"
|
||||
readonly="@Readonly"
|
||||
@oninput=@ChangeValueAsync
|
||||
@attributes="@InputAttributes" />
|
||||
}
|
||||
|
||||
} else
|
||||
{
|
||||
<textarea type="textarea"
|
||||
|
@ -33,6 +33,15 @@ public partial class InputText: InputBase
|
||||
[Parameter]
|
||||
public string Value { get; set; }
|
||||
|
||||
private string inputType
|
||||
{
|
||||
get
|
||||
{
|
||||
if (IsPassword) return "password";
|
||||
return "text";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Parameter]
|
||||
public EventCallback<string> ValueChanged { get; set; }
|
||||
|
Loading…
x
Reference in New Issue
Block a user