Quick review, must be completed by author

reviews/1
Matija Koželj 2 years ago
parent 3a5d96fc5e
commit 2d78796801

@ -3,7 +3,7 @@
@inherits InputBase; @inherits InputBase;
<label class="checkbox-group" for="@Id"> <label class="checkbox-group" for="@Id">
<input class="checkbox-input" id="@Id" name="@ParentCheckBoxGroup.Name" type="checkbox" @attributes=@InputAttributes> <input class="checkbox-input" id="@Id" type="checkbox" @attributes=@InputAttributes checked="@Checked" disabled="@Disabled">
<div class="checkbox-fill"></div> <div class="checkbox-fill"></div>
<label for="@Id" class="checkbox-label">@Label</label> <label for="@Id" class="checkbox-label">@Label</label>
</label> </label>

@ -4,20 +4,11 @@ using Microsoft.AspNetCore.Components;
namespace Connected.Components; namespace Connected.Components;
public partial class CheckBox : InputBase public partial class CheckBox : InputBase
{ {
[CascadingParameter]
public CheckBoxGroup? ParentCheckBoxGroup { get; set; }
private bool _checked { get; set; }
[Parameter] [Parameter]
public bool? Checked public bool Checked { get; set; }
{
get => _checked;
set => _checked = (bool)value;
}
[Parameter, EditorRequired] [Parameter, EditorRequired]
public string Id { get; set; } public string? Id { get; set; }
[Parameter] [Parameter]
public EventCallback<bool> CheckedChanged { get; set; } public EventCallback<bool> CheckedChanged { get; set; }
@ -25,18 +16,7 @@ public partial class CheckBox : InputBase
public async Task OnChange() public async Task OnChange()
{ {
Checked = !Checked; Checked = !Checked;
CheckedChanged.InvokeAsync((bool)Checked);
}
protected override async Task OnParametersSetAsync() await CheckedChanged.InvokeAsync(Checked);
{
await base.OnInitializedAsync();
if (ParentCheckBoxGroup.Disabled) Disabled = true;
if (!InputAttributes.ContainsKey("disabled"))
InputAttributes.Add("disabled", Disabled);
if (!InputAttributes.ContainsKey("checked"))
InputAttributes.Add("checked", Checked);
StateHasChanged();
} }
} }

@ -1,13 +0,0 @@
@using Connected.Models;
<CascadingValue Value="this">
<div>
@if (!string.IsNullOrEmpty(Name))
{
<h5>@Name</h5>
}
<div class="container">
@ChildContent
</div>
</div>
</CascadingValue>

@ -1,14 +0,0 @@
using Microsoft.AspNetCore.Components;
namespace Connected.Components;
public partial class CheckBoxGroup
{
[Parameter, EditorRequired]
public string Name { get; set; }
[Parameter]
public bool Disabled { get; set; }
[Parameter]
public RenderFragment ChildContent { get; set; }
}

@ -54,7 +54,6 @@ namespace Connected.Components
protected async Task OnClick(MouseEventArgs e) protected async Task OnClick(MouseEventArgs e)
{ {
await Click.InvokeAsync(e); await Click.InvokeAsync(e);
} }
} }
} }

@ -41,7 +41,9 @@ public partial class Link
protected override async Task OnParametersSetAsync() protected override async Task OnParametersSetAsync()
{ {
if (string.IsNullOrEmpty(Text)) Text = Url; if (string.IsNullOrEmpty(Text))
Text = Url;
await base.OnParametersSetAsync(); await base.OnParametersSetAsync();
} }
} }

@ -5,45 +5,36 @@ using Microsoft.AspNetCore.Components.Web;
using System.Numerics; using System.Numerics;
namespace Connected.Components; namespace Connected.Components;
public partial class NumberInput<NumberType>:InputBase where NumberType : INumber<NumberType> public partial class NumberInput<NumberType> : InputBase where NumberType : INumber<NumberType>
{ {
private double _step =1;
[Parameter] [Parameter]
public double Step { public double Step { get; set; } = 1;
get
{
return _step;
}
set
{
_step=value;
}
}
[Parameter] [Parameter]
public bool DisableMouseWheel public bool DisableMouseWheel { get; set; } = false;
{
get;
set;
} = false;
private async Task StepUp() private async Task StepUp()
{ {
try try
{ {
double num = (double)Convert.ChangeType(Value, typeof(double)); var num = (double)Convert.ChangeType(Value, typeof(double));
num += _step;
num += Step;
if (DecimalPlaces > 0) if (DecimalPlaces > 0)
num = Math.Round(num, DecimalPlaces); num = Math.Round(num, DecimalPlaces);
Value = (NumberType)Convert.ChangeType(num, typeof(NumberType)); Value = (NumberType)Convert.ChangeType(num, typeof(NumberType));
if (IsError) ErrorText = string.Empty;
if (IsError)
ErrorText = string.Empty;
} }
catch catch
{ {
ErrorText = "Error with step up!"; ErrorText = "Error with step up!";
Value = default(NumberType); Value = default;
} }
await ValueChanged.InvokeAsync(Value); await ValueChanged.InvokeAsync(Value);
} }
@ -51,26 +42,34 @@ public partial class NumberInput<NumberType>:InputBase where NumberType : INumbe
{ {
try try
{ {
double num = (double)Convert.ChangeType(Value, typeof(double)); var num = (double)Convert.ChangeType(Value, typeof(double));
num -= Step;
num -= _step;
if (DecimalPlaces > 0) if (DecimalPlaces > 0)
num = Math.Round(num, DecimalPlaces); num = Math.Round(num, DecimalPlaces);
Value = (NumberType)Convert.ChangeType(num, typeof(NumberType)); Value = (NumberType)Convert.ChangeType(num, typeof(NumberType));
if (IsError) ErrorText = string.Empty;
} catch if (IsError)
ErrorText = string.Empty;
}
catch
{ {
ErrorText = "Error with step down!"; ErrorText = "Error with step down!";
Value = default(NumberType); Value = default;
} }
await ValueChanged.InvokeAsync(Value); await ValueChanged.InvokeAsync(Value);
} }
protected async Task OnMouseWheel(WheelEventArgs args) protected async Task OnMouseWheel(WheelEventArgs args)
{ {
if (DisableMouseWheel == false) if (DisableMouseWheel)
{ return;
if (args.ShiftKey || Disabled || Readonly) if (args.ShiftKey || Disabled || Readonly)
return; return;
if (args.DeltaY >= 0) if (args.DeltaY >= 0)
{ {
await StepDown(); await StepDown();
@ -79,30 +78,28 @@ public partial class NumberInput<NumberType>:InputBase where NumberType : INumbe
{ {
await StepUp(); await StepUp();
} }
} else
{
return;
}
} }
private string _value; private string? _value;
[Parameter] [Parameter]
public NumberType? Value public NumberType? Value
{ {
get get
{ {
if (string.IsNullOrEmpty(_value)) return default(NumberType); if (string.IsNullOrEmpty(_value))
return default;
return (NumberType)Convert.ChangeType(_value, typeof(NumberType)); return (NumberType)Convert.ChangeType(_value, typeof(NumberType));
} }
set set
{ {
_value = value.ToString(); _value = value?.ToString();
} }
} }
[Parameter] [Parameter]
public int DecimalPlaces { get; set; } =0; public int DecimalPlaces { get; set; } = 0;
[Parameter] [Parameter]
public EventCallback<NumberType> ValueChanged { get; set; } public EventCallback<NumberType> ValueChanged { get; set; }
@ -111,36 +108,35 @@ public partial class NumberInput<NumberType>:InputBase where NumberType : INumbe
{ {
if (args.Value is not null) if (args.Value is not null)
{ {
string newVal = args.Value.ToString(); var newVal = args.Value.ToString()!;
if (!newVal.Equals("0")) if (!newVal.Equals("0"))
{ {
if (newVal.ToString().Contains("-")) if (newVal.ToString().Contains("-"))
newVal = "-" + newVal.ToString().Replace("-", ""); newVal = "-" + newVal.ToString().Replace("-", "");
if (newVal.ToString().ToLower().Contains("e")) if (newVal.ToString().ToLower().Contains("e"))
newVal = "e" + newVal.ToString().Replace("e", ""); newVal = "e" + newVal.ToString().Replace("e", "");
} }
if (string.IsNullOrEmpty(newVal)) if (string.IsNullOrEmpty(newVal))
{ await ValueChanged.InvokeAsync(default);
await ValueChanged.InvokeAsync((NumberType)Convert.ChangeType((NumberType)Convert.ChangeType(null, typeof(NumberType)), typeof(NumberType)));
}
else
{
if (!newVal.Equals(_value)) if (!newVal.Equals(_value))
await ValueChanged.InvokeAsync((NumberType)Convert.ChangeType((NumberType)Convert.ChangeType(newVal, typeof(NumberType)), typeof(NumberType))); await ValueChanged.InvokeAsync((NumberType)Convert.ChangeType(newVal, typeof(NumberType)));
}
} }
} }
public async Task Change(ChangeEventArgs args) public async Task Change(ChangeEventArgs args)
{ {
if (args.Value is not null) if (args.Value is not null)
{
Value = AdjustDecimalPlaces((NumberType)Convert.ChangeType(args.Value, typeof(NumberType))); Value = AdjustDecimalPlaces((NumberType)Convert.ChangeType(args.Value, typeof(NumberType)));
}
ValueChanged.InvokeAsync(Value); await ValueChanged.InvokeAsync(Value);
} }
[Parameter] public EventCallback<KeyboardEventArgs> OnKeyDown { get; set; } [Parameter]
public EventCallback<KeyboardEventArgs> OnKeyDown { get; set; }
private bool CheckKey(string key) private bool CheckKey(string key)
{ {
@ -172,17 +168,19 @@ public partial class NumberInput<NumberType>:InputBase where NumberType : INumbe
private bool _preventDefaultAction = true; private bool _preventDefaultAction = true;
public async Task ChangeValue(KeyboardEventArgs args) public async Task ChangeValue(KeyboardEventArgs args)
{ {
_preventDefaultAction= true; _preventDefaultAction = true;
if (args is not null) if (args is not null)
{ {
var key = args.Key.ToString().ToLower(); var key = args.Key.ToString().ToLower();
if (CheckKey(key)) if (CheckKey(key))
{ {
_preventDefaultAction = false; _preventDefaultAction = false;
await OnKeyDown.InvokeAsync(args); await OnKeyDown.InvokeAsync(args);
} }
} else }
else
{ {
args.Key = null; args.Key = null;
} }
@ -222,8 +220,10 @@ public partial class NumberInput<NumberType>:InputBase where NumberType : INumbe
{ {
if (typeof(NumberType).Name.ToLower().Contains("int")) if (typeof(NumberType).Name.ToLower().Contains("int"))
{ {
if (Step - (int)Step > 0) Step = (int)Step; if (Step - (int)Step > 0)
if (Step < 1) Step = 1; Step = (int)Step;
if (Step < 1)
Step = 1;
} }
await base.OnParametersSetAsync(); await base.OnParametersSetAsync();
} }

@ -3,7 +3,7 @@
@inherits InputBase; @inherits InputBase;
<label class="radio-group" for="@Id"> <label class="radio-group" for="@Id">
<input class="radio-input" id="@Id" name="@ParentRadioGroup.Name" type="radio" @onchange="OnChange" @attributes=@InputAttributes> <input class="radio-input" id="@Id" name="@ParentRadioGroup.Name" type="radio" @onchange="OnChange" @attributes=@InputAttributes disabled="@Disabled" checked="@Checked">
<div class="radio-fill"></div> <div class="radio-fill"></div>
<label for="@Id" class="radio-label">@Label</label> <label for="@Id" class="radio-label">@Label</label>
</label> </label>

@ -7,17 +7,11 @@ public partial class Radio : InputBase
[CascadingParameter] [CascadingParameter]
public RadioGroup? ParentRadioGroup { get; set; } public RadioGroup? ParentRadioGroup { get; set; }
private bool _checked { get; set; }
[Parameter] [Parameter]
public bool? Checked public bool Checked { get; set; }
{
get => _checked;
set => _checked = (bool)value;
}
[Parameter, EditorRequired] [Parameter, EditorRequired]
public string Id { get; set; } public string? Id { get; set; }
[Parameter] [Parameter]
public EventCallback<bool> CheckedChanged { get; set; } public EventCallback<bool> CheckedChanged { get; set; }
@ -25,14 +19,6 @@ public partial class Radio : InputBase
public async Task OnChange() public async Task OnChange()
{ {
Checked = !Checked; Checked = !Checked;
CheckedChanged.InvokeAsync((bool)Checked); await CheckedChanged.InvokeAsync(Checked);
}
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
if (ParentRadioGroup.Disabled) Disabled = true;
if (!InputAttributes.ContainsKey("disabled"))
InputAttributes.Add("disabled", Disabled);
} }
} }

@ -6,6 +6,7 @@
{ {
<h5>@Name</h5> <h5>@Name</h5>
} }
<div class="container"> <div class="container">
@ChildContent @ChildContent
</div> </div>

@ -4,12 +4,12 @@ namespace Connected.Components;
public partial class RadioGroup public partial class RadioGroup
{ {
[Parameter, EditorRequired] [Parameter, EditorRequired]
public string Name { get; set; } public string? Name { get; set; }
[Parameter] [Parameter]
public bool Disabled { get; set; } public bool Disabled { get; set; }
[Parameter] [Parameter]
public RenderFragment ChildContent { get; set; } public RenderFragment? ChildContent { get; set; }
} }

@ -1,5 +1,6 @@
using Connected.Models; using Connected.Models;
using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components;
using System.Collections.ObjectModel;
namespace Connected.Components; namespace Connected.Components;
public partial class SimpleSelect<ValueType> : InputBase public partial class SimpleSelect<ValueType> : InputBase
@ -10,7 +11,7 @@ public partial class SimpleSelect<ValueType> : InputBase
[Parameter] [Parameter]
public IEnumerable<ValueType> Items { get; set; } public IEnumerable<ValueType> Items { get; set; }
public IEnumerable<ValueType> OriginalItems { get; set; } public ObservableCollection<ValueType> OriginalItems { get; set; }
[Parameter] [Parameter]
public bool EnableSearch { get; set; } = true; public bool EnableSearch { get; set; } = true;
@ -60,17 +61,19 @@ public partial class SimpleSelect<ValueType> : InputBase
protected override async Task OnParametersSetAsync() protected override async Task OnParametersSetAsync()
{ {
OriginalItems = Items; OriginalItems = new ObservableCollection<ValueType>(Items);
if (_searchText.Length>0) FilterItems();
if (_searchText.Length > 0)
FilterItems();
await base.OnParametersSetAsync(); await base.OnParametersSetAsync();
} }
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{ {
await base.OnInitializedAsync(); await base.OnInitializedAsync();
if (Required)
{ if (Required && InputAttributes.ContainsKey("required"))
if (InputAttributes.ContainsKey("required")) InputAttributes.Add("required", true); InputAttributes.Add("required", true);
}
} }
} }

@ -5,7 +5,7 @@
<div class="@InputFieldClassList"> <div class="@InputFieldClassList">
@if (NumOfRows==1) @if (NumOfRows==1)
{ {
<input type="@inputType" <input type="@InputType"
value="@Value" value="@Value"
placeholder="@Placeholder" placeholder="@Placeholder"
disabled="@Disabled" disabled="@Disabled"

@ -2,7 +2,7 @@
using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components;
namespace Connected.Components; namespace Connected.Components;
public partial class TextInput: InputBase public partial class TextInput : InputBase
{ {
[Parameter] [Parameter]
@ -17,14 +17,7 @@ public partial class TextInput: InputBase
} }
set set
{ {
if (value < 1) _numberOfLines = Math.Max(1, value);
{
_numberOfLines = 1;
}
else
{
_numberOfLines = value;
}
} }
} }
private int _numberOfLines = 1; private int _numberOfLines = 1;
@ -33,36 +26,26 @@ public partial class TextInput: InputBase
[Parameter] [Parameter]
public string Value { get; set; } = string.Empty; public string Value { get; set; } = string.Empty;
private string inputType private string InputType => IsPassword ? "password" : "text";
{
get
{
if (IsPassword) return "password";
return "text";
}
}
[Parameter] [Parameter]
public EventCallback<string> ValueChanged { get; set; } public EventCallback<string> ValueChanged { get; set; }
private async Task ChangeValueAsync(ChangeEventArgs args) private async Task ChangeValueAsync(ChangeEventArgs args)
{ {
await ValueChanged.InvokeAsync(args.Value.ToString()); await ValueChanged.InvokeAsync(args?.Value?.ToString());
} }
private async Task Clear() private async Task Clear()
{ {
await ValueChanged.InvokeAsync(string.Empty); await ValueChanged.InvokeAsync(string.Empty);
} }
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{ {
await base.OnInitializedAsync(); await base.OnInitializedAsync();
if (Required)
{
if (!InputAttributes.ContainsKey("required")) InputAttributes.Add("required", true);
}
}
if (Required && !InputAttributes.ContainsKey("required"))
InputAttributes.Add("required", true);
}
} }

@ -30,7 +30,7 @@ public class InputBase : ComponentBase
[Parameter] [Parameter]
public bool Required { get; set; } = false; public bool Required { get; set; } = false;
public Dictionary<string, object> InputAttributes { get; set; } public Dictionary<string, object> InputAttributes { get; set; } = new();
/// <summary> /// <summary>
/// Show clear button. /// Show clear button.
@ -50,18 +50,11 @@ public class InputBase : ComponentBase
[Parameter] [Parameter]
public bool ShowCharacterCounter { get; set; } public bool ShowCharacterCounter { get; set; }
private string _errorText = string.Empty; /// <summary>
///
/// </summary>
[Parameter] [Parameter]
public string ErrorText { public string ErrorText { get; set; } = string.Empty;
get
{
return _errorText;
}
set
{
_errorText = value;
}
}
public bool IsError public bool IsError
{ {
@ -79,15 +72,16 @@ public class InputBase : ComponentBase
protected virtual async Task SetTextAsync(string text) protected virtual async Task SetTextAsync(string text)
{ {
if (Text != text) if (Text == text)
{ return;
Text = text; Text = text;
await TextChanged.InvokeAsync(text); await TextChanged.InvokeAsync(text);
} }
}
private string _helperText = string.Empty; private string _helperText = string.Empty;
[Parameter] [Parameter]
public string HelperText public string HelperText
{ {

Loading…
Cancel
Save