diff --git a/src/BootstrapBlazor.Shared/Samples/PopoverConfirms.razor b/src/BootstrapBlazor.Shared/Samples/PopoverConfirms.razor index bba118cf6d2672c0d88ead3f07b9ef978c4b6c22..3c9c45a7f8bec5c6e816070fbccf6f37c6954d16 100644 --- a/src/BootstrapBlazor.Shared/Samples/PopoverConfirms.razor +++ b/src/BootstrapBlazor.Shared/Samples/PopoverConfirms.razor @@ -26,7 +26,7 @@ - + @@ -48,6 +48,11 @@ + + + + diff --git a/src/BootstrapBlazor.Shared/Samples/PopoverConfirms.razor.cs b/src/BootstrapBlazor.Shared/Samples/PopoverConfirms.razor.cs index ada0a0ba832e1fbe1cc9f788aa26de41c5e0ae8b..3eed4abd054ac83ee20b8d2e8209094ba1ecda29 100644 --- a/src/BootstrapBlazor.Shared/Samples/PopoverConfirms.razor.cs +++ b/src/BootstrapBlazor.Shared/Samples/PopoverConfirms.razor.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Website: https://www.blazor.zone or https://argozhang.github.io/ +using BootstrapBlazor.Components; using BootstrapBlazor.Shared.Common; using BootstrapBlazor.Shared.Components; using Microsoft.AspNetCore.Components.Forms; @@ -84,84 +85,91 @@ public sealed partial class PopoverConfirms /// private static IEnumerable GetAttributes() => new AttributeItem[] { - // TODO: 移动到数据库中 - new AttributeItem() { - Name = "Text", - Description = "显示标题", - Type = "string", - ValueList = "", - DefaultValue = "删除" - }, - new AttributeItem() { - Name = "Icon", - Description = "按钮图标", - Type = "string", - ValueList = "", - DefaultValue = "fa fa-remove" - }, - new AttributeItem() { - Name = "CloseButtonText", - Description = "关闭按钮显示文字", - Type = "string", - ValueList = "", - DefaultValue = "关闭" - }, - new AttributeItem() { - Name = "CloseButtonColor", - Description = "确认按钮颜色", - Type = "Color", - ValueList = "None / Active / Primary / Secondary / Success / Danger / Warning / Info / Light / Dark / Link", - DefaultValue = "Secondary" - }, - new AttributeItem() { - Name = "Color", - Description = "颜色", - Type = "Color", - ValueList = "None / Active / Primary / Secondary / Success / Danger / Warning / Info / Light / Dark / Link", - DefaultValue = "None" - }, - new AttributeItem() { - Name = "ConfirmButtonText", - Description = "确认按钮显示文字", - Type = "string", - ValueList = "", - DefaultValue = "确定" - }, - new AttributeItem() { - Name = "ConfirmButtonColor", - Description = "确认按钮颜色", - Type = "None / Active / Primary / Secondary / Success / Danger / Warning / Info / Light / Dark / Link", - ValueList = "", - DefaultValue = "Primary" - }, - new AttributeItem() { - Name = "ConfirmIcon", - Description = "确认框图标", - Type = "string", - ValueList = "", - DefaultValue = "fa fa-exclamation-circle text-info" - }, - new AttributeItem() { - Name = "Content", - Description = "显示文字", - Type = "string", - ValueList = "", - DefaultValue = "确认删除吗?" - }, - new AttributeItem() { - Name = "Placement", - Description = "位置", - Type = "Placement", - ValueList = "Auto / Top / Left / Bottom / Right", - DefaultValue = "Auto" - }, - new AttributeItem() { - Name = "Title", - Description = "Popover 弹窗标题", - Type = "string", - ValueList = "", - DefaultValue = " " - }, + // TODO: 移动到数据库中 + new AttributeItem() { + Name = nameof(PopConfirmButton.IsLink), + Description = "是否为 A 标签渲染组件", + Type = "bool", + ValueList = "true/false", + DefaultValue = "false" + }, + new AttributeItem() { + Name = "Text", + Description = "显示标题", + Type = "string", + ValueList = "", + DefaultValue = "删除" + }, + new AttributeItem() { + Name = "Icon", + Description = "按钮图标", + Type = "string", + ValueList = "", + DefaultValue = "fa fa-remove" + }, + new AttributeItem() { + Name = "CloseButtonText", + Description = "关闭按钮显示文字", + Type = "string", + ValueList = "", + DefaultValue = "关闭" + }, + new AttributeItem() { + Name = "CloseButtonColor", + Description = "确认按钮颜色", + Type = "Color", + ValueList = "None / Active / Primary / Secondary / Success / Danger / Warning / Info / Light / Dark / Link", + DefaultValue = "Secondary" + }, + new AttributeItem() { + Name = "Color", + Description = "颜色", + Type = "Color", + ValueList = "None / Active / Primary / Secondary / Success / Danger / Warning / Info / Light / Dark / Link", + DefaultValue = "None" + }, + new AttributeItem() { + Name = "ConfirmButtonText", + Description = "确认按钮显示文字", + Type = "string", + ValueList = "", + DefaultValue = "确定" + }, + new AttributeItem() { + Name = "ConfirmButtonColor", + Description = "确认按钮颜色", + Type = "None / Active / Primary / Secondary / Success / Danger / Warning / Info / Light / Dark / Link", + ValueList = "", + DefaultValue = "Primary" + }, + new AttributeItem() { + Name = "ConfirmIcon", + Description = "确认框图标", + Type = "string", + ValueList = "", + DefaultValue = "fa fa-exclamation-circle text-info" + }, + new AttributeItem() { + Name = "Content", + Description = "显示文字", + Type = "string", + ValueList = "", + DefaultValue = "确认删除吗?" + }, + new AttributeItem() { + Name = "Placement", + Description = "位置", + Type = "Placement", + ValueList = "Auto / Top / Left / Bottom / Right", + DefaultValue = "Auto" + }, + new AttributeItem() { + Name = "Title", + Description = "Popover 弹窗标题", + Type = "string", + ValueList = "", + DefaultValue = " " + } }; /// @@ -170,23 +178,23 @@ public sealed partial class PopoverConfirms /// private static IEnumerable GetEvents() => new EventItem[] { - new EventItem() - { - Name = "OnConfirm", - Description="点击确认时回调方法", - Type ="Func" - }, - new EventItem() - { - Name = "OnClose", - Description="点击关闭时回调方法", - Type ="Func" - }, - new EventItem() - { - Name = "OnBeforeClick", - Description="点击确认弹窗前回调方法 返回真时弹出弹窗 返回假时不弹出", - Type ="Func>" - }, + new EventItem() + { + Name = "OnConfirm", + Description="点击确认时回调方法", + Type ="Func" + }, + new EventItem() + { + Name = "OnClose", + Description="点击关闭时回调方法", + Type ="Func" + }, + new EventItem() + { + Name = "OnBeforeClick", + Description="点击确认弹窗前回调方法 返回真时弹出弹窗 返回假时不弹出", + Type ="Func>" + } }; } diff --git a/src/BootstrapBlazor/BootstrapBlazor.csproj b/src/BootstrapBlazor/BootstrapBlazor.csproj index ebcd3ad7d3a51966c8c62cb3b8417bb44606ea82..dd5152c34cea17a46eeb9bf36b1998b6c327bcce 100644 --- a/src/BootstrapBlazor/BootstrapBlazor.csproj +++ b/src/BootstrapBlazor/BootstrapBlazor.csproj @@ -1,7 +1,7 @@ - 6.4.1-beta03 + 6.4.1 diff --git a/src/BootstrapBlazor/Components/Button/PopConfirmButton.razor b/src/BootstrapBlazor/Components/Button/PopConfirmButton.razor index 69c1c1caa714b47b6bdd229fb7407c9c5890a3c9..d98bb8d5c8fed259be9b6990d44c8f3a39e3fe4c 100644 --- a/src/BootstrapBlazor/Components/Button/PopConfirmButton.razor +++ b/src/BootstrapBlazor/Components/Button/PopConfirmButton.razor @@ -1,7 +1,9 @@ @namespace BootstrapBlazor.Components @inherits PopConfirmButtonBase - + diff --git a/src/BootstrapBlazor/Components/Button/PopConfirmButton.razor.cs b/src/BootstrapBlazor/Components/Button/PopConfirmButton.razor.cs index 5f79dd0e8d1add6e042d55e2967ce6f8244f1de3..a0590d8bb8ec040794554f2767707d618cb6d689 100644 --- a/src/BootstrapBlazor/Components/Button/PopConfirmButton.razor.cs +++ b/src/BootstrapBlazor/Components/Button/PopConfirmButton.razor.cs @@ -26,15 +26,20 @@ public partial class PopConfirmButton private bool Submit { get; set; } /// - /// OnInitialized 方法 + /// OnParametersSet 方法 /// - protected override void OnInitialized() + protected override void OnParametersSet() { - base.OnInitialized(); + base.OnParametersSet(); ConfirmButtonText ??= Localizer[nameof(ConfirmButtonText)]; CloseButtonText ??= Localizer[nameof(CloseButtonText)]; Content ??= Localizer[nameof(Content)]; + + if (IsLink) + { + Color = Color.None; + } } /// @@ -74,11 +79,7 @@ public partial class PopConfirmButton Icon = ConfirmIcon, OnConfirm = Confirm, OnClose = OnClose, - Callback = async () => - { - // 调用 JS 进行弹窗 等待 弹窗点击确认回调 - await JSRuntime.InvokeVoidAsync(Id, "bb_confirm"); - } + Callback = async () => await JSRuntime.InvokeVoidAsync(Id, "bb_confirm") }); } } diff --git a/src/BootstrapBlazor/Components/Button/PopConfirmButtonBase.cs b/src/BootstrapBlazor/Components/Button/PopConfirmButtonBase.cs index af549c81754d7dac1e4fbb5ae238de5ddac4ba87..52882c1b3eb004300a37931122900e8f9171743f 100644 --- a/src/BootstrapBlazor/Components/Button/PopConfirmButtonBase.cs +++ b/src/BootstrapBlazor/Components/Button/PopConfirmButtonBase.cs @@ -11,6 +11,12 @@ namespace BootstrapBlazor.Components; /// public abstract class PopConfirmButtonBase : ButtonBase { + /// + /// 获得/设置 是否为 A 标签 默认 false 使用 button 渲染 + /// + [Parameter] + public bool IsLink { get; set; } + /// /// 获得/设置 弹窗显示位置 /// @@ -78,4 +84,14 @@ public abstract class PopConfirmButtonBase : ButtonBase /// [Parameter] public string ConfirmIcon { get; set; } = "fa fa-exclamation-circle text-info"; + + /// + /// + /// + protected string TagName => IsLink ? "a" : "button"; + + /// + /// + /// + protected string? ElementType => IsLink ? null : "button"; } diff --git a/test/UnitTest/Components/PopConfirmButtonTest.cs b/test/UnitTest/Components/PopConfirmButtonTest.cs index 0f7c9487319b9dde00569112c7f1d2ea4c8f1189..142b3708bc4ac1507385a2e82e8daba7dc276b24 100644 --- a/test/UnitTest/Components/PopConfirmButtonTest.cs +++ b/test/UnitTest/Components/PopConfirmButtonTest.cs @@ -105,5 +105,12 @@ public class PopConfirmButtonTest : PopoverTestBase // Confirm buttons = cut.FindAll(".popover-confirm-buttons button"); cut.InvokeAsync(() => buttons[1].Click()); + + // IsLink + popButton.SetParametersAndRender(pb => + { + pb.Add(a => a.IsLink, true); + }); + Assert.Contains("a data-bs-toggle=\"confirm\"", popButton.Markup); } }