From d688b25589e059f4b7188ca09824cc96db030ad8 Mon Sep 17 00:00:00 2001 From: markosteger Date: Thu, 16 Feb 2023 13:17:06 +0100 Subject: [PATCH] Radio, RadioGroup --- .../Pages/Index.razor | 23 +++++++++----- .../Components/Radio.razor | 8 +++++ .../Components/Radio.razor.cs | 31 +++++++++++++++++++ .../Components/RadioGroup.razor | 15 +++++++++ .../Components/RadioGroup.razor.cs | 12 +++++++ 5 files changed, 81 insertions(+), 8 deletions(-) create mode 100644 src/Connected.Components/Components/Radio.razor create mode 100644 src/Connected.Components/Components/Radio.razor.cs create mode 100644 src/Connected.Components/Components/RadioGroup.razor create mode 100644 src/Connected.Components/Components/RadioGroup.razor.cs diff --git a/src/Connected.Components.Showcase.Runner/Pages/Index.razor b/src/Connected.Components.Showcase.Runner/Pages/Index.razor index 883720b..7df32d4 100644 --- a/src/Connected.Components.Showcase.Runner/Pages/Index.razor +++ b/src/Connected.Components.Showcase.Runner/Pages/Index.razor @@ -6,14 +6,21 @@

SelectedValue: @SelectedValue.ToString()

- - - - - - - - + + + + + + + + + + + + + + + @code { int SelectedValue; 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; } + +}