diff --git a/src/Connected.Components.Showcase.Runner/Pages/Index.razor b/src/Connected.Components.Showcase.Runner/Pages/Index.razor index 6f94a83..7df32d4 100644 --- a/src/Connected.Components.Showcase.Runner/Pages/Index.razor +++ b/src/Connected.Components.Showcase.Runner/Pages/Index.razor @@ -6,13 +6,21 @@

SelectedValue: @SelectedValue.ToString()

- - - + + + + + + + + + + + + + + + @code { int SelectedValue; diff --git a/src/Connected.Components/Components/CheckBox.razor b/src/Connected.Components/Components/CheckBox.razor new file mode 100644 index 0000000..899ccaf --- /dev/null +++ b/src/Connected.Components/Components/CheckBox.razor @@ -0,0 +1,13 @@ +@using Connected.Models; + +@inherits InputBase; + +
+@if (Checked) +{ + +} else { + +} + +
\ No newline at end of file diff --git a/src/Connected.Components/Components/CheckBox.razor.cs b/src/Connected.Components/Components/CheckBox.razor.cs new file mode 100644 index 0000000..12bd057 --- /dev/null +++ b/src/Connected.Components/Components/CheckBox.razor.cs @@ -0,0 +1,21 @@ +using Connected.Models; +using Microsoft.AspNetCore.Components; + +namespace Connected.Components; +public partial class CheckBox: InputBase +{ + [Parameter] + public bool Checked { get; set; } = false; + + [Parameter, EditorRequired] + public string Id { get; set; } + + [Parameter] + public EventCallback CheckedChange { get; set; } + public async Task OnChange(ChangeEventArgs args) + { + Checked = (bool)args.Value; + CheckedChange.InvokeAsync(Checked); + } + +} diff --git a/src/Connected.Components/Components/CheckBoxGroup.razor b/src/Connected.Components/Components/CheckBoxGroup.razor new file mode 100644 index 0000000..68efc7c --- /dev/null +++ b/src/Connected.Components/Components/CheckBoxGroup.razor @@ -0,0 +1,9 @@ +@using Connected.Models; + +@inherits InputBase; + +
+
+ @ChildContent +
+
\ No newline at end of file diff --git a/src/Connected.Components/Components/CheckBoxGroup.razor.cs b/src/Connected.Components/Components/CheckBoxGroup.razor.cs new file mode 100644 index 0000000..d1512cb --- /dev/null +++ b/src/Connected.Components/Components/CheckBoxGroup.razor.cs @@ -0,0 +1,11 @@ +using Microsoft.AspNetCore.Components; + +namespace Connected.Components; +public partial class CheckBoxGroup +{ + [Parameter, EditorRequired] + public string Id { get; set; } + + [Parameter] + public RenderFragment ChildContent { get; set; } +} diff --git a/src/Connected.Components/Components/NumberInput.razor.cs b/src/Connected.Components/Components/NumberInput.razor.cs index 01a81c8..17f6a14 100644 --- a/src/Connected.Components/Components/NumberInput.razor.cs +++ b/src/Connected.Components/Components/NumberInput.razor.cs @@ -228,5 +228,14 @@ public partial class NumberInput:InputBase where NumberType : INumbe await base.OnParametersSetAsync(); } - #endregion + protected override async Task OnInitializedAsync() + { + await base.OnInitializedAsync(); + if (Required) + { + if (!InputAttributes.ContainsKey("required")) InputAttributes.Add("required", true); + } + } + + #endregion } \ No newline at end of file diff --git a/src/Connected.Components/Components/Radio.razor b/src/Connected.Components/Components/Radio.razor new file mode 100644 index 0000000..18e385e --- /dev/null +++ b/src/Connected.Components/Components/Radio.razor @@ -0,0 +1,8 @@ +@using Connected.Models; + +@inherits InputBase; + +
+ + +
\ No newline at end of file diff --git a/src/Connected.Components/Components/Radio.razor.cs b/src/Connected.Components/Components/Radio.razor.cs new file mode 100644 index 0000000..a86a940 --- /dev/null +++ b/src/Connected.Components/Components/Radio.razor.cs @@ -0,0 +1,31 @@ +using Connected.Models; +using Microsoft.AspNetCore.Components; + +namespace Connected.Components; +public partial class Radio: InputBase +{ + [CascadingParameter] + public RadioGroup? ParentRadioGroup { get; set; } + + [Parameter] + public bool Checked { get; set; } = false; + + [Parameter, EditorRequired] + public string Id { get; set; } + + [Parameter] + public EventCallback CheckedChange { get; set; } + public async Task OnChange(ChangeEventArgs args) + { + Checked = (bool)args.Value; + CheckedChange.InvokeAsync(Checked); + } + + protected override async Task OnInitializedAsync() + { + await base.OnInitializedAsync(); + if (ParentRadioGroup.Disabled) Disabled = true; + if (!InputAttributes.ContainsKey("disabled")) + InputAttributes.Add("disabled", Disabled); + } +} diff --git a/src/Connected.Components/Components/RadioGroup.razor b/src/Connected.Components/Components/RadioGroup.razor new file mode 100644 index 0000000..b842c61 --- /dev/null +++ b/src/Connected.Components/Components/RadioGroup.razor @@ -0,0 +1,15 @@ +@using Connected.Models; + +@inherits InputBase; + + +
+ @if (!string.IsNullOrEmpty(Name)) + { +
@Name
+ } +
+ @ChildContent +
+
+
\ No newline at end of file diff --git a/src/Connected.Components/Components/RadioGroup.razor.cs b/src/Connected.Components/Components/RadioGroup.razor.cs new file mode 100644 index 0000000..7b07360 --- /dev/null +++ b/src/Connected.Components/Components/RadioGroup.razor.cs @@ -0,0 +1,12 @@ +using Microsoft.AspNetCore.Components; + +namespace Connected.Components; +public partial class RadioGroup +{ + [Parameter, EditorRequired] + public string Name { get; set; } + + [Parameter] + public RenderFragment ChildContent { get; set; } + +} diff --git a/src/Connected.Components/Components/SimpleSelect.razor b/src/Connected.Components/Components/SimpleSelect.razor index ec9c163..8fb0f45 100644 --- a/src/Connected.Components/Components/SimpleSelect.razor +++ b/src/Connected.Components/Components/SimpleSelect.razor @@ -7,7 +7,6 @@ @if (Items is not null) {
- @if (IsLabel) @@ -42,8 +41,7 @@ + @bind-value="@SearchText" /> } @foreach (ValueType item in Items) { diff --git a/src/Connected.Components/Components/SimpleSelect.razor.cs b/src/Connected.Components/Components/SimpleSelect.razor.cs index 2baadb7..456a06b 100644 --- a/src/Connected.Components/Components/SimpleSelect.razor.cs +++ b/src/Connected.Components/Components/SimpleSelect.razor.cs @@ -29,30 +29,13 @@ public partial class SimpleSelect : InputBase } } - private string DropDownClass { get; set; } = "drop-down"; - - bool DropDownClicked = false; - - public void DropDownClassToggle() - { - DropDownClicked = !DropDownClicked; - if (DropDownClicked) - { - DropDownClass = ""; - } else - { - DropDownClass = "drop-down"; - } - StateHasChanged(); - } - private async Task SetSelectedItem(ValueType item) { //DropDownClassToggle(); await ValueChanged.InvokeAsync(item); } - private async Task FilterItems() + private void FilterItems() { if (string.IsNullOrEmpty(_searchText)) { @@ -76,13 +59,18 @@ public partial class SimpleSelect : InputBase protected override async Task OnParametersSetAsync() { - if (base.InputAttributes is null) base.InputAttributes = new(); - if (base.Required) - { - if (base.InputAttributes.ContainsKey("required")) base.InputAttributes.Add("required", true); - } + OriginalItems = Items; - if (_searchText.Length>0) await FilterItems(); + 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); + } } } \ No newline at end of file diff --git a/src/Connected.Components/Components/TextInput.razor.cs b/src/Connected.Components/Components/TextInput.razor.cs index e7e5354..b8d4268 100644 --- a/src/Connected.Components/Components/TextInput.razor.cs +++ b/src/Connected.Components/Components/TextInput.razor.cs @@ -56,14 +56,13 @@ public partial class TextInput: InputBase } - protected override async Task OnParametersSetAsync() - { - if (base.InputAttributes is null) base.InputAttributes = new(); - if (base.Required) + protected override async Task OnInitializedAsync() + { + await base.OnInitializedAsync(); + if (Required) { - if (base.InputAttributes.ContainsKey("required")) base.InputAttributes.Add("required", true); + if (!InputAttributes.ContainsKey("required")) InputAttributes.Add("required", true); } - await base.OnInitializedAsync(); - } + } } \ No newline at end of file diff --git a/src/Connected.Components/Models/InputBase.cs b/src/Connected.Components/Models/InputBase.cs index a95722c..f6bda7a 100644 --- a/src/Connected.Components/Models/InputBase.cs +++ b/src/Connected.Components/Models/InputBase.cs @@ -1,7 +1,5 @@ using Connected.Utilities; using Microsoft.AspNetCore.Components; -using static Connected.Colors; -using static System.Net.Mime.MediaTypeNames; namespace Connected.Models; public class InputBase : ComponentBase @@ -124,4 +122,9 @@ public class InputBase : ComponentBase [Parameter] public string Placeholder { get; set; } = string.Empty; + + protected override async Task OnInitializedAsync() + { + if (InputAttributes is null) InputAttributes = new(); + } }