Skip to content

Commit c98250e

Browse files
authored
feat(EditorForm): add EditorFormGroupType parameter (#7612)
* feat(EditorForm): add EditorFormGroupType parameter * doc: 增加示例 * test: 更新单元测试 * doc: 增加注释 * chore: bump version 10.3.1-beta03 * doc: 更新资源文件
1 parent 66ec4ce commit c98250e

File tree

10 files changed

+126
-4
lines changed

10 files changed

+126
-4
lines changed

src/BootstrapBlazor.Server/Components/Samples/EditorForms.razor

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,30 @@
149149
</GroupBox>
150150
</DemoBlock>
151151

152+
<DemoBlock Title="@Localizer["GroupTitle"]" Introduction="@Localizer["GroupIntro"]" Name="Group">
153+
<section ignore>
154+
<p>@((MarkupString)Localizer["GroupDescription"].Value)</p>
155+
<BootstrapInputGroup>
156+
<BootstrapInputGroupLabel DisplayText="GroupType"></BootstrapInputGroupLabel>
157+
<Segmented @bind-Value="_groupType">
158+
<SegmentedItem Text="GroupBox" Value="EditorFormGroupType.GroupBox" />
159+
<SegmentedItem Text="RowHeader" Value="EditorFormGroupType.RowHeader" />
160+
</Segmented>
161+
</BootstrapInputGroup>
162+
</section>
163+
<EditorForm Model="@Model" GroupType="_groupType">
164+
<FieldItems>
165+
<EditorItem @bind-Field="@context.Name" GroupOrder="1" GroupName="Group 1"></EditorItem>
166+
<EditorItem @bind-Field="@context.Address" GroupOrder="1" GroupName="Group 1"></EditorItem>
167+
<EditorItem @bind-Field="@context.DateTime" GroupOrder="2" GroupName="Group 1"></EditorItem>
168+
<EditorItem @bind-Field="@context.Count" GroupOrder="2" GroupName="Group 1"></EditorItem>
169+
<EditorItem @bind-Field="@context.Education" GroupOrder="3" GroupName="Group 2"></EditorItem>
170+
<EditorItem @bind-Field="@context.Complete" GroupOrder="3" GroupName="Group 2"></EditorItem>
171+
<EditorItem @bind-Field="@context.Hobby" Items="@Hobbies" GroupOrder="4" GroupName="Group 3"></EditorItem>
172+
</FieldItems>
173+
</EditorForm>
174+
</DemoBlock>
175+
152176
<AttributeTable Type="typeof(EditorForm<>)" />
153177

154178
<AttributeTable Type="typeof(EditorItem<,>)"></AttributeTable>

src/BootstrapBlazor.Server/Components/Samples/EditorForms.razor.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public sealed partial class EditorForms
2626
private IStringLocalizer<Foo>? FooLocalizer { get; set; }
2727

2828
private List<string> _ignoreItems = [];
29+
private EditorFormGroupType _groupType = EditorFormGroupType.GroupBox;
2930

3031
private Task OnSwitchIgnoreItems()
3132
{

src/BootstrapBlazor.Server/Locales/en-US.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2129,6 +2129,9 @@
21292129
"EditorFormTips3": "Complex edit columns, set up <code>EditTemplate</code> templates, and edit custom components",
21302130
"EditorFormTips4": "The buttons in the form can be set up multiplely, just set the buttons <code>Buttons</code> template",
21312131
"GroupBoxTitle": "An example of a form",
2132+
"GroupDescription": "Grouping is enabled by setting the <code>GroupName</code> parameter of the <code>EditorItem</code> component, and the order is controlled by <code>GroupOrder</code>.",
2133+
"GroupIntro": "The grouping format can be controlled by setting the <code>groupType</code> value.",
2134+
"GroupTitle": "Group",
21322135
"IgnoreItemsDescription": "This attribute has the same priority as the <code>Ignore</code> parameter in <code>EditorItem</code>. If it is set to ignore anywhere, it will not be rendered.",
21332136
"IgnoreItemsIntro": "By setting the <code>IgnoreItems</code> value, you can notify the component not to render the specified column in the collection.",
21342137
"IgnoreItemsSwitchButtonText": "Switch",

src/BootstrapBlazor.Server/Locales/zh-CN.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2129,6 +2129,9 @@
21292129
"EditorFormTips3": "复杂编辑列,设置 <code>EditTemplate</code> 模板,进行自定义组件进行编辑",
21302130
"EditorFormTips4": "表单内按钮可以设置多个,设置 <code>Buttons</code> 模板即可",
21312131
"GroupBoxTitle": "表单示例",
2132+
"GroupDescription": "通过设置 <code>EditorItem</code> 组件参数 <code>GroupName</code> 开启分组功能,通过 <code>GroupOrder</code> 控制顺序 ",
2133+
"GroupIntro": "通过设置 <code>GroupType</code> 值控制分组形式",
2134+
"GroupTitle": "分组功能",
21322135
"IgnoreItemsDescription": "此属性的优先级与 <code>EditorItem</code> 参数 <code>Ignore</code> 相同,任何一个地方设置了忽略,最终都不会渲染",
21332136
"IgnoreItemsIntro": "通过设置 <code>IgnoreItems</code> 值通知组件不渲染集合中的指定列",
21342137
"IgnoreItemsSwitchButtonText": "切换",

src/BootstrapBlazor/BootstrapBlazor.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Razor">
22

33
<PropertyGroup>
4-
<Version>10.3.1-beta02</Version>
4+
<Version>10.3.1-beta03</Version>
55
</PropertyGroup>
66

77
<ItemGroup>

src/BootstrapBlazor/Components/EditorForm/EditorForm.razor.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ namespace BootstrapBlazor.Components;
1616
public partial class EditorForm<TModel> : IShowLabel, IDisposable
1717
{
1818
private string? ClassString => CssBuilder.Default("bb-editor")
19+
.AddClass("bb-editor-group-row-header", GroupType == EditorFormGroupType.RowHeader)
1920
.AddClassFromAttributes(AdditionalAttributes)
2021
.Build();
2122

@@ -192,6 +193,13 @@ public partial class EditorForm<TModel> : IShowLabel, IDisposable
192193
[Parameter]
193194
public bool IsRenderWhenValueChanged { get; set; }
194195

196+
/// <summary>
197+
/// <para lang="zh">获得/设置 分组类型 默认 <see cref="EditorFormGroupType.GroupBox"/></para>
198+
/// <para lang="en">Gets or sets group type. Default is <see cref="EditorFormGroupType.GroupBox"/></para>
199+
/// </summary>
200+
[Parameter]
201+
public EditorFormGroupType GroupType { get; set; }
202+
195203
/// <summary>
196204
/// <para lang="zh">获得/设置 级联上下文 EditContext 实例 内置于 EditForm 或者 ValidateForm 时有值</para>
197205
/// <para lang="en">Gets or sets Cascading EditContext Instance. Available when inside EditForm or ValidateForm</para>

src/BootstrapBlazor/Components/EditorForm/EditorForm.razor.scss

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.bb-editor {
1+
.bb-editor {
22
position: relative;
33

44
.ef-loading {
@@ -9,4 +9,43 @@
99
bottom: 0;
1010
background-color: var(--bs-body-bg);
1111
}
12+
13+
&.bb-editor-group-row-header {
14+
.groupbox {
15+
--bb-groupbox-padding: 0;
16+
--bb-groupbox-legend-top: 0;
17+
--bb-groupbox-legend-left: 0;
18+
--bb-groupbox-divider-color: var(--bs-border-color);
19+
display: flex;
20+
flex-direction: row;
21+
flex-wrap: nowrap;
22+
align-items: center;
23+
border: 0;
24+
25+
.legend {
26+
writing-mode: vertical-rl;
27+
text-orientation: mixed;
28+
position: relative;
29+
color: var(--bb-groupbox-divider-color);
30+
}
31+
32+
.row {
33+
margin-inline-start: 1rem;
34+
flex: 1;
35+
width: 1%;
36+
min-width: 0;
37+
position: relative;
38+
39+
&::before {
40+
content: "";
41+
width: 1px;
42+
background-color: var(--bb-groupbox-divider-color);
43+
position: absolute;
44+
top: 1rem;
45+
bottom: 0;
46+
left: -0.5rem;
47+
}
48+
}
49+
}
50+
}
1251
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
@namespace BootstrapBlazor.Components
1+
@namespace BootstrapBlazor.Components
22
@inherits BootstrapComponentBase
33

44
<div @attributes="@AdditionalAttributes" class="@ClassString">
5-
<label class="legend">@Title</label>
5+
<span class="legend">@Title</span>
66
@ChildContent
77
</div>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the Apache 2.0 License
3+
// See the LICENSE file in the project root for more information.
4+
// Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone
5+
6+
namespace BootstrapBlazor.Components;
7+
8+
/// <summary>
9+
/// <para lang="zh">EditorForm 分组类型</para>
10+
/// <para lang="en">EditorForm group type</para>
11+
/// </summary>
12+
public enum EditorFormGroupType
13+
{
14+
/// <summary>
15+
/// <para lang="zh">使用 GroupBox 形式</para>
16+
/// <para lang="en">Group box</para>
17+
/// </summary>
18+
GroupBox,
19+
20+
/// <summary>
21+
/// <para lang="zh">使用 RowHeader 形式</para>
22+
/// <para lang="en">Row header</para>
23+
/// </summary>
24+
RowHeader,
25+
}

test/UnitTest/Components/EditorFormTest.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,25 @@ public void Buttons_Ok()
177177
});
178178
}
179179

180+
[Fact]
181+
public void GroupType_Ok()
182+
{
183+
var foo = new Foo();
184+
var cut = Context.Render<EditorForm<Foo>>(pb =>
185+
{
186+
pb.Add(a => a.Model, foo);
187+
pb.Add(a => a.GroupType, EditorFormGroupType.GroupBox);
188+
});
189+
190+
cut.DoesNotContain("bb-editor-group-row-header");
191+
192+
cut.Render(pb =>
193+
{
194+
pb.Add(a => a.GroupType, EditorFormGroupType.RowHeader);
195+
});
196+
cut.Contains("bb-editor-group-row-header");
197+
}
198+
180199
[Fact]
181200
public void Alignment_Right()
182201
{

0 commit comments

Comments
 (0)