diff --git a/src/Connected.Components.Showcase.Runner/Pages/Index.razor b/src/Connected.Components.Showcase.Runner/Pages/Index.razor index 9ed0882..3a7dd11 100644 --- a/src/Connected.Components.Showcase.Runner/Pages/Index.razor +++ b/src/Connected.Components.Showcase.Runner/Pages/Index.razor @@ -42,8 +42,14 @@ CloseOnDateSelect=true + +

Selected date is @date.ToString()

+

Number is: @number.ToString()

+ @code { DateTime date = DateTime.Today; + + int number = 0; } \ No newline at end of file diff --git a/src/Connected.Components/Components/Grid.razor.cs b/src/Connected.Components/Components/Grid.razor.cs index 563db2a..fe820dd 100644 --- a/src/Connected.Components/Components/Grid.razor.cs +++ b/src/Connected.Components/Components/Grid.razor.cs @@ -37,5 +37,4 @@ public partial class Grid: ComponentBase .Build(); } } - } diff --git a/src/Connected.Components/Components/NumberStepper.razor b/src/Connected.Components/Components/NumberStepper.razor new file mode 100644 index 0000000..042ae57 --- /dev/null +++ b/src/Connected.Components/Components/NumberStepper.razor @@ -0,0 +1,17 @@ +@typeparam NumberType + +
+
+
+ +
+
+
+ +
+
+
+ +
+
+
\ No newline at end of file diff --git a/src/Connected.Components/Components/NumberStepper.razor.cs b/src/Connected.Components/Components/NumberStepper.razor.cs new file mode 100644 index 0000000..55bfb42 --- /dev/null +++ b/src/Connected.Components/Components/NumberStepper.razor.cs @@ -0,0 +1,98 @@ +using Connected.Utilities; +using Microsoft.AspNetCore.Components; +using System.Numerics; + +namespace Connected.Components +{ + public partial class NumberStepper where NumberType : INumber + + { + [Parameter] + public string Class { get; set; } = string.Empty; + + /// + /// Increase 'Value' for the 'Step' + /// + /// 'Value' increased for the 'Step' parameter + private async Task StepUp() + { + try + { + var num = Helper.ConvertToType(Value); + + num += Step; + + Value=Helper.ConvertToType(num); + + } + catch + { + Value = default; + } + + await ValueChanged.InvokeAsync(Value); + } + + /// + /// Decrease 'Value' for the 'Step' + /// + /// 'Value' decreased for the 'Step' parameter + private async Task StepDown() + { + try + { + var num = Helper.ConvertToType(Value); + + num -= Step; + + Value = Helper.ConvertToType(num); + + } + catch + { + Value = default; + } + + await ValueChanged.InvokeAsync(Value); + } + + [Parameter] + public NumberType? Value + { + get + { + + try + { + return Helper.ConvertToType(_value); + } + catch + { + return default; + } + } + set + { + _value = Helper.ConvertToType(value); + } + } + private double _value { get; set; } = 0; + + /// + /// Value change event + /// + [Parameter] + public EventCallback ValueChanged { get; set; } + + [Parameter] + public double Step { get; set; } = 1; + + public async Task Change(ChangeEventArgs args) + { + if (args.Value is not null) + Value = (Helper.ConvertToType(args.Value)); + + await ValueChanged.InvokeAsync(Value); + } + } +} \ No newline at end of file