From a2a7b714e81f919929cefdfe3a6247b041ecf9c9 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Sun, 4 Feb 2024 21:23:24 +0800 Subject: [PATCH] feat(Segmented): update style for segmented item (#2898) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor: 精简代码 * doc: 更新注释 * refactor(Segmented): update style * refactor: 更新单元测试 * test: 更新单元测试 --- .../Components/Button/PopConfirmButtonBase.cs | 1 + .../Components/Modal/ModalDialog.razor.cs | 2 +- .../Components/Segmented/Segmented.razor.scss | 6 ++++-- .../Extensions/DialogServiceExtensions.cs | 9 ++------- test/UnitTest/Components/DisplayTest.cs | 14 +++++++------- test/UnitTest/Components/TableTest.cs | 4 ++-- .../Extensions/ITableColumnExtensionsTest.cs | 3 ++- 7 files changed, 19 insertions(+), 20 deletions(-) diff --git a/src/BootstrapBlazor/Components/Button/PopConfirmButtonBase.cs b/src/BootstrapBlazor/Components/Button/PopConfirmButtonBase.cs index ada1bec3359..623de23331b 100644 --- a/src/BootstrapBlazor/Components/Button/PopConfirmButtonBase.cs +++ b/src/BootstrapBlazor/Components/Button/PopConfirmButtonBase.cs @@ -69,6 +69,7 @@ public abstract class PopConfirmButtonBase : ButtonBase /// 获得/设置 点击确认弹窗前回调方法 返回真时弹出弹窗 返回假时不弹出 默认 null /// [Parameter] + [NotNull] public Func>? OnBeforeClick { get; set; } /// diff --git a/src/BootstrapBlazor/Components/Modal/ModalDialog.razor.cs b/src/BootstrapBlazor/Components/Modal/ModalDialog.razor.cs index 7a537deef68..8073b72187c 100644 --- a/src/BootstrapBlazor/Components/Modal/ModalDialog.razor.cs +++ b/src/BootstrapBlazor/Components/Modal/ModalDialog.razor.cs @@ -165,7 +165,7 @@ public partial class ModalDialog : IHandlerException public RenderFragment? HeaderTemplate { get; set; } /// - /// 获得/设置 保存按钮回调委托 + /// 获得/设置 保存按钮回调委托 返回 true 并且设置 true 时自动关闭弹窗 /// [Parameter] public Func>? OnSaveAsync { get; set; } diff --git a/src/BootstrapBlazor/Components/Segmented/Segmented.razor.scss b/src/BootstrapBlazor/Components/Segmented/Segmented.razor.scss index a82fc0250ee..8a01fb4cfc8 100644 --- a/src/BootstrapBlazor/Components/Segmented/Segmented.razor.scss +++ b/src/BootstrapBlazor/Components/Segmented/Segmented.razor.scss @@ -51,7 +51,6 @@ .segmented-item { padding: var(--bb-segmented-item-padding); - text-align: center; cursor: pointer; border-radius: var(--bb-segmented-item-border-radius); line-height: var(--bb-segmented-item-height); @@ -59,6 +58,9 @@ position: relative; transition: color 0.2s cubic-bezier(0.645, 0.045, 0.355, 1); white-space: nowrap; + display: flex; + align-items: center; + justify-content: center; &.mask { background-color: var(--bb-segmented-item-selected-bg); @@ -111,5 +113,5 @@ } [data-bs-theme='dark'] .segmented { - --bb-segmented-item-selected-bg: rgba(var(--bs-body-color-rgb),.12); + --bb-segmented-item-selected-bg: rgba(var(--bs-body-color-rgb),.12); } diff --git a/src/BootstrapBlazor/Extensions/DialogServiceExtensions.cs b/src/BootstrapBlazor/Extensions/DialogServiceExtensions.cs index 7682849fb57..4adbf7620ac 100644 --- a/src/BootstrapBlazor/Extensions/DialogServiceExtensions.cs +++ b/src/BootstrapBlazor/Extensions/DialogServiceExtensions.cs @@ -207,12 +207,8 @@ public static async Task ShowSaveDialog(this DialogService service, ShowSaveButton = true, OnSaveAsync = saveCallback }; - Dictionary? parameters = null; - if (parametersFactory != null) - { - parameters = []; - parametersFactory.Invoke(parameters); - } + var parameters = new Dictionary(); + parametersFactory?.Invoke(parameters); option.Component = BootstrapDynamicComponent.CreateComponent(parameters); configureOption?.Invoke(option); await service.Show(option, dialog); @@ -238,7 +234,6 @@ public static async Task ShowCloseDialog(this DialogService service, parametersFactory?.Invoke(parameters); option.Component = BootstrapDynamicComponent.CreateComponent(parameters); configureOption?.Invoke(option); - await service.Show(option, dialog); } diff --git a/test/UnitTest/Components/DisplayTest.cs b/test/UnitTest/Components/DisplayTest.cs index fc9f53e7528..425d5d471f1 100644 --- a/test/UnitTest/Components/DisplayTest.cs +++ b/test/UnitTest/Components/DisplayTest.cs @@ -14,9 +14,9 @@ public void FormatterAsync_Ok() { var cut = Context.RenderComponent>(pb => { - pb.Add(a => a.FormatterAsync, new Func>(v => + pb.Add(a => a.FormatterAsync, new Func>(v => { - return Task.FromResult("FormattedValue"); + return Task.FromResult("FormattedValue"); })); }); Assert.Contains("FormattedValue", cut.Markup); @@ -56,10 +56,10 @@ public void LookupService_Ok() [Fact] public void TypeResolver_Ok() { - var cut = Context.RenderComponent>(pb => + var cut = Context.RenderComponent>(pb => { - pb.Add(a => a.Value, new DisplayTest.Fish[] { new DisplayTest.Fish() { Value = "1" } }); - pb.Add(a => a.TypeResolver, new Func((assembly, typeName, ignoreCase) => typeof(DisplayTest.Fish))); + pb.Add(a => a.Value, new Fish[] { new() { Value = "1" } }); + pb.Add(a => a.TypeResolver, new Func((assembly, typeName, ignoreCase) => typeof(Fish))); }); Assert.Equal("
1
", cut.Markup); } @@ -67,9 +67,9 @@ public void TypeResolver_Ok() [Fact] public void TypeResolver_Null() { - var cut = Context.RenderComponent>(pb => + var cut = Context.RenderComponent>(pb => { - pb.Add(a => a.Value, new DisplayTest.Fish[] { new DisplayTest.Fish() { Value = "1" } }); + pb.Add(a => a.Value, new Fish[] { new() { Value = "1" } }); }); Assert.Equal("
", cut.Markup); } diff --git a/test/UnitTest/Components/TableTest.cs b/test/UnitTest/Components/TableTest.cs index 952ac17c33c..0245619df1c 100644 --- a/test/UnitTest/Components/TableTest.cs +++ b/test/UnitTest/Components/TableTest.cs @@ -6949,9 +6949,9 @@ public void Value_Formatter() var col = cut.FindComponent>(); col.SetParametersAndRender(pb => { - pb.Add(a => a.Formatter, new Func>(obj => + pb.Add(a => a.Formatter, new Func>(obj => { - return Task.FromResult("test-formatter"); + return Task.FromResult("test-formatter"); })); }); var table = cut.FindComponent(); diff --git a/test/UnitTest/Extensions/ITableColumnExtensionsTest.cs b/test/UnitTest/Extensions/ITableColumnExtensionsTest.cs index 263f42b317e..bc7cdbb2804 100644 --- a/test/UnitTest/Extensions/ITableColumnExtensionsTest.cs +++ b/test/UnitTest/Extensions/ITableColumnExtensionsTest.cs @@ -74,7 +74,8 @@ public void CopyValue_Ok() FormatString = "test-format", Formatter = obj => { - return Task.FromResult("test-formatter"); + var ret = "test-formatter"; + return Task.FromResult(ret); }, HeaderTemplate = new RenderFragment(col => builder => builder.AddContent(0, "test-header")), OnCellRender = args => { },