Skip to content

Commit 3c4cc8e

Browse files
tiansfatherhandesoftArgoZhangzhaijunlei955XUEWUQIUSHUANG
authored
feat(RadioListGeneric): support generic SelectedItem (#4859)
* Update ITableColumnExtensions.cs * Update ITableColumnExtensions.cs * refactor: 增加 Key 关键字 * feat: 增加 CheckboxGeneric 组件 * refactor: 更新泛型 CheckboxList 组件 * doc: 更新示例文档 * test: 增加单元测试 * feat: 增加 CheckboxListGeneric 组件 * test: 增加单元测试 * refactor: 精简代码 * revert: 撤销更新 * refactor: 增加可为空标记 * feat: 增加 RadioListGeneric 组件 --------- Co-authored-by: 卢骥 <[email protected]> Co-authored-by: Argo Zhang <[email protected]> Co-authored-by: chengKun <[email protected]> Co-authored-by: Frost Autumn <[email protected]> Co-authored-by: Diego2098 <[email protected]> Co-authored-by: Silver <[email protected]> Co-authored-by: j4587698 <[email protected]>
1 parent 3cf0a8f commit 3c4cc8e

File tree

5 files changed

+120
-3
lines changed

5 files changed

+120
-3
lines changed

src/BootstrapBlazor/Components/Checkbox/CheckboxListGeneric.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@namespace BootstrapBlazor.Components
22
@typeparam TValue
3-
@inherits ValidateBase<List<TValue>>
3+
@inherits ValidateBase<List<TValue?>>
44

55
@if (IsShowLabel)
66
{

src/BootstrapBlazor/Components/Checkbox/CheckboxListGeneric.razor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public partial class CheckboxListGeneric<TValue> : IModelEqualityComparer<TValue
9797
/// 获得/设置 SelectedItemChanged 方法
9898
/// </summary>
9999
[Parameter]
100-
public Func<IEnumerable<SelectedItem<TValue>>, List<TValue>, Task>? OnSelectedChanged { get; set; }
100+
public Func<IEnumerable<SelectedItem<TValue>>, List<TValue?>, Task>? OnSelectedChanged { get; set; }
101101

102102
/// <summary>
103103
/// 获得/设置 最多选中数量

src/BootstrapBlazor/Components/Radio/RadioList.razor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace BootstrapBlazor.Components;
1010
/// <summary>
1111
/// 单选框组合组件
1212
/// </summary>
13-
public partial class RadioList<TValue> : CheckboxList<TValue>
13+
public partial class RadioList<TValue>
1414
{
1515
/// <summary>
1616
/// 获得/设置 值为可为空枚举类型时是否自动添加空值 默认 false 自定义空值显示文本请参考 <see cref="NullItemText"/>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
@namespace BootstrapBlazor.Components
2+
@typeparam TValue
3+
@inherits ValidateBase<TValue>
4+
5+
@if (IsShowLabel)
6+
{
7+
<BootstrapLabel required="@Required" ShowLabelTooltip="ShowLabelTooltip" Value="@DisplayText" />
8+
}
9+
@* @if (IsButton)
10+
{
11+
<div @attributes="@AdditionalAttributes" class="radio-list-group">
12+
<div class="@ButtonClassString" role="group">
13+
@foreach (var item in Items)
14+
{
15+
<DynamicElement TagName="span" TriggerClick="!IsDisabled" OnClick="() => OnClick(item)" class="@GetButtonItemClassString(item)">
16+
@item.Text
17+
</DynamicElement>
18+
}
19+
</div>
20+
</div>
21+
}
22+
else
23+
{
24+
<div @attributes="@AdditionalAttributes" class="@ClassString" role="group">
25+
@foreach (var item in Items)
26+
{
27+
var content = GetChildContent(item);
28+
<Radio Value="@item" Color="@Color" GroupName="@GroupName" IsDisabled="@GetDisabledState(item)" ShowAfterLabel="true" ShowLabel="false" DisplayText="@item.Text" State="@CheckState(item)" OnClick="OnClick" ChildContent="content!"></Radio>
29+
}
30+
</div>
31+
}
32+
*@
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the Apache 2.0 License
3+
// See the LICENSE file in the project root for more information.
4+
// Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone
5+
6+
namespace BootstrapBlazor.Components;
7+
8+
/// <summary>
9+
/// 单选框组合组件
10+
/// </summary>
11+
[ExcludeFromCodeCoverage]
12+
public partial class RadioListGeneric<TValue>
13+
{
14+
/// <summary>
15+
/// 获得/设置 值为可为空枚举类型时是否自动添加空值 默认 false 自定义空值显示文本请参考 <see cref="NullItemText"/>
16+
/// </summary>
17+
[Parameter]
18+
public bool IsAutoAddNullItem { get; set; }
19+
20+
/// <summary>
21+
/// 获得/设置 空值项显示文字 默认为 "" 是否自动添加空值请参考 <see cref="IsAutoAddNullItem"/>
22+
/// </summary>
23+
[Parameter]
24+
[NotNull]
25+
public string? NullItemText { get; set; }
26+
27+
/// <summary>
28+
/// 获得/设置 项模板
29+
/// </summary>
30+
[Parameter]
31+
public RenderFragment<SelectedItem<TValue>>? ItemTemplate { get; set; }
32+
33+
//private string? GroupName => Id;
34+
35+
//private string? ClassString => CssBuilder.Default("radio-list form-control")
36+
// .AddClass("no-border", !ShowBorder && ValidCss != "is-invalid")
37+
// .AddClass("is-vertical", IsVertical)
38+
// .AddClass(CssClass).AddClass(ValidCss)
39+
// .Build();
40+
41+
//private string? ButtonClassString => CssBuilder.Default("radio-list btn-group")
42+
// .AddClass("disabled", IsDisabled)
43+
// .AddClass("btn-group-vertical", IsVertical)
44+
// .AddClassFromAttributes(AdditionalAttributes)
45+
// .Build();
46+
47+
//private string? GetButtonItemClassString(SelectedItem item) => CssBuilder.Default("btn")
48+
// .AddClass($"active bg-{Color.ToDescriptionString()}", CurrentValueAsString == item.Value)
49+
// .Build();
50+
51+
///// <summary>
52+
///// <inheritdoc/>
53+
///// </summary>
54+
//protected override void OnParametersSet()
55+
//{
56+
// var t = NullableUnderlyingType ?? typeof(TValue);
57+
// if (t.IsEnum && Items == null)
58+
// {
59+
// Items = t.ToSelectList<TValue>((NullableUnderlyingType != null && IsAutoAddNullItem) ? new SelectedItem<TValue>(default, NullItemText) : null);
60+
// }
61+
62+
// base.OnParametersSet();
63+
//}
64+
65+
///// <summary>
66+
///// 点击选择框方法
67+
///// </summary>
68+
//private async Task OnClick(SelectedItem<TValue> item)
69+
//{
70+
// if (!IsDisabled)
71+
// {
72+
// if (OnSelectedChanged != null)
73+
// {
74+
// await OnSelectedChanged(Items, Value);
75+
// }
76+
// StateHasChanged();
77+
// }
78+
//}
79+
80+
//private CheckboxState CheckState(SelectedItem<TValue> item) => this.Equals<TValue>(Value, item.Value) ? CheckboxState.Checked : CheckboxState.UnChecked;
81+
82+
//private RenderFragment? GetChildContent(SelectedItem<TValue> item) => ItemTemplate == null
83+
// ? null
84+
// : ItemTemplate(item);
85+
}

0 commit comments

Comments
 (0)