features/new
stm 2 years ago
parent dea04afcd4
commit 77a30b5cfe

@ -8,20 +8,20 @@
<InputNumber <InputNumber
Clearable="false" Clearable="false"
DisableMouseWheel="true" DisableMouseWheel="false"
Disabled="true" Disabled="false"
Readonly="true" Readonly="false"
Placeholder="Double" Placeholder="Double"
Label="Double" Label="Double"
Required="true" Required="false"
Step="0.001" Step="0.000516"
DecimalPlaces="2" DecimalPlaces=5
Class="m-2" Class="m-2"
@bind-Value="@inputValueDouble"> @bind-Value="@inputValueDouble">
</InputNumber> </InputNumber>
<InputNumber <InputNumber
Clearable="false" Clearable="true"
DisableMouseWheel="false" DisableMouseWheel="false"
Disabled="false" Disabled="false"
Readonly="false" Readonly="false"

@ -6,7 +6,7 @@
<div class="@InputFieldClassList"> <div class="@InputFieldClassList">
<input type="number" <input type="number"
value="@Value" value="@_value"
placeholder="@Placeholder" placeholder="@Placeholder"
step="@_step" step="@_step"
disabled="@Disabled" disabled="@Disabled"
@ -14,6 +14,7 @@
@onmousewheel="@OnMouseWheel" @onmousewheel="@OnMouseWheel"
@oninput=@ChangeValueAsync @oninput=@ChangeValueAsync
@attributes="@InputAttributes"> @attributes="@InputAttributes">
</input>
<span class="highlight"></span> <span class="highlight"></span>
<span class="bar"></span> <span class="bar"></span>

@ -3,8 +3,6 @@ using Connected.Utilities;
using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web; using Microsoft.AspNetCore.Components.Web;
using System.Numerics; using System.Numerics;
using System.Runtime.CompilerServices;
using static Connected.Colors;
namespace Connected.Components; namespace Connected.Components;
public partial class InputNumber<NumberType>:InputBase where NumberType : INumber<NumberType> public partial class InputNumber<NumberType>:InputBase where NumberType : INumber<NumberType>
@ -18,7 +16,7 @@ public partial class InputNumber<NumberType>:InputBase where NumberType : INumbe
} }
set 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)); double num = (double)Convert.ChangeType(Value, typeof(double));
num += _step; num += _step;
Value = (NumberType)Convert.ChangeType(num, typeof(NumberType)); Value = AdjustDecimalPlaces((NumberType)Convert.ChangeType(num, typeof(NumberType)));
await ValueChanged.InvokeAsync(Value); 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)); double num = (double)Convert.ChangeType(Value, typeof(double));
num -= _step; num -= _step;
Value = (NumberType)Convert.ChangeType(num, typeof(NumberType)); Value = AdjustDecimalPlaces((NumberType)Convert.ChangeType(num, typeof(NumberType)));
await ValueChanged.InvokeAsync(Value); await ValueChanged.InvokeAsync(Value);
} }
protected async Task OnMouseWheel(WheelEventArgs obj) protected async Task OnMouseWheel(WheelEventArgs obj)
{ {
if (DisableMouseWheel==false) if (!DisableMouseWheel)
{ {
if (!obj.ShiftKey || Disabled || Readonly) if (!obj.ShiftKey || Disabled || Readonly)
return; return;
@ -57,8 +55,20 @@ public partial class InputNumber<NumberType>:InputBase where NumberType : INumbe
} }
} }
private NumberType _value;
[Parameter] [Parameter]
public NumberType Value { get; set; } public NumberType Value
{
get
{
return _value;
}
set
{
_value = AdjustDecimalPlaces(value);
}
}
[Parameter] [Parameter]
public int DecimalPlaces { get; set; } =0; public int DecimalPlaces { get; set; } =0;
@ -72,38 +82,13 @@ public partial class InputNumber<NumberType>:InputBase where NumberType : INumbe
if (args.Value is not null) if (args.Value is not null)
{ {
NumberType value = (NumberType)Convert.ChangeType(args.Value, typeof(NumberType)); 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)); 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)));
}
}
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;
}
} }
await ValueChanged.InvokeAsync((NumberType)Convert.ChangeType(AdjustDecimalPlaces(value), typeof(NumberType)));
} }
return CalculatedStep;
} }
private NumberType AdjustDecimalPlaces(NumberType value) private NumberType AdjustDecimalPlaces(NumberType value)

@ -5,25 +5,14 @@
<div class="@InputFieldClassList"> <div class="@InputFieldClassList">
@if (NumOfRows==1) @if (NumOfRows==1)
{ {
@if (!IsPassword) <input type="@inputType"
{
<input type="text"
value="@Value" value="@Value"
placeholder="@Placeholder" placeholder="@Placeholder"
disabled="@Disabled" disabled="@Disabled"
readonly="@Readonly" readonly="@Readonly"
@oninput=@ChangeValueAsync @oninput=@ChangeValueAsync
@attributes="@InputAttributes" /> @attributes="@InputAttributes" />
} else
{
<input type="password"
value="@Value"
placeholder="@Placeholder"
disabled="@Disabled"
readonly="@Readonly"
@oninput=@ChangeValueAsync
@attributes="@InputAttributes" />
}
} else } else
{ {
<textarea type="textarea" <textarea type="textarea"

@ -33,6 +33,15 @@ public partial class InputText: InputBase
[Parameter] [Parameter]
public string Value { get; set; } public string Value { get; set; }
private string inputType
{
get
{
if (IsPassword) return "password";
return "text";
}
}
[Parameter] [Parameter]
public EventCallback<string> ValueChanged { get; set; } public EventCallback<string> ValueChanged { get; set; }

Loading…
Cancel
Save