Progress
This commit is contained in:
parent
edb2249a43
commit
dea04afcd4
@ -7,18 +7,30 @@
|
|||||||
<p>ValueText: @inputValueText</p>
|
<p>ValueText: @inputValueText</p>
|
||||||
|
|
||||||
<InputNumber
|
<InputNumber
|
||||||
|
Clearable="false"
|
||||||
|
DisableMouseWheel="true"
|
||||||
|
Disabled="true"
|
||||||
|
Readonly="true"
|
||||||
|
Placeholder="Double"
|
||||||
Label="Double"
|
Label="Double"
|
||||||
Required="true"
|
Required="true"
|
||||||
Step="0.001"
|
Step="0.001"
|
||||||
DecimalPlaces="2"
|
DecimalPlaces="2"
|
||||||
|
Class="m-2"
|
||||||
@bind-Value="@inputValueDouble">
|
@bind-Value="@inputValueDouble">
|
||||||
</InputNumber>
|
</InputNumber>
|
||||||
|
|
||||||
<InputNumber
|
<InputNumber
|
||||||
|
Clearable="false"
|
||||||
|
DisableMouseWheel="false"
|
||||||
|
Disabled="false"
|
||||||
|
Readonly="false"
|
||||||
|
Placeholder="Double"
|
||||||
Label="Integer"
|
Label="Integer"
|
||||||
Required="true"
|
Required="true"
|
||||||
Step="0.002"
|
Step="0.001"
|
||||||
|
DecimalPlaces="2"
|
||||||
|
Class="m-4"
|
||||||
@bind-Value="@inputValueInt">
|
@bind-Value="@inputValueInt">
|
||||||
</InputNumber>
|
</InputNumber>
|
||||||
|
|
||||||
@ -29,10 +41,13 @@
|
|||||||
@bind-Value="@inputValueText">
|
@bind-Value="@inputValueText">
|
||||||
</InputText>
|
</InputText>
|
||||||
|
|
||||||
<InputPassword Label="Password"
|
<InputText
|
||||||
|
Label="Password"
|
||||||
|
IsPassword="true"
|
||||||
Required="true"
|
Required="true"
|
||||||
|
ErrorText="@errorText"
|
||||||
@bind-Value="@inputValueText">
|
@bind-Value="@inputValueText">
|
||||||
</InputPassword>
|
</InputText>
|
||||||
|
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
step="@_step"
|
step="@_step"
|
||||||
disabled="@Disabled"
|
disabled="@Disabled"
|
||||||
readonly="@Readonly"
|
readonly="@Readonly"
|
||||||
|
@onmousewheel="@OnMouseWheel"
|
||||||
@oninput=@ChangeValueAsync
|
@oninput=@ChangeValueAsync
|
||||||
@attributes="@InputAttributes">
|
@attributes="@InputAttributes">
|
||||||
|
|
||||||
@ -33,7 +34,8 @@
|
|||||||
@if (Clearable && Value.ToString().Length > 0)
|
@if (Clearable && Value.ToString().Length > 0)
|
||||||
{
|
{
|
||||||
<span class="input-glyph button" @onclick="Clear">
|
<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>
|
</span>
|
||||||
}
|
}
|
||||||
@if (IsError)
|
@if (IsError)
|
||||||
|
@ -1,13 +1,15 @@
|
|||||||
using Connected.Models;
|
using Connected.Models;
|
||||||
using Connected.Utilities;
|
using Connected.Utilities;
|
||||||
using Microsoft.AspNetCore.Components;
|
using Microsoft.AspNetCore.Components;
|
||||||
|
using Microsoft.AspNetCore.Components.Web;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
using static Connected.Colors;
|
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>
|
||||||
{
|
{
|
||||||
private double _step;
|
private double _step =1;
|
||||||
[Parameter]
|
[Parameter]
|
||||||
public double Step {
|
public double Step {
|
||||||
get
|
get
|
||||||
@ -16,8 +18,42 @@ public partial class InputNumber<NumberType>:InputBase where NumberType : INumbe
|
|||||||
}
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
_step = value;
|
_step = CalculateStep(value);
|
||||||
AdjustStep();
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[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)
|
if (args.Value is not null)
|
||||||
{
|
{
|
||||||
NumberType originalValue = (NumberType)Convert.ChangeType(args.Value, typeof(NumberType));
|
NumberType value = (NumberType)Convert.ChangeType(args.Value, typeof(NumberType));
|
||||||
NumberType value = originalValue;
|
|
||||||
if (value.ToString().Length > 0)
|
if (value.ToString().Length > 0)
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -53,22 +88,23 @@ public partial class InputNumber<NumberType>:InputBase where NumberType : INumbe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AdjustStep()
|
private double CalculateStep(double step)
|
||||||
{
|
{
|
||||||
|
double CalculatedStep = 1;
|
||||||
if (DecimalPlaces > 0)
|
if (DecimalPlaces > 0)
|
||||||
{
|
{
|
||||||
var StepDecmalPlaces = Helper.GetDecimalPlaces(_step);
|
var CurrentStepDecmalPlaces = Helper.GetDecimalPlaces(step);
|
||||||
if (StepDecmalPlaces > DecimalPlaces)
|
|
||||||
|
if (CurrentStepDecmalPlaces > DecimalPlaces)
|
||||||
{
|
{
|
||||||
double MinStep = 1;
|
|
||||||
for (int i = 0; i < DecimalPlaces; i++)
|
for (int i = 0; i < DecimalPlaces; i++)
|
||||||
{
|
{
|
||||||
MinStep = MinStep / 10;
|
CalculatedStep = CalculatedStep / 10;
|
||||||
}
|
|
||||||
_step = MinStep;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return CalculatedStep;
|
||||||
|
}
|
||||||
|
|
||||||
private NumberType AdjustDecimalPlaces(NumberType value)
|
private NumberType AdjustDecimalPlaces(NumberType value)
|
||||||
{
|
{
|
||||||
@ -99,7 +135,6 @@ public partial class InputNumber<NumberType>:InputBase where NumberType : INumbe
|
|||||||
Value = AdjustDecimalPlaces(Value);
|
Value = AdjustDecimalPlaces(Value);
|
||||||
await ValueChanged.InvokeAsync(Value);
|
await ValueChanged.InvokeAsync(Value);
|
||||||
}
|
}
|
||||||
AdjustStep();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override async Task OnParametersSetAsync()
|
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -4,6 +4,8 @@
|
|||||||
|
|
||||||
<div class="@InputFieldClassList">
|
<div class="@InputFieldClassList">
|
||||||
@if (NumOfRows==1)
|
@if (NumOfRows==1)
|
||||||
|
{
|
||||||
|
@if (!IsPassword)
|
||||||
{
|
{
|
||||||
<input type="text"
|
<input type="text"
|
||||||
value="@Value"
|
value="@Value"
|
||||||
@ -13,6 +15,16 @@
|
|||||||
@oninput=@ChangeValueAsync
|
@oninput=@ChangeValueAsync
|
||||||
@attributes="@InputAttributes" />
|
@attributes="@InputAttributes" />
|
||||||
} else
|
} else
|
||||||
|
{
|
||||||
|
<input type="password"
|
||||||
|
value="@Value"
|
||||||
|
placeholder="@Placeholder"
|
||||||
|
disabled="@Disabled"
|
||||||
|
readonly="@Readonly"
|
||||||
|
@oninput=@ChangeValueAsync
|
||||||
|
@attributes="@InputAttributes" />
|
||||||
|
}
|
||||||
|
} else
|
||||||
{
|
{
|
||||||
<textarea type="textarea"
|
<textarea type="textarea"
|
||||||
rows="@NumOfRows"
|
rows="@NumOfRows"
|
||||||
|
@ -4,6 +4,10 @@ using Microsoft.AspNetCore.Components;
|
|||||||
namespace Connected.Components;
|
namespace Connected.Components;
|
||||||
public partial class InputText: InputBase
|
public partial class InputText: InputBase
|
||||||
{
|
{
|
||||||
|
|
||||||
|
[Parameter]
|
||||||
|
public bool IsPassword { get; set; } = false;
|
||||||
|
|
||||||
[Parameter]
|
[Parameter]
|
||||||
public int NumOfRows
|
public int NumOfRows
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user