Skip to content

Commit

Permalink
Add container class property to BSInputSwitch (#586)
Browse files Browse the repository at this point in the history
* Add option to add extra classes to the div container surrounding the input with ContainerClass property

* Update docs
  • Loading branch information
LockTar authored May 17, 2023
1 parent 0594e8b commit f402aaf
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/BlazorStrap-Docs/wwwroot/Static/V4/Forms/Checkbox.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/BlazorStrap-Docs/wwwroot/Static/V5/Forms/Checkbox.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/BlazorStrap.V4/Components/Forms/BSInputSwitch.razor
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@typeparam TValue
@inherits BlazorStrap.Shared.Components.Forms.BSInputCheckboxBase<TValue>

<div class="custom-control custom-switch">
<div class="@ContainerClassBuilder">
<input type="checkbox" class="@ClassBuilder" id="@Id" @onblur="OnBlurEvent" @onfocus="OnFocusEvent" checked="@Checked()" @onchange="RadioOnClickEvent" disabled="@IsDisabled">
<label class="custom-control-label" for="@Id" >@ChildContent</label>
</div>
7 changes: 6 additions & 1 deletion src/BlazorStrap.V4/Components/Forms/BSInputSwitch.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace BlazorStrap.V4
{
public partial class BSInputSwitch<TValue> : BSInputCheckboxBase<TValue>
{
[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;
Expand All @@ -19,5 +19,10 @@ public partial class BSInputSwitch<TValue> : BSInputCheckboxBase<TValue>
//.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();
}
}
2 changes: 1 addition & 1 deletion src/BlazorStrap.V5/Components/Forms/BSInputSwitch.razor
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@typeparam TValue
@inherits BlazorStrap.Shared.Components.Forms.BSInputCheckboxBase<TValue>

<div class="form-check form-switch">
<div class="@ContainerClassBuilder">
<input type="checkbox" class="@ClassBuilder" id="@Id" @onblur="OnBlurEvent" @onfocus="OnFocusEvent" checked="@Checked()" @onchange="RadioOnClickEvent" disabled="@IsDisabled">
<label class="form-check-label" for="@Id" >@ChildContent</label>
</div>
5 changes: 5 additions & 0 deletions src/BlazorStrap.V5/Components/Forms/BSInputSwitch.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,10 @@ public partial class BSInputSwitch<TValue> : BSInputCheckboxBase<TValue>
.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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ public abstract class BSInputCheckboxBase<T> : BSInputBase<T>
/// Value of <typeparamref name="T"/> when input is unchecked.
/// </summary>
[Parameter] public virtual T? UnCheckedValue { get; set; }


/// <summary>
/// CSS classes to add to div container of the input.
/// </summary>
[Parameter] public string? ContainerClass { get; set; }

protected bool IsRadio { get; set; }

protected bool _isToggle;
Expand All @@ -35,6 +40,7 @@ public abstract class BSInputCheckboxBase<T> : BSInputBase<T>


protected abstract string? ToggleClassBuilder { get; }
protected abstract string? ContainerClassBuilder { get; }

protected void RadioOnClickEvent()
{
Expand Down

0 comments on commit f402aaf

Please sign in to comment.