Skip to content

Commit eaa2a93

Browse files
authored
feat(Transfer): add IsWrapItemText parameter (#7057)
* chore: 增加预处理指令 * doc: 更新文档注释 * doc: 文档格式化 * refactor: 默认值更改为 true * feat: 增加 IsWrapItemText 参数 * doc: 代码格式化 * feat: 增加样式 * doc: 更新示例 * doc: 文档格式化 * test: 更新单元测试 * chore: bump version 9.12.1-beta02
1 parent 8d5d690 commit eaa2a93

File tree

10 files changed

+87
-17
lines changed

10 files changed

+87
-17
lines changed

src/BootstrapBlazor.Server/Components/Samples/Transfers.razor

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,29 @@
66
<DemoBlock Title="@Localizer["TransferNormalTitle"]"
77
Introduction="@Localizer["TransferNormalIntro"]"
88
Name="Normal">
9-
<Transfer TValue="string" Items="@Items" OnSelectedItemsChanged="@OnSelectedItemsChanged" />
9+
<section ignore class="row form-inline g-3">
10+
<div class="col-12 col-sm-6">
11+
<BootstrapInputGroup>
12+
<BootstrapInputGroupLabel DisplayText="IsWrapItem"></BootstrapInputGroupLabel>
13+
<Switch @bind-Value="@_isWrapItem"></Switch>
14+
</BootstrapInputGroup>
15+
</div>
16+
<div class="col-12 col-sm-6">
17+
<BootstrapInputGroup>
18+
<BootstrapInputGroupLabel DisplayText="IsWrapItemText"></BootstrapInputGroupLabel>
19+
<Switch @bind-Value="@_isWrapItemText"></Switch>
20+
</BootstrapInputGroup>
21+
</div>
22+
<div class="col-12 col-sm-6">
23+
<BootstrapInputGroup>
24+
<BootstrapInputGroupLabel DisplayText="ItemWidth"></BootstrapInputGroupLabel>
25+
<BootstrapInput @bind-Value="@_itemWidth"></BootstrapInput>
26+
</BootstrapInputGroup>
27+
</div>
28+
</section>
29+
<Transfer TValue="string" Items="@Items"
30+
IsWrapItem="@_isWrapItem" IsWrapItemText="@_isWrapItemText" ItemWidth="@_itemWidth"
31+
OnSelectedItemsChanged="@OnSelectedItemsChanged" />
1032
<ConsoleLogger @ref="Logger" />
1133
</DemoBlock>
1234

src/BootstrapBlazor.Server/Components/Samples/Transfers.razor.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ public sealed partial class Transfers : ComponentBase
4343

4444
private IEnumerable<SelectedItem> SelectedValue { get; set; } = Enumerable.Empty<SelectedItem>();
4545

46+
private bool _isWrapItem = true;
47+
private bool _isWrapItemText = true;
48+
private string? _itemWidth = "160px";
49+
4650
private Task OnSelectedItemsChanged(IEnumerable<SelectedItem> items)
4751
{
4852
Logger.Log(string.Join(" ", items.Select(i => i.Text)));
@@ -59,15 +63,17 @@ protected override async Task OnInitializedAsync()
5963
// 模拟异步加载数据源
6064
await Task.Delay(100);
6165

62-
Items = GeneratorItems();
66+
var items = GeneratorItems().ToList();
67+
items[1].Text = "我是一个超级长的专门为了测试溢出折行功能的候选项";
68+
Items = items;
6369
Items1 = GeneratorItems();
6470
Items2 = GeneratorItems();
6571

66-
Items3 = Enumerable.Range(1, 15).Select(i => new SelectedItem()
72+
Items3 = [.. Enumerable.Range(1, 15).Select(i => new SelectedItem()
6773
{
6874
Text = $"{Localizer["Backup"]} {i:d2}",
6975
Value = i.ToString()
70-
}).ToList();
76+
})];
7177

7278
Items4 = GeneratorItems();
7379
Items5 = GeneratorItems();

src/BootstrapBlazor.Server/Locales/en-US.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3219,7 +3219,7 @@
32193219
"PlaceHolder": "Please enter",
32203220
"TransfersTitle": "Transfer",
32213221
"TransferNormalTitle": "Basic usage",
3222-
"TransferNormalIntro": "Searchable",
3222+
"TransferNormalIntro": "Select the candidate items on the left and click the move button to move them to the right",
32233223
"TransferCustomerTitle": "Customizable",
32243224
"TransferCustomerIntro": "You can customize the list title copy, button copy, rendering function of data items, check status copy at the bottom of the list, content area at the bottom of the list, and so on.",
32253225
"TransferSearchTitle": "Searchable",

src/BootstrapBlazor.Server/Locales/zh-CN.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3219,7 +3219,7 @@
32193219
"PlaceHolder": "请输入",
32203220
"TransfersTitle": "Transfer 穿梭框",
32213221
"TransferNormalTitle": "基础用法",
3222-
"TransferNormalIntro": "可搜索",
3222+
"TransferNormalIntro": "左边勾选候选项点击移动按钮将候选项移动到右侧",
32233223
"TransferCustomerTitle": "可自定义",
32243224
"TransferCustomerIntro": "可以对列表标题文案、按钮文案、数据项的渲染函数、列表底部的勾选状态文案、列表底部的内容区等进行自定义。",
32253225
"TransferSearchTitle": "可搜索",

src/BootstrapBlazor/BootstrapBlazor.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<Project Sdk="Microsoft.NET.Sdk.Razor">
22

33
<PropertyGroup Condition="'$(VisualStudioVersion)' == '17.0'">
4-
<Version>9.12.1-beta01</Version>
4+
<Version>9.12.1-beta02</Version>
55
</PropertyGroup>
66

77
<PropertyGroup Condition="'$(VisualStudioVersion)' == '18.0'">
8-
<Version>10.0.0-rc.2.2.1</Version>
8+
<Version>10.0.0-rc.2.2.2</Version>
99
</PropertyGroup>
1010

1111
<ItemGroup>

src/BootstrapBlazor/Components/Transfer/Transfer.razor

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@
1313
HeaderTemplate="LeftHeaderTemplate!" ItemTemplate="LeftItemTemplate!">
1414
</TransferPanel>
1515
<div class="transfer-buttons">
16-
<Button Color="@Color.Primary" IsDisabled="@GetButtonState(RightItems)" OnClick="() => TransferItems(RightItems, LeftItems, false)">
16+
<Button Color="@Color.Primary" IsDisabled="@GetButtonState(RightItems)"
17+
OnClick="() => TransferItems(RightItems, LeftItems, false)">
1718
<i class="@LeftIcon"></i>
1819
<span class="@LeftButtonClassName">@LeftButtonText</span>
1920
</Button>
20-
<Button Color="@Color.Primary" IsDisabled="@GetButtonState(LeftItems)" OnClick="() => TransferItems(LeftItems, RightItems, true)">
21+
<Button Color="@Color.Primary" IsDisabled="@GetButtonState(LeftItems)"
22+
OnClick="() => TransferItems(LeftItems, RightItems, true)">
2123
<span class="@RightButtonClassName">@RightButtonText</span>
2224
<i class="@RightIcon"></i>
2325
</Button>

src/BootstrapBlazor/Components/Transfer/Transfer.razor.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,24 +192,31 @@ public partial class Transfer<TValue>
192192
public string? Height { get; set; }
193193

194194
/// <summary>
195-
/// 获得/设置 是否为换行模式 默认 false 不换行
195+
/// 获得/设置 候选项是否为换行模式 默认 false 不换行
196196
/// </summary>
197197
[Parameter]
198-
public bool IsWrapItem { get; set; }
198+
public bool IsWrapItem { get; set; } = true;
199199

200200
/// <summary>
201201
/// 获得/设置 候选项宽度 默认 null 未设置
202202
/// </summary>
203203
[Parameter]
204204
public string? ItemWidth { get; set; }
205205

206+
/// <summary>
207+
/// 获得/设置 候选项文本是否为换行 默认 false 不换行
208+
/// </summary>
209+
[Parameter]
210+
public bool IsWrapItemText { get; set; }
211+
206212
[Inject]
207213
[NotNull]
208214
private IIconTheme? IconTheme { get; set; }
209215

210216
private string? ClassString => CssBuilder.Default("bb-transfer")
211217
.AddClass("has-height", !string.IsNullOrEmpty(Height))
212218
.AddClass("wrap-item", IsWrapItem)
219+
.AddClass("wrap-item-text", IsWrapItemText)
213220
.AddClassFromAttributes(AdditionalAttributes)
214221
.Build();
215222

src/BootstrapBlazor/Components/Transfer/Transfer.razor.scss

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,29 @@
2828
}
2929

3030
&.wrap-item {
31+
.transfer-panel-list {
32+
flex-direction: row;
33+
flex-wrap: wrap;
34+
35+
.transfer-panel-item {
36+
width: var(--bb-transfer-panel-item-width);
37+
}
38+
}
39+
}
40+
41+
&.wrap-item-text {
3142
.transfer-panel-item .form-check-input + .form-check-label {
3243
white-space: normal;
3344
text-overflow: clip;
3445
overflow: visible;
3546
}
3647
}
48+
49+
.transfer-panel-item .form-check-input + .form-check-label {
50+
white-space: nowrap;
51+
text-overflow: ellipsis;
52+
overflow: hidden;
53+
}
3754
}
3855

3956
.transfer-panel {
@@ -70,13 +87,16 @@
7087
max-height: var(--bb-transfer-panel-list-max-height);
7188
min-height: var(--bb-transfer-panel-list-min-height);
7289
display: flex;
73-
flex-wrap: wrap;
90+
flex-direction: column;
91+
92+
.form-check {
93+
min-height: unset;
94+
}
7495
}
7596

7697
.transfer-panel-item {
7798
border-radius: var(--bs-border-radius);
7899
padding: var(--bb-transfer-panel-item-padding);
79-
width: var(--bb-transfer-panel-item-width);
80100
}
81101

82102
.transfer-panel-item .form-check-input + .form-check-label {

src/BootstrapBlazor/Components/Transfer/TransferPanel.razor

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
@if (ShowSearch)
1818
{
1919
<div class="transfer-panel-filter">
20-
<input type="text" autocomplete="off" placeholder="@SearchPlaceHolderString" disabled="@Disabled" class="input-inner" value="@SearchText" @oninput="@OnSearch" @onkeyup="@OnKeyUp">
20+
<input type="text" autocomplete="off" placeholder="@SearchPlaceHolderString" disabled="@Disabled"
21+
class="input-inner" value="@SearchText" @oninput="@OnSearch" @onkeyup="@OnKeyUp">
2122
<span class="@SearchClass" @onclick="@ClearSearch">
2223
<i class="@SearchIcon"></i>
2324
</span>
@@ -30,8 +31,8 @@
3031
{
3132
var state = item.Active ? CheckboxState.Checked : CheckboxState.UnChecked;
3233
<Checkbox TValue="SelectedItem" IsDisabled="@IsDisabled" class="@GetItemClass(item)"
33-
DisplayText="@item.Text" Value="item" ShowAfterLabel="true" ShowLabel="false"
34-
State="@state" OnStateChanged="@OnStateChanged"></Checkbox>
34+
DisplayText="@item.Text" Value="item" ShowAfterLabel="true" ShowLabel="false"
35+
State="@state" OnStateChanged="@OnStateChanged"></Checkbox>
3536
}
3637
else
3738
{

test/UnitTest/Components/TransferTest.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,20 @@ public void Items_Ok()
1212
{
1313
// 未设置 Items 为空
1414
var cut = Context.RenderComponent<Transfer<string>>();
15+
cut.Contains("class=\"bb-transfer wrap-item\"");
16+
17+
cut.SetParametersAndRender(pb =>
18+
{
19+
pb.Add(a => a.IsWrapItem, false);
20+
});
1521
cut.Contains("class=\"bb-transfer\"");
1622

23+
cut.SetParametersAndRender(pb =>
24+
{
25+
pb.Add(a => a.IsWrapItemText, true);
26+
});
27+
cut.Contains("class=\"bb-transfer wrap-item-text\"");
28+
1729
// 设置 Items
1830
cut.SetParametersAndRender(pb =>
1931
{

0 commit comments

Comments
 (0)