Skip to content

Commit

Permalink
chore(Select): revert Select component update (#4844)
Browse files Browse the repository at this point in the history
* refactor: 增加级联参数

* doc: 更新示例文档

* doc: 更改示例文件名

* doc: 增加原 Select 组件文档

* test: 增加 SelectGeneric 组件单元测试

* revert: 撤销忽略单元测试标签

* revert: 撤销单元测试更新

* revert: 恢复支持泛型逻辑

* test: 更新单元测试

* refactor: 更改可见性

* refactor: 移动组件到独立包

* chore: bump version 9.1.3-beta07

* revert: 撤销泛型更改
  • Loading branch information
ArgoZhang authored Dec 13, 2024
1 parent 56e8e74 commit 41dbb19
Show file tree
Hide file tree
Showing 20 changed files with 1,116 additions and 1,499 deletions.
441 changes: 441 additions & 0 deletions src/BootstrapBlazor.Shared/Components/Samples/SelectGenerics.razor

Large diffs are not rendered by default.

405 changes: 405 additions & 0 deletions src/BootstrapBlazor.Shared/Components/Samples/SelectGenerics.razor.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
.select-custom ::deep .dropdown-menu {
--bs-dropdown-link-active-bg: var(--bs-secondary);
--bs-dropdown-link-active-color: var(--bs-body-color);
--bb-dropdown-max-height: 540px;
}

.select-custom ::deep .divider {
--bb-divider-margin: 1rem 0;
--bb-divider-bg: #c0c4cc;
}

.dropdown-item-demo {
border-radius: var(--bs-dropdown-border-radius);
border: var(--bs-dropdown-border-width) solid var(--bs-dropdown-border-color);
padding: .5rem;
flex-direction: column;
}

.select-custom-header {
display: flex;
align-items: center;
margin-top: .5rem;
}

.select-custom-header .id {
background-color: var(--bs-success);
padding: .25rem .5rem;
border-radius: var(--bs-dropdown-border-radius);
}

.select-custom-header .name {
padding: .25rem .5rem;
margin: 0 1rem;
flex: 1;
font-weight: bold;
}

.select-custom-header .status {
}

.select-custom-body {
display: flex;
}

.select-custom-body ::deep .progress {
height: 6px;
margin-bottom: .5rem;
}

.select-custom-body .bb-avatar {
width: 102px;
border: 2px solid var(--bs-info);
}

.select-custom-detail {
flex: 1;
margin-inline-start: 2rem;
}

.select-custom-detail > div {
margin-bottom: .5rem;
}
14 changes: 0 additions & 14 deletions src/BootstrapBlazor.Shared/Components/Samples/Selects.razor
Original file line number Diff line number Diff line change
Expand Up @@ -436,20 +436,6 @@
</div>
</DemoBlock>

<DemoBlock Title="@Localizer["SelectsGenericTitle"]"
Introduction="@Localizer["SelectsGenericIntro"]"
Name="Generic">
<section ignore>@((MarkupString)Localizer["SelectsGenericDesc"].Value)</section>
<div class="row">
<div class="col-12 col-sm-6">
<SelectGeneric Items="_genericItems" @bind-Value="_selectedFoo" IsEditable="true"></SelectGeneric>
</div>
<div class="col-12 col-sm-6">
<Display Value="_selectedFoo?.Address"></Display>
</div>
</div>
</DemoBlock>

<AttributeTable Items="@GetAttributes()" />

<EventTable Items="@GetEvents()" />
Original file line number Diff line number Diff line change
Expand Up @@ -242,15 +242,6 @@ private Task OnTimeZoneValueChanged(string timeZoneId)
return Task.CompletedTask;
}

private readonly List<SelectedItem<Foo?>> _genericItems =
[
new() { Text = "Foo1", Value = new Foo() { Id = 1, Address = "Address_F001" } },
new() { Text = "Foo2", Value = new Foo() { Id = 2, Address = "Address_F002" } },
new() { Text = "Foo3", Value = new Foo() { Id = 3, Address = "Address_F003" } }
];

private Foo? _selectedFoo;

/// <summary>
/// 获得事件方法
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/BootstrapBlazor/BootstrapBlazor.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<Version>9.1.3-beta06</Version>
<Version>9.1.3-beta07</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
61 changes: 2 additions & 59 deletions src/BootstrapBlazor/Components/Select/Select.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ namespace BootstrapBlazor.Components;
/// Select 组件实现类
/// </summary>
/// <typeparam name="TValue"></typeparam>
[ExcludeFromCodeCoverage]
public partial class Select<TValue> : ISelect, IModelEqualityComparer<TValue>
public partial class Select<TValue> : ISelect
{
[Inject]
[NotNull]
Expand Down Expand Up @@ -93,13 +92,6 @@ public partial class Select<TValue> : ISelect, IModelEqualityComparer<TValue>
[Parameter]
public Func<string, Task>? OnInputChangedCallback { get; set; }

/// <summary>
/// 获得/设置 选项输入更新后转换为 Value 回调方法 默认 null
/// </summary>
/// <remarks>设置 <see cref="IsEditable"/> 后生效</remarks>
[Parameter]
public Func<string, Task<TValue>>? TextConvertToValueCallback { get; set; }

/// <summary>
/// 获得/设置 无搜索结果时显示文字
/// </summary>
Expand Down Expand Up @@ -169,26 +161,6 @@ public partial class Select<TValue> : ISelect, IModelEqualityComparer<TValue>
[Parameter]
public bool DisableItemChangedWhenFirstRender { get; set; }

/// <summary>
/// 获得/设置 比较数据是否相同回调方法 默认为 null
/// <para>提供此回调方法时忽略 <see cref="CustomKeyAttribute"/> 属性</para>
/// </summary>
[Parameter]
public Func<TValue, TValue, bool>? ValueEqualityComparer { get; set; }

Func<TValue, TValue, bool>? IModelEqualityComparer<TValue>.ModelEqualityComparer
{
get => ValueEqualityComparer;
set => ValueEqualityComparer = value;
}

/// <summary>
/// 获得/设置 数据主键标识标签 默认为 <see cref="KeyAttribute"/>用于判断数据主键标签,如果模型未设置主键时可使用 <see cref="ValueEqualityComparer"/> 参数自定义判断数据模型支持联合主键
/// </summary>
[Parameter]
[NotNull]
public Type? CustomKeyAttribute { get; set; } = typeof(KeyAttribute);

[NotNull]
private Virtualize<SelectedItem>? VirtualizeElement { get; set; }

Expand Down Expand Up @@ -482,27 +454,6 @@ private async Task OnClickItem(SelectedItem item)
}

private async Task SelectedItemChanged(SelectedItem item)
{
if (item is SelectedItem<TValue> d && !Equals(d.Value, Value))
{
item.Active = true;
SelectedItem = item;

CurrentValue = d.Value;

// 触发 SelectedItemChanged 事件
if (OnSelectedItemChanged != null)
{
await OnSelectedItemChanged(SelectedItem);
}
}
else
{
await ValueTypeChanged(item);
}
}

private async Task ValueTypeChanged(SelectedItem item)
{
if (_lastSelectedValueString != item.Value)
{
Expand All @@ -511,7 +462,7 @@ private async Task ValueTypeChanged(SelectedItem item)
SelectedItem = item;

// 触发 StateHasChanged
_lastSelectedValueString = item.Value ?? "";
_lastSelectedValueString = item.Value;
CurrentValueAsString = _lastSelectedValueString;

// 触发 SelectedItemChanged 事件
Expand Down Expand Up @@ -585,12 +536,4 @@ private async Task OnChange(ChangeEventArgs args)
}
}
}

/// <summary>
/// <inheritdoc/>
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <returns></returns>
public bool Equals(TValue? x, TValue? y) => this.Equals<TValue>(x, y);
}
1 change: 0 additions & 1 deletion src/BootstrapBlazor/Components/Select/SelectOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ namespace BootstrapBlazor.Components;
/// <summary>
/// SelectOption 组件
/// </summary>
[ExcludeFromCodeCoverage]
public class SelectOption : ComponentBase
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ public class VirtualizeQueryOption
/// <summary>
/// 请求记录开始索引
/// </summary>
public int StartIndex { get; internal set; }
public int StartIndex { get; set; }

/// <summary>
/// 请求记录总数
/// </summary>
public int Count { get; internal set; }
public int Count { get; set; }

/// <summary>
/// Select 组件搜索文本
/// </summary>
public string? SearchText { get; internal set; }
public string? SearchText { get; set; }
}
18 changes: 0 additions & 18 deletions src/BootstrapBlazor/Components/SelectGeneric/ISelectGeneric.cs

This file was deleted.

115 changes: 0 additions & 115 deletions src/BootstrapBlazor/Components/SelectGeneric/SelectGeneric.razor

This file was deleted.

Loading

0 comments on commit 41dbb19

Please sign in to comment.