Aggiunto anche componente esplicito x double oltre che x decimals
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
@using System.Globalization
|
||||
|
||||
<input type="number"
|
||||
value="@FormattedValue"
|
||||
@onchange="OnChange"
|
||||
step="@Step.ToString(CultureInfo.InvariantCulture)"
|
||||
min="@(Min?.ToString(CultureInfo.InvariantCulture))"
|
||||
max="@(Max?.ToString(CultureInfo.InvariantCulture))"
|
||||
class="@CssClass" />
|
||||
|
||||
@code {
|
||||
/// <summary>
|
||||
/// Actual bind value
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public double Value { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Event for value changed
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public EventCallback<double> ValueChanged { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Number of decimal places to display
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public int Decimals { get; set; } = 3;
|
||||
|
||||
/// <summary>
|
||||
/// Step increment
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public double Step { get; set; } = 0.001;
|
||||
|
||||
/// <summary>
|
||||
/// Minimum value
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public double? Min { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Maximum value
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public double? Max { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// CssClass for input component
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public string CssClass { get; set; } = string.Empty;
|
||||
|
||||
private string FormattedValue => Value.ToString($"F{Decimals}", CultureInfo.InvariantCulture);
|
||||
|
||||
private async Task OnChange(ChangeEventArgs e)
|
||||
{
|
||||
if (double.TryParse(e.Value?.ToString(), NumberStyles.Any, CultureInfo.InvariantCulture, out var parsed))
|
||||
{
|
||||
var rounded = Math.Round(parsed, Decimals);
|
||||
Value = rounded;
|
||||
await ValueChanged.InvokeAsync(rounded);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user