Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/BootstrapBlazor/Components/Upload/ButtonUpload.razor
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@namespace BootstrapBlazor.Components
@namespace BootstrapBlazor.Components
@typeparam TValue
@inherits FileListUploadBase<TValue>

Expand All @@ -17,7 +17,7 @@
OnGetFileFormat="@OnGetFileFormat" OnCancel="OnCancel" CancelIcon="@CancelIcon" LoadingIcon="@LoadingIcon"
InvalidStatusIcon="@InvalidStatusIcon" ValidStatusIcon="@ValidStatusIcon"
ShowDownloadButton="@ShowDownloadButton" DownloadIcon="@DownloadIcon" OnDownload="@OnDownload"
DeleteIcon="@DeleteIcon" OnDelete="@OnFileDelete">
ShowDeleteButton="@ShowDeleteButton" DeleteIcon="@DeleteIcon" OnDelete="@OnFileDelete">
</UploadPreviewList>
}
<InputFile AdditionalAttributes="@GetUploadAdditionalAttributes()" OnChange="OnFileChange" />
Expand Down
7 changes: 7 additions & 0 deletions src/BootstrapBlazor/Components/Upload/ButtonUpload.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ namespace BootstrapBlazor.Components;
/// </summary>
public partial class ButtonUpload<TValue>
{
/// <summary>
/// <para lang="zh">获得/设置 是否显示删除按钮,默认 true</para>
/// <para lang="en">Gets or sets whether to display the delete button. Default is true</para>
/// </summary>
[Parameter]
public bool ShowDeleteButton { get; set; } = true;

/// <summary>
/// <para lang="zh">获得/设置 浏览按钮加载中图标</para>
/// <para lang="en">Gets or sets the loading icon for the browse button</para>
Expand Down
2 changes: 1 addition & 1 deletion src/BootstrapBlazor/Components/Upload/CardUpload.razor
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
ConfirmIcon="@DeleteConfirmButtonIcon"
ConfirmButtonColor="DeleteConfirmButtonColor"
ConfirmButtonText="@DeleteConfirmButtonText"
CloseButtonText="@DeleteCloseButtonText"
CloseButtonText="@DeleteCloseButtonText"
Content="@DeleteConfirmContent"
Icon="@RemoveIcon"
IsAsync="true"
Expand Down
7 changes: 7 additions & 0 deletions src/BootstrapBlazor/Components/Upload/CardUpload.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ public partial class CardUpload<TValue>

private string PreviewerId => $"prev_{Id}";

/// <summary>
/// <para lang="zh">获得/设置 是否显示删除按钮,默认 false</para>
/// <para lang="en">Gets or sets whether to display the delete button. Default is false</para>
/// </summary>
[Parameter]
public bool ShowDeleteButton { get; set; }

/// <summary>
/// <para lang="zh">获得/设置 是否允许预览的回调方法,默认 null</para>
/// <para lang="en">Gets or sets the callback method to determine whether preview is allowed. Default is null</para>
Expand Down
2 changes: 1 addition & 1 deletion src/BootstrapBlazor/Components/Upload/DropUpload.razor
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
CancelIcon="@CancelIcon" LoadingIcon="@LoadingIcon"
InvalidStatusIcon="@InvalidStatusIcon" ValidStatusIcon="@ValidStatusIcon"
ShowDownloadButton="@ShowDownloadButton" DownloadIcon="@DownloadIcon" OnDownload="@OnDownload"
DeleteIcon="@DeleteIcon" OnDelete="@OnFileDelete">
ShowDeleteButton="@ShowDeleteButton" DeleteIcon="@DeleteIcon" OnDelete="@OnFileDelete">
</UploadPreviewList>
}
<InputFile AdditionalAttributes="@GetUploadAdditionalAttributes()" OnChange="OnFileChange"/>
Expand Down
7 changes: 7 additions & 0 deletions src/BootstrapBlazor/Components/Upload/DropUpload.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ namespace BootstrapBlazor.Components;
/// </summary>
public partial class DropUpload
{
/// <summary>
/// <para lang="zh">获得/设置 是否显示删除按钮,默认 true</para>
/// <para lang="en">Gets or sets whether to display the delete button. Default is true</para>
/// </summary>
[Parameter]
public bool ShowDeleteButton { get; set; } = true;

/// <summary>
/// <para lang="zh">获得/设置 Body 模板,默认 null。设置 BodyTemplate 后 IconTemplate 和 TextTemplate 不生效</para>
/// <para lang="en">Gets or sets the body template. Default is null. When BodyTemplate is set, IconTemplate and TextTemplate are not effective</para>
Expand Down
7 changes: 0 additions & 7 deletions src/BootstrapBlazor/Components/Upload/FileListUploadBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,6 @@ namespace BootstrapBlazor.Components;
/// <typeparam name="TValue"></typeparam>
public class FileListUploadBase<TValue> : UploadBase<TValue>
{
/// <summary>
/// <para lang="zh">获得/设置 是否显示删除按钮,默认 false</para>
/// <para lang="en">Gets or sets whether to display the delete button. Default is false</para>
/// </summary>
[Parameter]
public bool ShowDeleteButton { get; set; }

/// <summary>
/// <para lang="zh">获得/设置 删除按钮图标</para>
/// <para lang="en">Gets or sets the delete button icon</para>
Expand Down
7 changes: 5 additions & 2 deletions src/BootstrapBlazor/Components/Upload/UploadPreviewList.razor
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@namespace BootstrapBlazor.Components
@namespace BootstrapBlazor.Components

@if (Items != null)
{
Expand Down Expand Up @@ -32,7 +32,10 @@
{
<i class="@InvalidStatusIconString"></i>
}
<i class="@DeleteIconString" @onclick:stopPropagation @onclick="@(e => OnFileDelete(item))"></i>
@if (ShowDeleteButton)
{
<i class="@DeleteIconString" @onclick:stopPropagation @onclick="@(e => OnFileDelete(item))"></i>
}
</div>
}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ public partial class UploadPreviewList
[Parameter]
public bool ShowDownloadButton { get; set; }

/// <summary>
/// <para lang="zh">获得/设置 是否显示删除按钮,默认 false</para>
/// <para lang="en">Gets or sets whether to display the delete button. Default is false</para>
/// </summary>
[Parameter]
public bool ShowDeleteButton { get; set; }
Comment thread
sourcery-ai[bot] marked this conversation as resolved.

/// <summary>
/// <para lang="zh">获得/设置 点击下载按钮回调方法,默认 null</para>
/// <para lang="en">Gets or sets the callback method for the download button click event. Default is null</para>
Expand Down
15 changes: 15 additions & 0 deletions test/UnitTest/Components/UploadButtonTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,21 @@ public void ButtonUpload_Accept_Ok()
cut.Contains("accept=\".jpg\"");
}

[Theory]
[InlineData(true, true)]
[InlineData(false, false)]
public void ShowDeleteButton_Ok(bool showDeleteButton, bool result)
{
var cut = Context.Render<ButtonUpload<string>>(pb =>
{
pb.Add(a => a.DefaultFileList, [new() { FileName = "1.csv" }]);
pb.Add(a => a.ShowUploadFileList, true);
pb.Add(a => a.ShowDeleteButton, showDeleteButton);
});
var exists = cut.Markup.Contains("delete-icon");
Assert.Equal(result, exists);
}

[Fact]
public void ButtonUpload_OnGetFileFormat_Ok()
{
Expand Down
17 changes: 15 additions & 2 deletions test/UnitTest/Components/UploadDropTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
// Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone

using Microsoft.AspNetCore.Components.Forms;
using System.ComponentModel.DataAnnotations;
using System.Threading.Tasks;

namespace UnitTest.Components;

Expand Down Expand Up @@ -187,6 +185,21 @@ public void OnGetFileFormat_Ok()
cut.Contains("fa-format-test");
}

[Theory]
[InlineData(true, true)]
[InlineData(false, false)]
public void ShowDeleteButton_Ok(bool showDeleteButton, bool result)
{
var cut = Context.Render<DropUpload>(pb =>
{
pb.Add(a => a.DefaultFileList, [new() { FileName = "1.csv" }]);
pb.Add(a => a.ShowUploadFileList, true);
pb.Add(a => a.ShowDeleteButton, showDeleteButton);
});
var exists = cut.Markup.Contains("delete-icon");
Assert.Equal(result, exists);
}

private class MockBrowserFile(string name = "UploadTestFile", string contentType = "text") : IBrowserFile
{
public string Name { get; } = name;
Expand Down