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;
<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>
<label for="@Id" class="checkbox-label">@Label</label>
</label>

@ -4,20 +4,11 @@ using Microsoft.AspNetCore.Components;
namespace Connected.Components;
public partial class CheckBox : InputBase
{
[CascadingParameter]
public CheckBoxGroup? ParentCheckBoxGroup { get; set; }
private bool _checked { get; set; }
[Parameter]
public bool? Checked
{
get => _checked;
set => _checked = (bool)value;
}
public bool Checked { get; set; }
[Parameter, EditorRequired]
public string Id { get; set; }
public string? Id { get; set; }
[Parameter]
public EventCallback<bool> CheckedChanged { get; set; }
@ -25,18 +16,7 @@ public partial class CheckBox : InputBase
public async Task OnChange()
{
Checked = !Checked;
CheckedChanged.InvokeAsync((bool)Checked);
}
protected override async Task OnParametersSetAsync()
{
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();
await CheckedChanged.InvokeAsync(Checked);
}
}

@ -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)
{
await Click.InvokeAsync(e);
}
}
}

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

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

@ -3,7 +3,7 @@
@inherits InputBase;
<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>
<label for="@Id" class="radio-label">@Label</label>
</label>

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

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

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

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

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

@ -2,7 +2,7 @@
using Microsoft.AspNetCore.Components;
namespace Connected.Components;
public partial class TextInput: InputBase
public partial class TextInput : InputBase
{
[Parameter]
@ -17,14 +17,7 @@ public partial class TextInput: InputBase
}
set
{
if (value < 1)
{
_numberOfLines = 1;
}
else
{
_numberOfLines = value;
}
_numberOfLines = Math.Max(1, value);
}
}
private int _numberOfLines = 1;
@ -33,36 +26,26 @@ public partial class TextInput: InputBase
[Parameter]
public string Value { get; set; } = string.Empty;
private string inputType
{
get
{
if (IsPassword) return "password";
return "text";
}
}
private string InputType => IsPassword ? "password" : "text";
[Parameter]
public EventCallback<string> ValueChanged { get; set; }
private async Task ChangeValueAsync(ChangeEventArgs args)
{
await ValueChanged.InvokeAsync(args.Value.ToString());
await ValueChanged.InvokeAsync(args?.Value?.ToString());
}
private async Task Clear()
{
await ValueChanged.InvokeAsync(string.Empty);
}
protected override async Task 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]
public bool Required { get; set; } = false;
public Dictionary<string, object> InputAttributes { get; set; }
public Dictionary<string, object> InputAttributes { get; set; } = new();
/// <summary>
/// Show clear button.
@ -50,18 +50,11 @@ public class InputBase : ComponentBase
[Parameter]
public bool ShowCharacterCounter { get; set; }
private string _errorText = string.Empty;
/// <summary>
///
/// </summary>
[Parameter]
public string ErrorText {
get
{
return _errorText;
}
set
{
_errorText = value;
}
}
public string ErrorText { get; set; } = string.Empty;
public bool IsError
{
@ -79,15 +72,16 @@ public class InputBase : ComponentBase
protected virtual async Task SetTextAsync(string text)
{
if (Text != text)
{
if (Text == text)
return;
Text = text;
await TextChanged.InvokeAsync(text);
}
}
private string _helperText = string.Empty;
[Parameter]
public string HelperText
{

Loading…
Cancel
Save