Skip to content

Commit

Permalink
feat(PopConfirmButton): add CloseButtonIcon/ConfirmButtonIcon paramet…
Browse files Browse the repository at this point in the history
…er (#5455)

* refactor: 精简代码

* refactor: 移除 dismiss 处理方法

* chore: 更新图标

* feat: 增加弹窗内按钮图标参数

* chore: 增加按钮图标参数

* test: 增加单元测试

* test: 更新单元测试

* chore: bump version 9.4.0

* chore: bump version 9.4.0
  • Loading branch information
ArgoZhang authored Feb 27, 2025
1 parent c174ff7 commit 441532b
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 60 deletions.
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.3.1-beta39</Version>
<Version>9.4.0</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/BootstrapBlazor/Components/Button/PopConfirmButton.razor
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ else
@ChildContent
</CascadingValue>
<PopConfirmButtonContent Title="@Title" Content="@Content" Icon="@ConfirmIcon"
CloseButtonColor="@CloseButtonColor" CloseButtonText="@CloseButtonText"
ConfirmButtonColor="@ConfirmButtonColor" ConfirmButtonText="@ConfirmButtonText"
CloseButtonColor="@CloseButtonColor" CloseButtonText="@CloseButtonText" CloseButtonIcon="@CloseButtonIcon"
ConfirmButtonColor="@ConfirmButtonColor" ConfirmButtonText="@ConfirmButtonText" ConfirmButtonIcon="@ConfirmButtonIcon"
ShowCloseButton="@ShowCloseButton" OnClose="@OnClose"
ShowConfirmButton="@ShowConfirmButton" OnConfirm="@OnClickConfirm" ChildContent="@BodyTemplate" />
</DynamicElement>;
Expand Down
12 changes: 12 additions & 0 deletions src/BootstrapBlazor/Components/Button/PopConfirmButtonBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ public abstract class PopConfirmButtonBase : ButtonBase
[NotNull]
public string? CloseButtonText { get; set; }

/// <summary>
/// 获得/设置 关闭按钮显示图标
/// </summary>
[Parameter]
public string? CloseButtonIcon { get; set; }

/// <summary>
/// 获得/设置 确认按钮显示文字 默认为 确定
/// </summary>
Expand All @@ -118,6 +124,12 @@ public abstract class PopConfirmButtonBase : ButtonBase
[Parameter]
public Color ConfirmButtonColor { get; set; } = Color.Primary;

/// <summary>
/// 获得/设置 确认按钮显示图标
/// </summary>
[Parameter]
public string? ConfirmButtonIcon { get; set; }

/// <summary>
/// 获得/设置 确认框图标
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,17 @@
<div class="popover-confirm-buttons">
@if (ShowCloseButton)
{
<div class="@CloseButtonClass" @onclick="@OnCloseClick">
<button class="@CloseButtonClass" @onclick="@OnCloseClick">
<i class="@CloseButtonIcon"></i>
<span>@CloseButtonText</span>
</div>
</button>
}
@if (ShowConfirmButton)
{
<div class="@ConfirmButtonClass" @onclick="@OnConfirmClick">
<button class="@ConfirmButtonClass" @onclick="@OnConfirmClick">
<i class="@ConfirmButtonIcon"></i>
<span>@ConfirmButtonText</span>
</div>
</button>
}
</div>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ public partial class PopConfirmButtonContent
[Parameter]
public RenderFragment? ChildContent { get; set; }

/// <summary>
/// 获得/设置 关闭按钮显示图标
/// </summary>
[Parameter]
public string? CloseButtonIcon { get; set; }

/// <summary>
/// 获得/设置 关闭按钮显示文字
/// </summary>
Expand All @@ -71,6 +77,12 @@ public partial class PopConfirmButtonContent
[Parameter]
public Color CloseButtonColor { get; set; } = Color.Secondary;

/// <summary>
/// 获得/设置 确认按钮显示图标
/// </summary>
[Parameter]
public string? ConfirmButtonIcon { get; set; }

/// <summary>
/// 获得/设置 确认按钮显示文字
/// </summary>
Expand All @@ -87,7 +99,6 @@ public partial class PopConfirmButtonContent
/// 获得/设置 确认框图标
/// </summary>
[Parameter]
[NotNull]
public string? Icon { get; set; }

/// <summary>
Expand All @@ -114,6 +125,8 @@ protected override void OnParametersSet()
base.OnParametersSet();

Icon ??= IconTheme.GetIconByKey(ComponentIcons.PopConfirmButtonConfirmIcon);
CloseButtonIcon ??= IconTheme.GetIconByKey(ComponentIcons.PopConfirmButtonContentCloseButtonIcon);
ConfirmButtonIcon ??= IconTheme.GetIconByKey(ComponentIcons.PopConfirmButtonContentConfirmButtonIcon);
}

/// <summary>
Expand Down
10 changes: 10 additions & 0 deletions src/BootstrapBlazor/Enums/ComponentIcons.cs
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,16 @@ public enum ComponentIcons
/// </summary>
PopConfirmButtonConfirmIcon,

/// <summary>
/// PopConfirmButton 组件弹窗中 CloseButtonIcon 图标
/// </summary>
PopConfirmButtonContentCloseButtonIcon,

/// <summary>
/// PopConfirmButton 组件弹窗中 ConfirmButtonIcon 图标
/// </summary>
PopConfirmButtonContentConfirmButtonIcon,

/// <summary>
/// Rate 组件 StarIcon 图标
/// </summary>
Expand Down
4 changes: 3 additions & 1 deletion src/BootstrapBlazor/Icons/BootstrapIcons.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ internal static class BootstrapIcons
{ ComponentIcons.PaginationPrevEllipsisPageIcon, "bi bi-three-dots" },
{ ComponentIcons.PaginationNextEllipsisPageIcon, "bi bi-three-dots" },

{ ComponentIcons.PopConfirmButtonConfirmIcon, "bi bi-exclamation-circle" },
{ ComponentIcons.PopConfirmButtonConfirmIcon, "bi bi-exclamation-circle-fill" },
{ ComponentIcons.PopConfirmButtonContentCloseButtonIcon, "bi bi-x" },
{ ComponentIcons.PopConfirmButtonContentConfirmButtonIcon, "bi bi-check" },

{ ComponentIcons.RateStarIcon, "bi bi-star-fill" },
{ ComponentIcons.RateUnStarIcon, "bi bi-star" },
Expand Down
2 changes: 2 additions & 0 deletions src/BootstrapBlazor/Icons/FontAwesomeIcons.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ internal static class FontAwesomeIcons
{ ComponentIcons.PaginationNextEllipsisPageIcon, "fa-solid fa-ellipsis" },

{ ComponentIcons.PopConfirmButtonConfirmIcon, "fa-solid fa-circle-exclamation" },
{ ComponentIcons.PopConfirmButtonContentCloseButtonIcon, "fa-solid fa-xmark" },
{ ComponentIcons.PopConfirmButtonContentConfirmButtonIcon, "fa-solid fa-check" },

{ ComponentIcons.RateStarIcon, "fa-solid fa-star" },
{ ComponentIcons.RateUnStarIcon, "fa-regular fa-star" },
Expand Down
4 changes: 3 additions & 1 deletion src/BootstrapBlazor/Icons/MaterialDesignIcons.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ internal static class MaterialDesignIcons
{ ComponentIcons.PaginationPrevEllipsisPageIcon, "mdi mdi-dots-horizontal" },
{ ComponentIcons.PaginationNextEllipsisPageIcon, "mdi mdi-dots-horizontal" },

{ ComponentIcons.PopConfirmButtonConfirmIcon, "mdi mdi-exclamation" },
{ ComponentIcons.PopConfirmButtonConfirmIcon, "mdi mdi-alert-circle" },
{ ComponentIcons.PopConfirmButtonContentCloseButtonIcon, "mdi mdi-close" },
{ ComponentIcons.PopConfirmButtonContentConfirmButtonIcon, "mdi mdi-check" },

{ ComponentIcons.RateStarIcon, "mdi mdi-star" },
{ ComponentIcons.RateUnStarIcon, "mdi mdi-star-outline" },
Expand Down
23 changes: 15 additions & 8 deletions test/UnitTest/Components/PopConfirmButtonTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,14 @@ public async Task Show_Ok()
pb.Add(a => a.ConfirmButtonColor, Color.Danger);
pb.Add(a => a.Icon, "fa-solid fa-font-awesome");
pb.Add(a => a.Text, "Test_Text");
pb.Add(a => a.CloseButtonIcon, "fa-solid fa-xmark");
pb.Add(a => a.ConfirmButtonIcon, "fa-solid fa-check");
});
});

cut.Contains("fa-solid fa-xmark");
cut.Contains("fa-solid fa-check");

// Show
var button = cut.Find("div");
await cut.InvokeAsync(() =>
Expand All @@ -33,7 +38,7 @@ await cut.InvokeAsync(() =>
});

// Close
var buttons = cut.FindAll(".popover-confirm-buttons div");
var buttons = cut.FindAll(".popover-confirm-buttons button");
await cut.InvokeAsync(() =>
{
buttons[0].Click();
Expand All @@ -45,7 +50,7 @@ await cut.InvokeAsync(() =>
{
button.Click();
});
buttons = cut.FindAll(".popover-confirm-buttons div");
buttons = cut.FindAll(".popover-confirm-buttons button");
await cut.InvokeAsync(() =>
{
buttons[1].Click();
Expand Down Expand Up @@ -97,7 +102,7 @@ await cut.InvokeAsync(() =>
});

// Close
buttons = cut.FindAll(".popover-confirm-buttons div");
buttons = cut.FindAll(".popover-confirm-buttons button");
await cut.InvokeAsync(() =>
{
buttons[0].Click();
Expand All @@ -111,7 +116,7 @@ await cut.InvokeAsync(() =>
{
button.Click();
});
buttons = cut.FindAll(".popover-confirm-buttons div");
buttons = cut.FindAll(".popover-confirm-buttons button");
await cut.InvokeAsync(() =>
{
buttons[1].Click();
Expand All @@ -132,7 +137,7 @@ await cut.InvokeAsync(() =>
});

// Confirm
buttons = cut.FindAll(".popover-confirm-buttons div");
buttons = cut.FindAll(".popover-confirm-buttons button");
await cut.InvokeAsync(() =>
{
buttons[1].Click();
Expand All @@ -158,7 +163,7 @@ await cut.InvokeAsync(() =>
});

// async confirm
buttons = cut.FindAll(".popover-confirm-buttons div");
buttons = cut.FindAll(".popover-confirm-buttons button");
_ = cut.InvokeAsync(() =>
{
buttons[1].Click();
Expand All @@ -178,7 +183,7 @@ await cut.InvokeAsync(() =>
});

// async confirm
buttons = cut.FindAll(".popover-confirm-buttons div");
buttons = cut.FindAll(".popover-confirm-buttons button");
await cut.InvokeAsync(() =>
{
buttons[1].Click();
Expand Down Expand Up @@ -248,10 +253,12 @@ public void Trigger_Ok()
}

[Fact]
public void ConfirmIcon_Ok()
public void Icon_Ok()
{
var cut = Context.RenderComponent<PopConfirmButtonContent>();
cut.Contains("text-info fa-solid fa-circle-exclamation");
cut.Contains("fa-solid fa-xmark");
cut.Contains("fa-solid fa-check");
}

[Fact]
Expand Down
43 changes: 1 addition & 42 deletions test/UnitTest/Components/TableTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5538,49 +5538,8 @@ public async Task OnAfterCancelSaveAsync_EditForm()
await cut.InvokeAsync(() => button[0].Click());

// 取消按钮
var cancelButton = cut.Find(".form-footer .btn-secondary");
await cut.InvokeAsync(() => cancelButton.Click());
Assert.True(afterCancelSave);
}

[Fact]
public async Task OnAfterCancelSaveAsync_InCell()
{
var localizer = Context.Services.GetRequiredService<IStringLocalizer<Foo>>();
var items = Foo.GenerateFoo(localizer, 2);
var afterCancelSave = false;
var cut = Context.RenderComponent<BootstrapBlazorRoot>(pb =>
{
pb.AddChildContent<Table<Foo>>(pb =>
{
pb.Add(a => a.RenderMode, TableRenderMode.Table);
pb.Add(a => a.Items, items);
pb.Add(a => a.IsMultipleSelect, true);
pb.Add(a => a.ShowToolbar, true);
pb.Add(a => a.ShowExtendButtons, true);
pb.Add(a => a.EditMode, EditMode.EditForm);
pb.Add(a => a.OnAfterCancelSaveAsync, () =>
{
afterCancelSave = true;
return Task.CompletedTask;
});
pb.Add(a => a.TableColumns, foo => builder =>
{
builder.OpenComponent<TableColumn<Foo, string>>(0);
builder.AddAttribute(1, "Field", "Name");
builder.AddAttribute(2, "FieldExpression", Utility.GenerateValueExpression(foo, "Name", typeof(string)));
builder.CloseComponent();
});
});
});

// test edit button
var button = cut.FindAll("tbody tr button");
button = cut.FindAll("tbody tr.is-editform button");
await cut.InvokeAsync(() => button[0].Click());

// 取消按钮
button = cut.FindAll("tbody tr button");
await cut.InvokeAsync(() => button[1].Click());
Assert.True(afterCancelSave);
}

Expand Down

0 comments on commit 441532b

Please sign in to comment.