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
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
</section>
<CardUpload TValue="string" IsMultiple="@_isMultiple" IsDirectory="@_isDirectory"
IsDisabled="@_isDisabled" IsUploadButtonAtFirst="@_isUploadButtonAtFirst"
ShowProgress="@_showProgress" ShowDeleteButton="@_showDeleteButton" ShowDeleteConfirmButton="@_showDeleteConfirmButton"
ShowProgress="@_showProgress" ShowDeleteButton="@_showDeleteButton" IsConfirmDelete="@_showDeleteConfirmButton"
ShowDownloadButton="@_showDownloadButton" ShowZoomButton="@_showZoomButton" OnChange="@OnCardUpload"></CardUpload>
</DemoBlock>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
Name="Normal">
<div class="row g-3">
<div class="col-12">
<InputUpload TValue="string" ShowDeleteButton="true" IsMultiple="true"
<InputUpload TValue="string" ShowDeleteButton="true" IsMultiple="true" IsConfirmDelete="true"
ShowLabel="true" DisplayText="@Localizer["UploadNormalLabelPhoto"]"
OnChange="@OnFileChange"></InputUpload>
</div>
Expand Down
5 changes: 3 additions & 2 deletions src/BootstrapBlazor/Components/Button/PopConfirmButton.razor
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@namespace BootstrapBlazor.Components
@namespace BootstrapBlazor.Components
@inherits PopConfirmButtonBase

@if (_renderTooltip)
Expand Down Expand Up @@ -35,7 +35,8 @@ else
</CascadingValue>
<PopConfirmButtonContent Title="@Title" Content="@Content" Icon="@ConfirmIcon"
CloseButtonColor="@CloseButtonColor" CloseButtonText="@CloseButtonText" CloseButtonIcon="@CloseButtonIcon"
ConfirmButtonColor="@ConfirmButtonColor" ConfirmButtonText="@ConfirmButtonText" ConfirmButtonIcon="@ConfirmButtonIcon"
ConfirmButtonColor="@ConfirmButtonColor"
ConfirmButtonText="@ConfirmButtonText" ConfirmButtonIcon="@ConfirmButtonIcon"
ShowCloseButton="@ShowCloseButton" OnClose="@OnClose"
ShowConfirmButton="@ShowConfirmButton" OnConfirm="@OnClickConfirm" ChildContent="@BodyTemplate" />
</DynamicElement>;
Expand Down
7 changes: 4 additions & 3 deletions src/BootstrapBlazor/Components/Upload/CardUpload.razor
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
</div>
@if (ShowDeleteButton)
{
@if (ShowDeleteConfirmButton)
@if (IsConfirmDelete)
{
<PopConfirmButton Placement="Placement.Top" class="btn btn-sm btn-outline-danger"
ConfirmIcon="@DeleteConfirmButtonIcon"
Expand All @@ -76,14 +76,15 @@
CloseButtonText="@DeleteCloseButtonText"
Content="@DeleteConfirmContent"
Icon="@RemoveIcon"
IsKeepDisabled="true"
IsAsync="true"
OnConfirm="@(async ()=> await OnCardFileDelete(item))" />
OnConfirm="@(()=> OnCardFileDelete(item))" />
}
else
{
<button type="button" class="btn btn-sm btn-outline-danger"
disabled="@GetDeleteButtonDisabledString(item)" aria-label="delete"
@onclick="() => OnCardFileDelete(item)">
@onclick="@(() => OnCardFileDelete(item))">
<i class="@RemoveIcon"></i>
</button>
}
Expand Down
11 changes: 10 additions & 1 deletion src/BootstrapBlazor/Components/Upload/CardUpload.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,16 @@ public partial class CardUpload<TValue>
/// <para lang="en">Gets or sets whether to display a confirmation dialog before deletion. Only takes effect when the ShowDeleteButton property is true</para>
/// </summary>
[Parameter]
public bool ShowDeleteConfirmButton { get; set; }
[Obsolete("已弃用,请使用 IsConfirmDelete 参数。Deprecated, please use the IsConfirmDelete parameter")]
[ExcludeFromCodeCoverage]
public bool ShowDeleteConfirmButton { get => IsConfirmDelete; set => IsConfirmDelete = value; }

/// <summary>
/// <para lang="zh">获得/设置 删除按钮否显示确认对话框,依赖 ShowDeleteButton 属性为 true 时有效</para>
/// <para lang="en">Gets or sets whether to display a confirmation dialog before deletion. Only takes effect when the ShowDeleteButton property is true</para>
/// </summary>
[Parameter]
public bool IsConfirmDelete { get; set; }

/// <summary>
/// <para lang="zh">获得/设置 删除确认弹窗中确认按钮颜色,默认 Color.Danger</para>
Expand Down
27 changes: 23 additions & 4 deletions src/BootstrapBlazor/Components/Upload/InputUpload.razor
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@namespace BootstrapBlazor.Components
@namespace BootstrapBlazor.Components
@typeparam TValue
@inherits UploadBase<TValue>

Expand All @@ -12,9 +12,28 @@
placeholder="@PlaceHolder" value="@CurrentValueAsString" />
@if (ShowDeleteButton)
{
<Button class="@RemoveButtonClassString" IsDisabled="@IsDeleteButtonDisabled"
Icon="@DeleteButtonIcon" Text="@DeleteButtonText" Color="Color.None"
OnClick="@TriggerDeleteFile"></Button>
@if (IsConfirmDelete)
{
<PopConfirmButton Placement="Placement.Top" class="@RemoveButtonClassString"
ConfirmIcon="@DeleteConfirmButtonIcon"
ConfirmButtonColor="@DeleteConfirmButtonColor"
ConfirmButtonText="@DeleteConfirmButtonText"
CloseButtonText="@DeleteCloseButtonText"
Content="@DeleteConfirmContent"
Text="@DeleteButtonText"
Icon="@DeleteButtonIcon"
IsDisabled="@IsDeleteButtonDisabled"
IsKeepDisabled="true"
IsAsync="true"
OnConfirm="@TriggerDeleteFile" />
}
else
{
<Button class="@RemoveButtonClassString" IsDisabled="@IsDeleteButtonDisabled"
Icon="@DeleteButtonIcon" Text="@DeleteButtonText" Color="Color.None"
OnClick="@TriggerDeleteFile"></Button>
}

}
<Button class="@BrowserButtonClassString" IsDisabled="@CheckStatus()" Icon="@BrowserButtonIcon"
Text="@BrowserButtonText" Color="Color.None"></Button>
Expand Down
43 changes: 42 additions & 1 deletion src/BootstrapBlazor/Components/Upload/InputUpload.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,48 @@ public partial class InputUpload<TValue>
[Parameter]
public bool ShowDeleteButton { get; set; }

/// <summary>
/// <para lang="zh">获得/设置 删除按钮否显示确认对话框,依赖 ShowDeleteButton 属性为 true 时有效</para>
/// <para lang="en">Gets or sets whether to display a confirmation dialog before deletion. Only takes effect when the ShowDeleteButton property is true</para>
/// </summary>
[Parameter]
public bool IsConfirmDelete { get; set; }

/// <summary>
/// <para lang="zh">获得/设置 删除确认弹窗中确认按钮图标,默认 null</para>
/// <para lang="en">Gets or sets the confirmation button icon in the delete confirmation dialog. Default is null</para>
/// </summary>
[Parameter]
public string? DeleteConfirmButtonIcon { get; set; }

/// <summary>
/// <para lang="zh">获得/设置 删除确认弹窗中确认按钮颜色,默认 Color.Danger</para>
/// <para lang="en">Gets or sets the color of the confirmation button in the delete confirmation dialog. Default is Color.Danger</para>
/// </summary>
[Parameter]
public Color DeleteConfirmButtonColor { get; set; } = Color.Danger;

/// <summary>
/// <para lang="zh">获得/设置 删除确认弹窗中确认按钮显示文字,默认 null</para>
/// <para lang="en">Gets or sets the confirmation button display text in the delete confirmation dialog. Default is null</para>
/// </summary>
[Parameter]
public string? DeleteConfirmButtonText { get; set; }

/// <summary>
/// <para lang="zh">获得/设置 删除确认弹窗中取消按钮显示文字,默认 null</para>
/// <para lang="en">Gets or sets the cancel button display text in the delete confirmation dialog. Default is null</para>
/// </summary>
[Parameter]
public string? DeleteCloseButtonText { get; set; }

/// <summary>
/// <para lang="zh">获得/设置 删除确认弹窗中确认文本内容,默认 null 使用资源文件中内置文字</para>
/// <para lang="en">Gets or sets the confirmation text content in the delete confirmation dialog. Default is null (uses built-in text from resource file)</para>
/// </summary>
[Parameter]
public string? DeleteConfirmContent { get; set; }

/// <summary>
/// <para lang="zh">获得/设置 PlaceHolder 占位符文本</para>
/// <para lang="en">Gets or sets the placeholder text</para>
Expand Down Expand Up @@ -118,6 +160,5 @@ private async Task TriggerDeleteFile()
var item = Files[index - 1];
await OnFileDelete(item);
}
CurrentValue = default;
}
}
2 changes: 1 addition & 1 deletion src/BootstrapBlazor/Components/Upload/UploadBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ private void UpdateValue(List<UploadFile> items)
}
else if (ValueType == typeof(IBrowserFile))
{
CurrentValue = (TValue)items[0].File!;
CurrentValue = items.Count != 0 ? (TValue?)items[0].File : default;
}
else if (ValueType == typeof(string))
{
Expand Down
4 changes: 2 additions & 2 deletions test/UnitTest/Components/UploadCardTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ public void ActionButtonTemplate_Ok()
}

[Fact]
public async Task ShowConfirmButton_Ok()
public async Task IsConfirmDelete_Ok()
{
var cut = Context.Render<CardUpload<string>>(pb =>
{
Expand All @@ -333,7 +333,7 @@ public async Task ShowConfirmButton_Ok()
new() { FileName = "test.png" }
]);
pb.Add(a => a.ShowDeleteButton, true);
pb.Add(a => a.ShowDeleteConfirmButton, true);
pb.Add(a => a.IsConfirmDelete, true);
pb.Add(a => a.DeleteConfirmButtonColor, Color.Danger);
pb.Add(a => a.DeleteConfirmButtonIcon, "icon-delete");
pb.Add(a => a.DeleteConfirmContent, "content-delete");
Expand Down
31 changes: 31 additions & 0 deletions test/UnitTest/Components/UploadInputTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,36 @@ await cut.InvokeAsync(() => input.Instance.OnChange.InvokeAsync(new InputFileCha
cut.WaitForAssertion(() => cut.Contains("btn btn-delete"));
}

[Fact]
public async Task IsConfirmDelete_Ok()
{
var file = new MockBrowserFile();
var cut = Context.Render<InputUpload<IBrowserFile>>(pb =>
{
pb.Add(a => a.ShowDeleteButton, true);
pb.Add(a => a.IsConfirmDelete, true);
pb.Add(a => a.DeleteConfirmButtonColor, Color.Danger);
pb.Add(a => a.DeleteConfirmButtonIcon, "icon-delete");
pb.Add(a => a.DeleteConfirmContent, "content-delete");
pb.Add(a => a.DeleteConfirmButtonText, "confirm");
pb.Add(a => a.DeleteCloseButtonText, "cancel");
});

var input = cut.FindComponent<InputFile>();
await cut.InvokeAsync(() => input.Instance.OnChange.InvokeAsync(new InputFileChangeEventArgs(new List<MockBrowserFile>()
{
new()
})));

var button = cut.FindComponent<PopConfirmButton>();
Assert.NotNull(button);
Assert.NotNull(button.Instance.OnConfirm);
Assert.DoesNotContain("pop-confirm disabled", button.Markup);

await cut.InvokeAsync(button.Instance.OnConfirm);
Comment thread
ArgoZhang marked this conversation as resolved.
Assert.Contains("pop-confirm disabled", button.Markup);
}

[Fact]
public async Task InputUpload_ValidateForm_Ok()
{
Expand Down Expand Up @@ -209,6 +239,7 @@ await cut.InvokeAsync(() => input.Instance.OnChange.InvokeAsync(new InputFileCha
Assert.DoesNotContain("test5.png;test6.png", cut.Markup);
}


[Fact]
public void InputUpload_IsMultiple()
{
Expand Down
Loading