Skip to content

Commit 365c07f

Browse files
authored
feat(CardUpload): add ActionButtonTemplate parameter (#7027)
* feat: 增加 ActionButtonTemplate 模板 * refactor: 增加条件 * test: 增加单元测试
1 parent d82ddbe commit 365c07f

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

src/BootstrapBlazor/Components/Upload/CardUpload.razor

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
<div class="upload-item-size"><span>@item.GetFileName()</span> (@item.Size.ToFileSizeString())</div>
3333
<div class="upload-item-actions">
3434
<div class="btn-group">
35+
@if (ActionButtonTemplate != null)
36+
{
37+
@ActionButtonTemplate(item)
38+
}
3539
@if (ShowZoomButton)
3640
{
3741
<button type="button" class="btn btn-sm btn-secondary btn-zoom" disabled="@GetDisabledString(item)" @onclick="() => OnClickZoom(item)" aria-label="zoom">

src/BootstrapBlazor/Components/Upload/CardUpload.razor.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ public partial class CardUpload<TValue>
6060
[Parameter]
6161
public RenderFragment<UploadFile>? IconTemplate { get; set; }
6262

63+
/// <summary>
64+
/// 获得/设置 操作按钮模板
65+
/// </summary>
66+
[Parameter]
67+
public RenderFragment<UploadFile>? ActionButtonTemplate { get; set; }
68+
6369
/// <summary>
6470
/// 获得/设置 新建图标
6571
/// </summary>

test/UnitTest/Components/UploadCardTest.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,24 @@ await cut.InvokeAsync(() => input.Instance.OnChange.InvokeAsync(new InputFileCha
220220
btn.InnerHtml.Contains("disabled=\"disabled\"");
221221
}
222222

223+
[Fact]
224+
public void ActionButtonTemplate_Ok()
225+
{
226+
var cut = Context.RenderComponent<CardUpload<string>>(pb =>
227+
{
228+
pb.Add(a => a.DefaultFileList,
229+
[
230+
new() { FileName = "test.png" }
231+
]);
232+
pb.Add(a => a.ActionButtonTemplate, file => pb =>
233+
{
234+
pb.AddMarkupContent(0, "<button class=\"action-button-test\"></button>");
235+
});
236+
});
237+
238+
cut.Contains("action-button-test");
239+
}
240+
223241
private class MockBrowserFile(string name = "UploadTestFile", string contentType = "text", TimeSpan? delay = null) : IBrowserFile
224242
{
225243
public string Name { get; } = name;

0 commit comments

Comments
 (0)