Skip to content

Commit a2a7b71

Browse files
authored
feat(Segmented): update style for segmented item (dotnetcore#2898)
* refactor: 精简代码 * doc: 更新注释 * refactor(Segmented): update style * refactor: 更新单元测试 * test: 更新单元测试
1 parent be32eeb commit a2a7b71

File tree

7 files changed

+19
-20
lines changed

7 files changed

+19
-20
lines changed

src/BootstrapBlazor/Components/Button/PopConfirmButtonBase.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public abstract class PopConfirmButtonBase : ButtonBase
6969
/// 获得/设置 点击确认弹窗前回调方法 返回真时弹出弹窗 返回假时不弹出 默认 null
7070
/// </summary>
7171
[Parameter]
72+
[NotNull]
7273
public Func<Task<bool>>? OnBeforeClick { get; set; }
7374

7475
/// <summary>

src/BootstrapBlazor/Components/Modal/ModalDialog.razor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public partial class ModalDialog : IHandlerException
165165
public RenderFragment? HeaderTemplate { get; set; }
166166

167167
/// <summary>
168-
/// 获得/设置 保存按钮回调委托
168+
/// 获得/设置 保存按钮回调委托 返回 true 并且设置 <see cref="IsAutoCloseAfterSave"/> true 时自动关闭弹窗
169169
/// </summary>
170170
[Parameter]
171171
public Func<Task<bool>>? OnSaveAsync { get; set; }

src/BootstrapBlazor/Components/Segmented/Segmented.razor.scss

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,16 @@
5151

5252
.segmented-item {
5353
padding: var(--bb-segmented-item-padding);
54-
text-align: center;
5554
cursor: pointer;
5655
border-radius: var(--bb-segmented-item-border-radius);
5756
line-height: var(--bb-segmented-item-height);
5857
font-size: var(--bb-segmented-item-font-size);
5958
position: relative;
6059
transition: color 0.2s cubic-bezier(0.645, 0.045, 0.355, 1);
6160
white-space: nowrap;
61+
display: flex;
62+
align-items: center;
63+
justify-content: center;
6264

6365
&.mask {
6466
background-color: var(--bb-segmented-item-selected-bg);
@@ -111,5 +113,5 @@
111113
}
112114

113115
[data-bs-theme='dark'] .segmented {
114-
--bb-segmented-item-selected-bg: rgba(var(--bs-body-color-rgb),.12);
116+
--bb-segmented-item-selected-bg: rgba(var(--bs-body-color-rgb),.12);
115117
}

src/BootstrapBlazor/Extensions/DialogServiceExtensions.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -207,12 +207,8 @@ public static async Task ShowSaveDialog<TComponent>(this DialogService service,
207207
ShowSaveButton = true,
208208
OnSaveAsync = saveCallback
209209
};
210-
Dictionary<string, object?>? parameters = null;
211-
if (parametersFactory != null)
212-
{
213-
parameters = [];
214-
parametersFactory.Invoke(parameters);
215-
}
210+
var parameters = new Dictionary<string, object?>();
211+
parametersFactory?.Invoke(parameters);
216212
option.Component = BootstrapDynamicComponent.CreateComponent<TComponent>(parameters);
217213
configureOption?.Invoke(option);
218214
await service.Show(option, dialog);
@@ -238,7 +234,6 @@ public static async Task ShowCloseDialog<TComponent>(this DialogService service,
238234
parametersFactory?.Invoke(parameters);
239235
option.Component = BootstrapDynamicComponent.CreateComponent<TComponent>(parameters);
240236
configureOption?.Invoke(option);
241-
242237
await service.Show(option, dialog);
243238
}
244239

test/UnitTest/Components/DisplayTest.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ public void FormatterAsync_Ok()
1414
{
1515
var cut = Context.RenderComponent<Display<string>>(pb =>
1616
{
17-
pb.Add(a => a.FormatterAsync, new Func<string, Task<string>>(v =>
17+
pb.Add(a => a.FormatterAsync, new Func<string, Task<string?>>(v =>
1818
{
19-
return Task.FromResult("FormattedValue");
19+
return Task.FromResult<string?>("FormattedValue");
2020
}));
2121
});
2222
Assert.Contains("FormattedValue", cut.Markup);
@@ -56,20 +56,20 @@ public void LookupService_Ok()
5656
[Fact]
5757
public void TypeResolver_Ok()
5858
{
59-
var cut = Context.RenderComponent<Display<DisplayTest.Fish[]>>(pb =>
59+
var cut = Context.RenderComponent<Display<Fish[]>>(pb =>
6060
{
61-
pb.Add(a => a.Value, new DisplayTest.Fish[] { new DisplayTest.Fish() { Value = "1" } });
62-
pb.Add(a => a.TypeResolver, new Func<Assembly, string, bool, Type>((assembly, typeName, ignoreCase) => typeof(DisplayTest.Fish)));
61+
pb.Add(a => a.Value, new Fish[] { new() { Value = "1" } });
62+
pb.Add(a => a.TypeResolver, new Func<Assembly, string, bool, Type>((assembly, typeName, ignoreCase) => typeof(Fish)));
6363
});
6464
Assert.Equal("<div class=\"form-control is-display\">1</div>", cut.Markup);
6565
}
6666

6767
[Fact]
6868
public void TypeResolver_Null()
6969
{
70-
var cut = Context.RenderComponent<Display<DisplayTest.Fish[]>>(pb =>
70+
var cut = Context.RenderComponent<Display<Fish[]>>(pb =>
7171
{
72-
pb.Add(a => a.Value, new DisplayTest.Fish[] { new DisplayTest.Fish() { Value = "1" } });
72+
pb.Add(a => a.Value, new Fish[] { new() { Value = "1" } });
7373
});
7474
Assert.Equal("<div class=\"form-control is-display\"></div>", cut.Markup);
7575
}

test/UnitTest/Components/TableTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6949,9 +6949,9 @@ public void Value_Formatter()
69496949
var col = cut.FindComponent<TableColumn<Foo, int>>();
69506950
col.SetParametersAndRender(pb =>
69516951
{
6952-
pb.Add(a => a.Formatter, new Func<object?, Task<string>>(obj =>
6952+
pb.Add(a => a.Formatter, new Func<object?, Task<string?>>(obj =>
69536953
{
6954-
return Task.FromResult("test-formatter");
6954+
return Task.FromResult<string?>("test-formatter");
69556955
}));
69566956
});
69576957
var table = cut.FindComponent<MockTable>();

test/UnitTest/Extensions/ITableColumnExtensionsTest.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ public void CopyValue_Ok()
7474
FormatString = "test-format",
7575
Formatter = obj =>
7676
{
77-
return Task.FromResult("test-formatter");
77+
var ret = "test-formatter";
78+
return Task.FromResult<string?>(ret);
7879
},
7980
HeaderTemplate = new RenderFragment<ITableColumn>(col => builder => builder.AddContent(0, "test-header")),
8081
OnCellRender = args => { },

0 commit comments

Comments
 (0)