Skip to content

Commit

Permalink
feat(Segmented): update style for segmented item (#2898)
Browse files Browse the repository at this point in the history
* refactor: 精简代码

* doc: 更新注释

* refactor(Segmented): update style

* refactor: 更新单元测试

* test: 更新单元测试
  • Loading branch information
ArgoZhang authored Feb 4, 2024
1 parent be32eeb commit a2a7b71
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public abstract class PopConfirmButtonBase : ButtonBase
/// 获得/设置 点击确认弹窗前回调方法 返回真时弹出弹窗 返回假时不弹出 默认 null
/// </summary>
[Parameter]
[NotNull]
public Func<Task<bool>>? OnBeforeClick { get; set; }

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/BootstrapBlazor/Components/Modal/ModalDialog.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public partial class ModalDialog : IHandlerException
public RenderFragment? HeaderTemplate { get; set; }

/// <summary>
/// 获得/设置 保存按钮回调委托
/// 获得/设置 保存按钮回调委托 返回 true 并且设置 <see cref="IsAutoCloseAfterSave"/> true 时自动关闭弹窗
/// </summary>
[Parameter]
public Func<Task<bool>>? OnSaveAsync { get; set; }
Expand Down
6 changes: 4 additions & 2 deletions src/BootstrapBlazor/Components/Segmented/Segmented.razor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,16 @@

.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);
font-size: var(--bb-segmented-item-font-size);
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);
Expand Down Expand Up @@ -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);
}
9 changes: 2 additions & 7 deletions src/BootstrapBlazor/Extensions/DialogServiceExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,12 +207,8 @@ public static async Task ShowSaveDialog<TComponent>(this DialogService service,
ShowSaveButton = true,
OnSaveAsync = saveCallback
};
Dictionary<string, object?>? parameters = null;
if (parametersFactory != null)
{
parameters = [];
parametersFactory.Invoke(parameters);
}
var parameters = new Dictionary<string, object?>();
parametersFactory?.Invoke(parameters);
option.Component = BootstrapDynamicComponent.CreateComponent<TComponent>(parameters);
configureOption?.Invoke(option);
await service.Show(option, dialog);
Expand All @@ -238,7 +234,6 @@ public static async Task ShowCloseDialog<TComponent>(this DialogService service,
parametersFactory?.Invoke(parameters);
option.Component = BootstrapDynamicComponent.CreateComponent<TComponent>(parameters);
configureOption?.Invoke(option);

await service.Show(option, dialog);
}

Expand Down
14 changes: 7 additions & 7 deletions test/UnitTest/Components/DisplayTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ public void FormatterAsync_Ok()
{
var cut = Context.RenderComponent<Display<string>>(pb =>
{
pb.Add(a => a.FormatterAsync, new Func<string, Task<string>>(v =>
pb.Add(a => a.FormatterAsync, new Func<string, Task<string?>>(v =>
{
return Task.FromResult("FormattedValue");
return Task.FromResult<string?>("FormattedValue");
}));
});
Assert.Contains("FormattedValue", cut.Markup);
Expand Down Expand Up @@ -56,20 +56,20 @@ public void LookupService_Ok()
[Fact]
public void TypeResolver_Ok()
{
var cut = Context.RenderComponent<Display<DisplayTest.Fish[]>>(pb =>
var cut = Context.RenderComponent<Display<Fish[]>>(pb =>
{
pb.Add(a => a.Value, new DisplayTest.Fish[] { new DisplayTest.Fish() { Value = "1" } });
pb.Add(a => a.TypeResolver, new Func<Assembly, string, bool, Type>((assembly, typeName, ignoreCase) => typeof(DisplayTest.Fish)));
pb.Add(a => a.Value, new Fish[] { new() { Value = "1" } });
pb.Add(a => a.TypeResolver, new Func<Assembly, string, bool, Type>((assembly, typeName, ignoreCase) => typeof(Fish)));
});
Assert.Equal("<div class=\"form-control is-display\">1</div>", cut.Markup);
}

[Fact]
public void TypeResolver_Null()
{
var cut = Context.RenderComponent<Display<DisplayTest.Fish[]>>(pb =>
var cut = Context.RenderComponent<Display<Fish[]>>(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("<div class=\"form-control is-display\"></div>", cut.Markup);
}
Expand Down
4 changes: 2 additions & 2 deletions test/UnitTest/Components/TableTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6949,9 +6949,9 @@ public void Value_Formatter()
var col = cut.FindComponent<TableColumn<Foo, int>>();
col.SetParametersAndRender(pb =>
{
pb.Add(a => a.Formatter, new Func<object?, Task<string>>(obj =>
pb.Add(a => a.Formatter, new Func<object?, Task<string?>>(obj =>
{
return Task.FromResult("test-formatter");
return Task.FromResult<string?>("test-formatter");
}));
});
var table = cut.FindComponent<MockTable>();
Expand Down
3 changes: 2 additions & 1 deletion test/UnitTest/Extensions/ITableColumnExtensionsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string?>(ret);
},
HeaderTemplate = new RenderFragment<ITableColumn>(col => builder => builder.AddContent(0, "test-header")),
OnCellRender = args => { },
Expand Down

0 comments on commit a2a7b71

Please sign in to comment.