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; }
}

@ -4,26 +4,26 @@ using Microsoft.AspNetCore.Components.Web;
namespace Connected.Components namespace Connected.Components
{ {
public partial class Glyph public partial class Glyph
{ {
[Parameter] [Parameter]
public string SVG { get; set; } = string.Empty; public string SVG { get; set; } = string.Empty;
[Parameter] [Parameter]
public string Color { get; set; } = "#000000"; public string Color { get; set; } = "#000000";
[Parameter] [Parameter]
public int Width { get; set; } = 24; public int Width { get; set; } = 24;
[Parameter] [Parameter]
public int Height { get; set; } = 24; public int Height { get; set; } = 24;
private string WidthString private string WidthString
{
get
{ {
get return Width.ToString() + "px";
{
return Width.ToString() + "px";
}
} }
}
private string HeightString private string HeightString
{ {
@ -34,17 +34,17 @@ namespace Connected.Components
} }
[Parameter] [Parameter]
public string Class { get; set; } = string.Empty; public string Class { get; set; } = string.Empty;
private string GlyphClassList private string GlyphClassList
{
get
{ {
get return new CssBuilder()
{ .AddClass(Class)
return new CssBuilder() .Build();
.AddClass(Class)
.Build();
}
} }
}
[Parameter] [Parameter]
/// <summary> /// <summary>
@ -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);
} }
} }
} }

@ -4,46 +4,48 @@ using Microsoft.AspNetCore.Components;
namespace Connected.Components; namespace Connected.Components;
public partial class Link public partial class Link
{ {
[Parameter, EditorRequired] [Parameter, EditorRequired]
public string Url { get; set; } = string.Empty; public string Url { get; set; } = string.Empty;
[Parameter, EditorRequired] [Parameter, EditorRequired]
public string Text { get; set; } = string.Empty; public string Text { get; set; } = string.Empty;
[Parameter, EditorRequired] [Parameter, EditorRequired]
public string Target { get; set; } = "_self"; public string Target { get; set; } = "_self";
[Parameter] [Parameter]
public string Class { get; set; } = string.Empty; public string Class { get; set; } = string.Empty;
private string LinkClassList private string LinkClassList
{ {
get get
{ {
return new CssBuilder() return new CssBuilder()
.AddClass(Class) .AddClass(Class)
.Build(); .Build();
} }
} }
[Parameter] [Parameter]
public string Style { get; set; } = string.Empty; public string Style { get; set; } = string.Empty;
private string LinkStyleList private string LinkStyleList
{ {
get get
{ {
return new StyleBuilder() return new StyleBuilder()
.AddStyle(Style) .AddStyle(Style)
.Build(); .Build();
} }
} }
protected override async Task OnParametersSetAsync() protected override async Task OnParametersSetAsync()
{ {
if (string.IsNullOrEmpty(Text)) Text = Url; if (string.IsNullOrEmpty(Text))
await base.OnParametersSetAsync(); Text = Url;
}
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,96 +42,101 @@ 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)
return;
if (args.DeltaY >= 0)
{ {
if (args.ShiftKey || Disabled || Readonly) await StepDown();
return; }
if (args.DeltaY >= 0) else
{
await StepDown();
}
else
{
await StepUp();
}
} else
{ {
return; await StepUp();
} }
} }
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; }
public async Task GetValueAsync(ChangeEventArgs args) public async Task GetValueAsync(ChangeEventArgs args)
{ {
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)));
} if (!newVal.Equals(_value))
else await ValueChanged.InvokeAsync((NumberType)Convert.ChangeType(newVal, typeof(NumberType)));
{
if (!newVal.Equals(_value))
await ValueChanged.InvokeAsync((NumberType)Convert.ChangeType((NumberType)Convert.ChangeType(newVal, typeof(NumberType)), 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)
{ {
@ -159,7 +155,7 @@ public partial class NumberInput<NumberType>:InputBase where NumberType : INumbe
break; break;
} }
default: default:
{ {
result = false; result = false;
break; break;
} }
@ -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,11 +220,13 @@ 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();
} }
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{ {

@ -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);
} }
} }

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

@ -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;
@ -59,18 +60,20 @@ 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,67 +2,50 @@
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]
public bool IsPassword { get; set; } = false; public bool IsPassword { get; set; } = false;
[Parameter]
public int NumOfRows
{
get
{
return _numberOfLines;
}
set
{
if (value < 1)
{
_numberOfLines = 1;
}
else
{
_numberOfLines = value;
}
}
}
private int _numberOfLines = 1;
[Parameter] [Parameter]
public string Value { get; set; } = string.Empty; public int NumOfRows
private string inputType
{ {
get get
{ {
if (IsPassword) return "password"; return _numberOfLines;
return "text"; }
set
{
_numberOfLines = Math.Max(1, value);
} }
} }
private int _numberOfLines = 1;
[Parameter]
public string Value { get; set; } = string.Empty;
private string InputType => IsPassword ? "password" : "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;
await TextChanged.InvokeAsync(text); Text = 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