diff --git a/src/Connected.Components.Showcase.Runner/Pages/Index.razor b/src/Connected.Components.Showcase.Runner/Pages/Index.razor index 057b2b3..4183816 100644 --- a/src/Connected.Components.Showcase.Runner/Pages/Index.razor +++ b/src/Connected.Components.Showcase.Runner/Pages/Index.razor @@ -1,20 +1,71 @@ @page "/" -@using Connected.Components; -@using Connected.Enums; -@using Connected.Models.Modal; @using Connected.Models; -@using Connected.Services; -@using Connected.Utilities; +@using Connected.Components; + + +

Component Sandbox

+ + + @for (int i = 0; i < 5; i++) + { + int num = i; + + + Fixed content @num.ToString() + + + Collapsable content @num.ToString() + + + } + + +

Izbran datum je: @date

-

Component Example page

+ + + Step1 + + + Step2 + + + Step3 + + + Step4 + + + + + - + + + + +

Selected date is @date.ToString()

+ +

Number is: @number.ToString()

+

DNumber is: @dnumber.ToString()

@code { - + DateTime date = DateTime.Today; + + double dnumber = 0; + + int number = 0; + + string ErrorText = ""; + + public void ChangeErrorText() + { + if (string.IsNullOrEmpty(ErrorText)) + ErrorText = "Test string: Error has ocurred!"; + else + ErrorText = string.Empty; + //StateHasChanged(); + } } \ No newline at end of file diff --git a/src/Connected.Components/Components/DatePicker.razor b/src/Connected.Components/Components/DatePicker.razor index b1e13ff..763b407 100644 --- a/src/Connected.Components/Components/DatePicker.razor +++ b/src/Connected.Components/Components/DatePicker.razor @@ -5,9 +5,9 @@
- -
Some helping Text
-
At least 6 characters required
+ +
@HelperText
+
@ErrorText
@@ -20,7 +20,6 @@
- @if (Shown) { @@ -96,6 +95,11 @@
@CalendarStart.AddDays(i).ToString("ddd").Substring(0,1)
} + @for (int i=0; i
+ } + @foreach (var Date in ShowingDates) { -
+
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/NumberInput.razor b/src/Connected.Components/Components/NumberInput.razor index 71cf4b4..65307c7 100644 --- a/src/Connected.Components/Components/NumberInput.razor +++ b/src/Connected.Components/Components/NumberInput.razor @@ -5,53 +5,45 @@ @typeparam NumberType
- ChangeValue(args)) - @onkeydown:preventDefault="@_preventDefaultAction" - @oninput=@SetValueAsync + placeholder="@Placeholder" + step="@Step" + value="@Value" @onmousewheel=@OnMouseWheel - @onchange="@Change" @onwheel="OnMouseWheel" - @attributes="@InputAttributes" /> - + @oninput=@SetNumberValueAsync + @attributes="@InputAttributes" + @onchange="@Change" + required="@Required" /> + - @if (IsLabel) - { - - } - @if (IsHelperText && !IsError) - { -
@HelperText
- } + + + +
@HelperText
@if (IsError) {
@ErrorText
} - - - - - - - @if (Clearable && !string.IsNullOrEmpty(Value?.ToString())) + + @if (!isValueNull || IsError) + { + + @if (!isValueNull) { - + } @if (IsError) { - + } - + }
\ No newline at end of file diff --git a/src/Connected.Components/Components/NumberInput.razor.cs b/src/Connected.Components/Components/NumberInput.razor.cs index 2f09c56..28756ad 100644 --- a/src/Connected.Components/Components/NumberInput.razor.cs +++ b/src/Connected.Components/Components/NumberInput.razor.cs @@ -42,10 +42,12 @@ public partial class NumberInput : InputBase where NumberType : INum if (IsError) ErrorText = string.Empty; + isValueNull = false; } catch { ErrorText = "Error with step up!"; + isValueNull = true; Value = default; } @@ -71,11 +73,13 @@ public partial class NumberInput : InputBase where NumberType : INum if (IsError) ErrorText = string.Empty; + isValueNull = false; } catch { ErrorText = "Error with step down!"; Value = default; + isValueNull = true; } await ValueChanged.InvokeAsync(Value); @@ -104,7 +108,19 @@ public partial class NumberInput : InputBase where NumberType : INum } } - private string? _value; + private bool isValueNull { get; set; } = true; + + private bool IsValueSet() + { + bool result = false; + if (Value is not null) + { + result= true; + } + return result; + } + + //private string? _value; /// @@ -114,28 +130,28 @@ public partial class NumberInput : InputBase where NumberType : INum /// [Parameter] [EditorRequired] - public NumberType? Value - { - get - { - if (string.IsNullOrEmpty(_value)) - return default; - else - { - try - { - return Helper.ConvertToType(_value); - } catch - { - return default; - } - } - } - set - { - _value = value?.ToString(); - } - } + public NumberType? Value { get; set; } = default; + //{ + // get + // { + // if (string.IsNullOrEmpty(_value)) + // return default; + // else + // { + // try + // { + // return Helper.ConvertToType(_value); + // } catch + // { + // return default; + // } + // } + // } + // set + // { + // Value = value; + // } + //} /// /// Number of decimal places for Value. If set, Value is corrected when input looses focus @@ -145,33 +161,48 @@ public partial class NumberInput : InputBase where NumberType : INum [Parameter] public int DecimalPlaces { get; set; } = 0; - /// /// Value change event /// [Parameter] - public EventCallback ValueChanged { get; set; } + public EventCallback ValueChanged { get; set; } + + //public async Task SetValueAsync(ChangeEventArgs args) + //{ + // if (args.Value is not null) + // { + // var newVal = args.Value.ToString()!; + + // if (!newVal.Equals("0")) + // { + // if (newVal.ToString().Contains("-")) + // newVal = "-" + newVal.ToString().Replace("-", ""); - public async Task SetValueAsync(ChangeEventArgs args) + // if (newVal.ToString().ToLower().Contains("e")) + // newVal = "e" + newVal.ToString().Replace("e", ""); + // } + + // if (string.IsNullOrEmpty(newVal)) + // await ValueChanged.InvokeAsync(default); + + // if (!newVal.Equals(_value)) + // await ValueChanged.InvokeAsync(Helper.ConvertToType(newVal)); + // } + //} + + public async Task SetNumberValueAsync(ChangeEventArgs args) { if (args.Value is not null) { - var newVal = args.Value.ToString()!; - - if (!newVal.Equals("0")) + if (!string.IsNullOrEmpty(args.Value.ToString())) { - if (newVal.ToString().Contains("-")) - newVal = "-" + newVal.ToString().Replace("-", ""); - - if (newVal.ToString().ToLower().Contains("e")) - newVal = "e" + newVal.ToString().Replace("e", ""); + Value = Helper.ConvertToType(args.Value); + isValueNull = false; + } else + { + isValueNull = true; } - - if (string.IsNullOrEmpty(newVal)) - await ValueChanged.InvokeAsync(default); - - if (!newVal.Equals(_value)) - await ValueChanged.InvokeAsync(Helper.ConvertToType(newVal)); + await ValueChanged.InvokeAsync(Value); } } @@ -179,7 +210,7 @@ public partial class NumberInput : InputBase where NumberType : INum { if (args.Value is not null) Value = AdjustDecimalPlaces(Helper.ConvertToType(args.Value)); - + isValueNull = false; await ValueChanged.InvokeAsync(Value); } @@ -189,53 +220,53 @@ public partial class NumberInput : InputBase where NumberType : INum [Parameter] public EventCallback OnKeyDown { get; set; } - private bool CheckKey(string key) - { - bool result; - if (Helper.IsNumeric(key)) return true; - switch (key.ToLower()) - { - case "backspace": - case "delete": - case "arrowleft": - case "arrowright": - case "-": - //case "e": - { - result = true; - break; - } - default: - { - result = false; - break; - } - } - - if ((key.Equals("-") || key.Equals("-")) && _value.Contains(key)) result = false; - return result; - } - - private bool _preventDefaultAction = true; - public async Task ChangeValue(KeyboardEventArgs args) - { - _preventDefaultAction = true; - if (args is not null) - { - var key = args.Key.ToString().ToLower(); - - if (CheckKey(key)) - { - _preventDefaultAction = false; - - await OnKeyDown.InvokeAsync(args); - } - } - else - { - args.Key = null; - } - } + //private bool CheckKey(string key) + //{ + // bool result; + // if (Helper.IsNumeric(key)) return true; + // switch (key.ToLower()) + // { + // case "backspace": + // case "delete": + // case "arrowleft": + // case "arrowright": + // case "-": + // //case "e": + // { + // result = true; + // break; + // } + // default: + // { + // result = false; + // break; + // } + // } + + // if ((key.Equals("-") || key.Equals("-")) && _value.Contains(key)) result = false; + // return result; + //} + + //private bool _preventDefaultAction = true; + //public async Task ChangeValue(KeyboardEventArgs args) + //{ + // _preventDefaultAction = true; + // if (args is not null) + // { + // var key = args.Key.ToString().ToLower(); + + // if (CheckKey(key)) + // { + // _preventDefaultAction = false; + + // await OnKeyDown.InvokeAsync(args); + // } + // } + // else + // { + // args.Key = null; + // } + //} /// /// Method for adjusting decimal places provided with parameter @@ -259,8 +290,10 @@ public partial class NumberInput : InputBase where NumberType : INum /// private async Task Clear() { - var val = Helper.ConvertToType(null); - await ValueChanged.InvokeAsync(val); + //var val = Helper.ConvertToType(null); + Value = default(NumberType); + isValueNull = true; + await ValueChanged.InvokeAsync(Value); } #region Lifecycle diff --git a/src/Connected.Components/Components/NumberStepper.razor b/src/Connected.Components/Components/NumberStepper.razor new file mode 100644 index 0000000..d0dc8df --- /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 diff --git a/src/Connected.Components/Components/ToggleGlyphButton.razor b/src/Connected.Components/Components/ToggleGlyphButton.razor index 6e6c789..73de04a 100644 --- a/src/Connected.Components/Components/ToggleGlyphButton.razor +++ b/src/Connected.Components/Components/ToggleGlyphButton.razor @@ -9,12 +9,12 @@
@if (GlyphPosition == Position.Top) { - + } @ChildContent @if (GlyphPosition == Position.Bottom) { - + }
diff --git a/src/Connected.Components/Components/ToggleGlyphButton.razor.cs b/src/Connected.Components/Components/ToggleGlyphButton.razor.cs index 9878734..eceac3e 100644 --- a/src/Connected.Components/Components/ToggleGlyphButton.razor.cs +++ b/src/Connected.Components/Components/ToggleGlyphButton.razor.cs @@ -55,6 +55,16 @@ public partial class ToggleGlyphButton: Button [Parameter] public Color ToggledGlyphColor { get; set; } = Color.Dark; + private string _ShownGlyph + { + get + { + if (Toggled) + return ToggledGlyph; + return Glyph; + } + } + #endregion #region Events