From f402aaf061100d7c5c51b786cfb427dabaea00b2 Mon Sep 17 00:00:00 2001 From: Ralph Jansen Date: Wed, 17 May 2023 21:20:38 +0200 Subject: [PATCH] Add container class property to BSInputSwitch (#586) * Add option to add extra classes to the div container surrounding the input with ContainerClass property * Update docs --- src/BlazorStrap-Docs/wwwroot/Static/V4/Forms/Checkbox.md | 1 + src/BlazorStrap-Docs/wwwroot/Static/V5/Forms/Checkbox.md | 1 + src/BlazorStrap.V4/Components/Forms/BSInputSwitch.razor | 2 +- .../Components/Forms/BSInputSwitch.razor.cs | 7 ++++++- src/BlazorStrap.V5/Components/Forms/BSInputSwitch.razor | 2 +- .../Components/Forms/BSInputSwitch.razor.cs | 5 +++++ .../Shared/Components/Forms/BSInputCheckboxBase.cs | 8 +++++++- 7 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/BlazorStrap-Docs/wwwroot/Static/V4/Forms/Checkbox.md b/src/BlazorStrap-Docs/wwwroot/Static/V4/Forms/Checkbox.md index 771a31fe..4b51e31e 100644 --- a/src/BlazorStrap-Docs/wwwroot/Static/V4/Forms/Checkbox.md +++ b/src/BlazorStrap-Docs/wwwroot/Static/V4/Forms/Checkbox.md @@ -14,6 +14,7 @@ See [shared](layout/shared) for additional parameters | IsOutlined | bool | true-false | `.btn-outline-[]` | | IsReadonly | bool | true/false | `readonly` | | IsToggle | bool | true/false | Toggle Button | +| ContainerClass | string | string | custom class to add to `custom-control custom-switch` | ::: `@("value")` is not required it's a line declaration of a string to make the demo work diff --git a/src/BlazorStrap-Docs/wwwroot/Static/V5/Forms/Checkbox.md b/src/BlazorStrap-Docs/wwwroot/Static/V5/Forms/Checkbox.md index 0e97f142..f06a740f 100644 --- a/src/BlazorStrap-Docs/wwwroot/Static/V5/Forms/Checkbox.md +++ b/src/BlazorStrap-Docs/wwwroot/Static/V5/Forms/Checkbox.md @@ -14,6 +14,7 @@ See [shared](layout/shared) for additional parameters | IsOutlined | bool | true-false | `.btn-outline-[]` | | IsReadonly | bool | true/false | `readonly` | | IsToggle | bool | true/false | Toggle Button | +| ContainerClass | string | string | custom class to add to `form-check form-switch` | ::: `@("value")` is not required it's a line declaration of a string to make the demo work diff --git a/src/BlazorStrap.V4/Components/Forms/BSInputSwitch.razor b/src/BlazorStrap.V4/Components/Forms/BSInputSwitch.razor index 8cbb87de..72cb88ff 100644 --- a/src/BlazorStrap.V4/Components/Forms/BSInputSwitch.razor +++ b/src/BlazorStrap.V4/Components/Forms/BSInputSwitch.razor @@ -2,7 +2,7 @@ @typeparam TValue @inherits BlazorStrap.Shared.Components.Forms.BSInputCheckboxBase -
+
\ No newline at end of file diff --git a/src/BlazorStrap.V4/Components/Forms/BSInputSwitch.razor.cs b/src/BlazorStrap.V4/Components/Forms/BSInputSwitch.razor.cs index d0e96b59..177c5ade 100644 --- a/src/BlazorStrap.V4/Components/Forms/BSInputSwitch.razor.cs +++ b/src/BlazorStrap.V4/Components/Forms/BSInputSwitch.razor.cs @@ -7,7 +7,7 @@ namespace BlazorStrap.V4 { public partial class BSInputSwitch : BSInputCheckboxBase { - [Parameter] public string Id { get; set; } = Guid.NewGuid().ToString().Replace("-",""); + [Parameter] public string Id { get; set; } = Guid.NewGuid().ToString().Replace("-", ""); protected override string? ToggleClassBuilder => null; protected override string? LayoutClass => null; @@ -19,5 +19,10 @@ public partial class BSInputSwitch : BSInputCheckboxBase //.AddClass(LayoutClass, !string.IsNullOrEmpty(LayoutClass)) .AddClass(Class, !string.IsNullOrEmpty(Class)) .Build().ToNullString(); + + protected override string? ContainerClassBuilder => new CssBuilder() + .AddClass("custom-control custom-switch") + .AddClass(ContainerClass) + .Build().ToNullString(); } } diff --git a/src/BlazorStrap.V5/Components/Forms/BSInputSwitch.razor b/src/BlazorStrap.V5/Components/Forms/BSInputSwitch.razor index 03586451..845bdc62 100644 --- a/src/BlazorStrap.V5/Components/Forms/BSInputSwitch.razor +++ b/src/BlazorStrap.V5/Components/Forms/BSInputSwitch.razor @@ -2,7 +2,7 @@ @typeparam TValue @inherits BlazorStrap.Shared.Components.Forms.BSInputCheckboxBase -
+
\ No newline at end of file diff --git a/src/BlazorStrap.V5/Components/Forms/BSInputSwitch.razor.cs b/src/BlazorStrap.V5/Components/Forms/BSInputSwitch.razor.cs index 151721ea..05ce26c7 100644 --- a/src/BlazorStrap.V5/Components/Forms/BSInputSwitch.razor.cs +++ b/src/BlazorStrap.V5/Components/Forms/BSInputSwitch.razor.cs @@ -19,5 +19,10 @@ public partial class BSInputSwitch : BSInputCheckboxBase .AddClass(LayoutClass, !string.IsNullOrEmpty(LayoutClass)) .AddClass(Class, !string.IsNullOrEmpty(Class)) .Build().ToNullString(); + + protected override string? ContainerClassBuilder => new CssBuilder() + .AddClass("form-check form-switch") + .AddClass(ContainerClass) + .Build().ToNullString(); } } diff --git a/src/BlazorStrap/Shared/Components/Forms/BSInputCheckboxBase.cs b/src/BlazorStrap/Shared/Components/Forms/BSInputCheckboxBase.cs index e8b65bce..c7e30978 100644 --- a/src/BlazorStrap/Shared/Components/Forms/BSInputCheckboxBase.cs +++ b/src/BlazorStrap/Shared/Components/Forms/BSInputCheckboxBase.cs @@ -26,7 +26,12 @@ public abstract class BSInputCheckboxBase : BSInputBase /// Value of when input is unchecked. /// [Parameter] public virtual T? UnCheckedValue { get; set; } - + + /// + /// CSS classes to add to div container of the input. + /// + [Parameter] public string? ContainerClass { get; set; } + protected bool IsRadio { get; set; } protected bool _isToggle; @@ -35,6 +40,7 @@ public abstract class BSInputCheckboxBase : BSInputBase protected abstract string? ToggleClassBuilder { get; } + protected abstract string? ContainerClassBuilder { get; } protected void RadioOnClickEvent() {