Progress
This commit is contained in:
parent
edb2249a43
commit
dea04afcd4
@ -7,32 +7,47 @@
|
||||
<p>ValueText: @inputValueText</p>
|
||||
|
||||
<InputNumber
|
||||
Clearable="false"
|
||||
DisableMouseWheel="true"
|
||||
Disabled="true"
|
||||
Readonly="true"
|
||||
Placeholder="Double"
|
||||
Label="Double"
|
||||
Required="true"
|
||||
Step="0.001"
|
||||
DecimalPlaces="2"
|
||||
Class="m-2"
|
||||
@bind-Value="@inputValueDouble">
|
||||
</InputNumber>
|
||||
|
||||
<InputNumber
|
||||
Label="Integer"
|
||||
Required="true"
|
||||
Step="0.002"
|
||||
|
||||
@bind-Value="@inputValueInt">
|
||||
<InputNumber
|
||||
Clearable="false"
|
||||
DisableMouseWheel="false"
|
||||
Disabled="false"
|
||||
Readonly="false"
|
||||
Placeholder="Double"
|
||||
Label="Integer"
|
||||
Required="true"
|
||||
Step="0.001"
|
||||
DecimalPlaces="2"
|
||||
Class="m-4"
|
||||
@bind-Value="@inputValueInt">
|
||||
</InputNumber>
|
||||
|
||||
<InputText
|
||||
Label="String"
|
||||
Required="true"
|
||||
ErrorText="@errorText"
|
||||
@bind-Value="@inputValueText">
|
||||
Label="String"
|
||||
Required="true"
|
||||
ErrorText="@errorText"
|
||||
@bind-Value="@inputValueText">
|
||||
</InputText>
|
||||
|
||||
<InputPassword Label="Password"
|
||||
Required="true"
|
||||
@bind-Value="@inputValueText">
|
||||
</InputPassword>
|
||||
<InputText
|
||||
Label="Password"
|
||||
IsPassword="true"
|
||||
Required="true"
|
||||
ErrorText="@errorText"
|
||||
@bind-Value="@inputValueText">
|
||||
</InputText>
|
||||
|
||||
|
||||
@code {
|
||||
|
@ -11,6 +11,7 @@
|
||||
step="@_step"
|
||||
disabled="@Disabled"
|
||||
readonly="@Readonly"
|
||||
@onmousewheel="@OnMouseWheel"
|
||||
@oninput=@ChangeValueAsync
|
||||
@attributes="@InputAttributes">
|
||||
|
||||
@ -33,7 +34,8 @@
|
||||
@if (Clearable && Value.ToString().Length > 0)
|
||||
{
|
||||
<span class="input-glyph button" @onclick="Clear">
|
||||
<i class='bx bx-x-circle'></i>
|
||||
<Glyph SVG="@Icons.Material.Rounded.Dangerous" />
|
||||
<!--<i class='bx bx-x-circle'></i>-->
|
||||
</span>
|
||||
}
|
||||
@if (IsError)
|
||||
|
@ -1,13 +1,15 @@
|
||||
using Connected.Models;
|
||||
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>
|
||||
{
|
||||
private double _step;
|
||||
private double _step =1;
|
||||
[Parameter]
|
||||
public double Step {
|
||||
get
|
||||
@ -16,8 +18,42 @@ public partial class InputNumber<NumberType>:InputBase where NumberType : INumbe
|
||||
}
|
||||
set
|
||||
{
|
||||
_step = value;
|
||||
AdjustStep();
|
||||
_step = CalculateStep(value);
|
||||
}
|
||||
}
|
||||
|
||||
[Parameter]
|
||||
public bool DisableMouseWheel { get; set; } = false;
|
||||
|
||||
private async Task StepUp()
|
||||
{
|
||||
double num = (double)Convert.ChangeType(Value, typeof(double));
|
||||
num += _step;
|
||||
Value = (NumberType)Convert.ChangeType(num, typeof(NumberType));
|
||||
await ValueChanged.InvokeAsync(Value);
|
||||
}
|
||||
|
||||
private async Task StepDown()
|
||||
{
|
||||
double num = (double)Convert.ChangeType(Value, typeof(double));
|
||||
num -= _step;
|
||||
Value = (NumberType)Convert.ChangeType(num, typeof(NumberType));
|
||||
await ValueChanged.InvokeAsync(Value);
|
||||
}
|
||||
protected async Task OnMouseWheel(WheelEventArgs obj)
|
||||
{
|
||||
if (DisableMouseWheel==false)
|
||||
{
|
||||
if (!obj.ShiftKey || Disabled || Readonly)
|
||||
return;
|
||||
if (obj.DeltaY < 0)
|
||||
{
|
||||
StepDown();
|
||||
}
|
||||
else
|
||||
{
|
||||
StepUp();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -35,8 +71,7 @@ public partial class InputNumber<NumberType>:InputBase where NumberType : INumbe
|
||||
{
|
||||
if (args.Value is not null)
|
||||
{
|
||||
NumberType originalValue = (NumberType)Convert.ChangeType(args.Value, typeof(NumberType));
|
||||
NumberType value = originalValue;
|
||||
NumberType value = (NumberType)Convert.ChangeType(args.Value, typeof(NumberType));
|
||||
if (value.ToString().Length > 0)
|
||||
{
|
||||
|
||||
@ -53,21 +88,22 @@ public partial class InputNumber<NumberType>:InputBase where NumberType : INumbe
|
||||
}
|
||||
}
|
||||
|
||||
private void AdjustStep()
|
||||
private double CalculateStep(double step)
|
||||
{
|
||||
double CalculatedStep = 1;
|
||||
if (DecimalPlaces > 0)
|
||||
{
|
||||
var StepDecmalPlaces = Helper.GetDecimalPlaces(_step);
|
||||
if (StepDecmalPlaces > DecimalPlaces)
|
||||
var CurrentStepDecmalPlaces = Helper.GetDecimalPlaces(step);
|
||||
|
||||
if (CurrentStepDecmalPlaces > DecimalPlaces)
|
||||
{
|
||||
double MinStep = 1;
|
||||
for (int i = 0; i < DecimalPlaces; i++)
|
||||
{
|
||||
MinStep = MinStep / 10;
|
||||
CalculatedStep = CalculatedStep / 10;
|
||||
}
|
||||
_step = MinStep;
|
||||
}
|
||||
}
|
||||
return CalculatedStep;
|
||||
}
|
||||
|
||||
private NumberType AdjustDecimalPlaces(NumberType value)
|
||||
@ -99,7 +135,6 @@ public partial class InputNumber<NumberType>:InputBase where NumberType : INumbe
|
||||
Value = AdjustDecimalPlaces(Value);
|
||||
await ValueChanged.InvokeAsync(Value);
|
||||
}
|
||||
AdjustStep();
|
||||
}
|
||||
|
||||
protected override async Task OnParametersSetAsync()
|
||||
|
@ -1,44 +0,0 @@
|
||||
@using Connected.Models;
|
||||
|
||||
@inherits InputBase;
|
||||
|
||||
<div class="@InputFieldClassList">
|
||||
<input type="password"
|
||||
value="@Value"
|
||||
placeholder="@Placeholder"
|
||||
disabled="@Disabled"
|
||||
readonly="@Readonly"
|
||||
@oninput=@ChangeValueAsync
|
||||
@attributes="@InputAttributes" />
|
||||
|
||||
<span class="highlight"></span>
|
||||
<span class="bar"></span>
|
||||
@if (IsLabel)
|
||||
{
|
||||
<label class="label-animated">@Label</label>
|
||||
}
|
||||
@if (IsHelperText && !IsError)
|
||||
{
|
||||
<div class="input-helper-text">@HelperText</div>
|
||||
}
|
||||
@if (IsError)
|
||||
{
|
||||
<div class="input-error-text">@ErrorText</div>
|
||||
}
|
||||
<span class="input-glyph-wraper">
|
||||
<span class="input-glyph">
|
||||
@if (Clearable && Value.ToString().Length > 0)
|
||||
{
|
||||
<span class="input-glyph button" @onclick="Clear">
|
||||
<i class='bx bx-x-circle'></i>
|
||||
</span>
|
||||
}
|
||||
@if (IsError)
|
||||
{
|
||||
<span class="input-glyph error">
|
||||
<i class='bx bx-error-circle'></i>
|
||||
</span>
|
||||
}
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
@ -1,36 +0,0 @@
|
||||
using Connected.Models;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
|
||||
namespace Connected.Components;
|
||||
public partial class InputPassword: InputBase
|
||||
{
|
||||
|
||||
[Parameter]
|
||||
public string Value { get; set; }
|
||||
|
||||
|
||||
[Parameter]
|
||||
public EventCallback<string> ValueChanged { get; set; }
|
||||
|
||||
private async Task ChangeValueAsync(ChangeEventArgs args)
|
||||
{
|
||||
await ValueChanged.InvokeAsync(args.Value.ToString());
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private async Task Clear()
|
||||
{
|
||||
await ValueChanged.InvokeAsync(string.Empty);
|
||||
}
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
if (base.InputAttributes is null) base.InputAttributes = new();
|
||||
if (base.Required)
|
||||
{
|
||||
if (base.InputAttributes.ContainsKey("required")) base.InputAttributes.Add("required", true);
|
||||
}
|
||||
await base.OnInitializedAsync();
|
||||
}
|
||||
|
||||
}
|
@ -5,13 +5,25 @@
|
||||
<div class="@InputFieldClassList">
|
||||
@if (NumOfRows==1)
|
||||
{
|
||||
<input type="text"
|
||||
@if (!IsPassword)
|
||||
{
|
||||
<input type="text"
|
||||
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"
|
||||
|
@ -4,6 +4,10 @@ using Microsoft.AspNetCore.Components;
|
||||
namespace Connected.Components;
|
||||
public partial class InputText: InputBase
|
||||
{
|
||||
|
||||
[Parameter]
|
||||
public bool IsPassword { get; set; } = false;
|
||||
|
||||
[Parameter]
|
||||
public int NumOfRows
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user