-
-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[HxRadioButtonList][HxCheckboxList] Adds Toogle buttons to Radio and Checkbox lists #879
Open
mmonteagudo
wants to merge
10
commits into
havit:master
Choose a base branch
from
mmonteagudo:feature/HxRadio_CheckButtonListBase-ToggleView
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
eae22a0
[HxRadioButtonList][HxCheckboxList] Adds Toggle Button view
mmonteagudo 25a1341
Added documentation for CheckboxList and RadioButtonList
mmonteagudo c8250b4
Added documentation for CheckboxList and RadioButtonList
mmonteagudo e80b669
Merge branch 'feature/HxRadio_CheckButtonListBase-ToggleView' of http…
mmonteagudo e9240c3
Merge branch 'master' into feature/HxRadio_CheckButtonListBase-Toggle…
mmonteagudo 864e41a
Updated CheckboxList Toggle view
mmonteagudo 5785143
Fix update Checkbox list toggle view
mmonteagudo c965d89
Added Color management for CheckboxList toggle view
mmonteagudo 74ebfe5
Set Default Color as None
mmonteagudo 48d1a49
fixed check-input class on RadioButtonList
mmonteagudo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
using Havit.Blazor.Components.Web.Infrastructure; | ||
using Havit.Blazor.Components.Web.Bootstrap.Internal; | ||
using Havit.Blazor.Components.Web.Infrastructure; | ||
|
||
namespace Havit.Blazor.Components.Web.Bootstrap; | ||
|
||
|
@@ -7,13 +8,18 @@ namespace Havit.Blazor.Components.Web.Bootstrap; | |
/// </summary> | ||
/// <typeparam name="TValue">Type of value.</typeparam> | ||
/// <typeparam name="TItem">Type of items.</typeparam> | ||
public abstract class HxRadioButtonListBase<TValue, TItem> : HxInputBase<TValue> | ||
public abstract class HxRadioButtonListBase<TValue, TItem> : HxInputBase<TValue>, IInputWithToggleButton | ||
{ | ||
/// <summary> | ||
/// Allows grouping radios on the same horizontal row by rendering them inline. Default is <c>false</c>. | ||
/// </summary> | ||
[Parameter] public bool Inline { get; set; } | ||
|
||
/// <summary> | ||
/// Input as toggle or regular. | ||
/// </summary> | ||
[Parameter] public InputAsToggle? InputAsToggle { get; set; } | ||
|
||
/// <summary> | ||
/// Selects a value from an item. | ||
/// Not required when <c>TValueType</c> is the same as <c>TItemTime</c>. | ||
|
@@ -134,6 +140,7 @@ protected void BuildRenderInput_RenderRadioItem(RenderTreeBuilder builder, int i | |
var item = _itemsToRender[index]; | ||
if (item != null) | ||
{ | ||
var inputAsToggleEffective = (this as IInputWithToggleButton).InputAsToggleEffective; | ||
bool selected = (index == _selectedItemIndex); | ||
if (selected) | ||
{ | ||
|
@@ -142,13 +149,14 @@ protected void BuildRenderInput_RenderRadioItem(RenderTreeBuilder builder, int i | |
|
||
string inputId = GroupName + "_" + index.ToString(); | ||
|
||
builder.OpenElement(100, "div"); | ||
|
||
// TODO CoreCssClass | ||
builder.AddAttribute(101, "class", CssClassHelper.Combine("form-check", Inline ? "form-check-inline" : null, ItemCssClassImpl, ItemCssClassSelectorImpl?.Invoke(item))); | ||
|
||
if (inputAsToggleEffective != Bootstrap.InputAsToggle.Toggle) | ||
{ | ||
builder.OpenElement(100, "div"); | ||
// TODO CoreCssClass | ||
builder.AddAttribute(101, "class", CssClassHelper.Combine("form-check", Inline ? "form-check-inline" : null, ItemCssClassImpl, ItemCssClassSelectorImpl?.Invoke(item))); | ||
} | ||
Comment on lines
+152
to
+157
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Careful, this ignores |
||
builder.OpenElement(200, "input"); | ||
builder.AddAttribute(201, "class", CssClassHelper.Combine("form-check-input", ItemInputCssClassImpl, ItemInputCssClassSelectorImpl?.Invoke(item))); | ||
builder.AddAttribute(201, "class", CssClassHelper.Combine(inputAsToggleEffective == Bootstrap.InputAsToggle.Toggle ? "btn-check" : "form -check-input", ItemInputCssClassImpl, ItemInputCssClassSelectorImpl?.Invoke(item))); | ||
builder.AddAttribute(202, "type", "radio"); | ||
builder.AddAttribute(203, "name", GroupName); | ||
builder.AddAttribute(204, "id", inputId); | ||
|
@@ -165,7 +173,7 @@ protected void BuildRenderInput_RenderRadioItem(RenderTreeBuilder builder, int i | |
builder.CloseElement(); // input | ||
|
||
builder.OpenElement(300, "label"); | ||
builder.AddAttribute(301, "class", CssClassHelper.Combine("form-check-label", ItemTextCssClassImpl, ItemTextCssClassSelectorImpl?.Invoke(item))); | ||
builder.AddAttribute(301, "class", CssClassHelper.Combine(inputAsToggleEffective == Bootstrap.InputAsToggle.Toggle ? "btn" : "form-check-label", ItemTextCssClassImpl, ItemTextCssClassSelectorImpl?.Invoke(item))); | ||
builder.AddAttribute(302, "for", inputId); | ||
if (ItemTemplateImpl != null) | ||
{ | ||
|
@@ -177,7 +185,10 @@ protected void BuildRenderInput_RenderRadioItem(RenderTreeBuilder builder, int i | |
} | ||
builder.CloseElement(); // label | ||
|
||
builder.CloseElement(); // div | ||
if (inputAsToggleEffective != Bootstrap.InputAsToggle.Toggle) | ||
{ | ||
builder.CloseElement(); // div | ||
} | ||
} | ||
} | ||
|
||
|
16 changes: 16 additions & 0 deletions
16
Havit.Blazor.Components.Web.Bootstrap/Forms/Internal/IInputWithToggleButton.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
namespace Havit.Blazor.Components.Web.Bootstrap.Internal; | ||
/// <summary> | ||
/// Represents an input with a toggle button option | ||
/// </summary> | ||
public interface IInputWithToggleButton | ||
{ | ||
/// <summary> | ||
/// Gets or sets the input as toggle or regular. | ||
/// </summary> | ||
InputAsToggle? InputAsToggle { get; set; } | ||
|
||
/// <summary> | ||
/// Gets the effective input type. | ||
/// </summary> | ||
InputAsToggle InputAsToggleEffective => InputAsToggle ?? Bootstrap.InputAsToggle.Regular; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
namespace Havit.Blazor.Components.Web.Bootstrap; | ||
/// <summary> | ||
/// Input display type. | ||
/// </summary> | ||
public enum InputAsToggle | ||
{ | ||
/// <summary> | ||
/// Regular | ||
/// </summary> | ||
Regular = 0, | ||
/// <summary> | ||
/// <see href="https://getbootstrap.com/docs/5.3/forms/checks-radios/#toggle-buttons">Toggle buttons</see>. | ||
/// </summary> | ||
Toggle = 1 | ||
} |
25 changes: 25 additions & 0 deletions
25
....Blazor.Documentation/Pages/Components/HxCheckboxListDoc/HxCheckboxList_Demo_Toggle.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
@inject IDemoDataService DemoDataService | ||
|
||
<HxCheckboxList TItem="EmployeeDto" | ||
TValue="int" | ||
InputAsToggle="InputAsToggle.Toggle" | ||
Label="Employees" | ||
Data="@data" | ||
ItemTextSelector="@(employee => employee.Name)" | ||
ItemValueSelector="@(employee => employee.Id)" | ||
@bind-Value="selectedEmployeeIds" /> | ||
|
||
<p class="mt-2"> | ||
Selected employee IDs: @String.Join(", ", selectedEmployeeIds.Select(i => i.ToString()) ?? Enumerable.Empty<string>()) | ||
</p> | ||
|
||
@code | ||
{ | ||
private IEnumerable<EmployeeDto> data; | ||
private List<int> selectedEmployeeIds { get; set; } = new(); | ||
|
||
protected override async Task OnParametersSetAsync() | ||
{ | ||
data = await DemoDataService.GetPreferredEmployeesAsync(count: 5); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
...r.Documentation/Pages/Components/HxRadioButtonListDoc/HxRadioButtonList_Demo_Toggle.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
@inject IDemoDataService DemoDataService | ||
|
||
<HxRadioButtonList Label="Employee" | ||
TItem="EmployeeDto" | ||
InputAsToggle="InputAsToggle.Toggle" | ||
TValue="int?" | ||
Data="@data" | ||
@bind-Value="@selectedEmployeeId" | ||
ItemTextSelector="@(employee => employee.Name)" | ||
ItemValueSelector="@(employee => employee.Id)" /> | ||
|
||
<p class="mt-2">Selected employee ID: @selectedEmployeeId</p> | ||
|
||
@code { | ||
private IEnumerable<EmployeeDto> data; | ||
private int? selectedEmployeeId; | ||
|
||
protected override async Task OnInitializedAsync() | ||
{ | ||
data = await DemoDataService.GetPreferredEmployeesAsync(count: 5); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The API is up for discussion in the related issue #887.