Skip to content

Commit 6af62a5

Browse files
authored
feat(BootstrapInputGroupLabel): redesign IsInputGroupLabel logic (#5172)
* doc: 代码格式化 * refactor: 精简逻辑 * refactor: 重构逻辑提高可读性 * test: 更新单元测试 * Revert "refactor: 精简逻辑" This reverts commit b2265dd. * revert: 撤销更改 * test: 更新单元测试
1 parent 1c0f564 commit 6af62a5

File tree

3 files changed

+30
-32
lines changed

3 files changed

+30
-32
lines changed

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

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,64 +11,64 @@
1111
<div class="row g-3">
1212
<div class="col-12 col-md-6 col-lg-4 xl-3">
1313
<BootstrapInputGroup>
14-
<BootstrapInputGroupLabel DisplayText="CurrentValue" />
15-
<BootstrapInput @bind-Value="@CurrentValue" />
14+
<BootstrapInputGroupLabel DisplayText="CurrentValue"></BootstrapInputGroupLabel>
15+
<BootstrapInput @bind-Value="@CurrentValue"></BootstrapInput>
1616
</BootstrapInputGroup>
1717
</div>
1818
<div class="col-12 col-md-6 col-lg-4 xl-3">
1919
<BootstrapInputGroup>
20-
<BootstrapInputGroupLabel DisplayText="MinValue" />
21-
<BootstrapInput @bind-Value="@MinValue" />
20+
<BootstrapInputGroupLabel DisplayText="MinValue"></BootstrapInputGroupLabel>
21+
<BootstrapInput @bind-Value="@MinValue"></BootstrapInput>
2222
</BootstrapInputGroup>
2323
</div>
2424
<div class="col-12 col-md-6 col-lg-4 xl-3">
2525
<BootstrapInputGroup>
26-
<BootstrapInputGroupLabel DisplayText="MaxValue" />
27-
<BootstrapInput @bind-Value="@MaxValue" />
26+
<BootstrapInputGroupLabel DisplayText="MaxValue"></BootstrapInputGroupLabel>
27+
<BootstrapInput @bind-Value="@MaxValue"></BootstrapInput>
2828
</BootstrapInputGroup>
2929
</div>
3030
<div class="col-12 col-md-6 col-lg-4 xl-3">
3131
<BootstrapInputGroup>
32-
<BootstrapInputGroupLabel DisplayText="DisplayText" />
33-
<BootstrapInput @bind-Value="@DisplayText" />
32+
<BootstrapInputGroupLabel DisplayText="DisplayText"></BootstrapInputGroupLabel>
33+
<BootstrapInput @bind-Value="@DisplayText"></BootstrapInput>
3434
</BootstrapInputGroup>
3535
</div>
3636
<div class="col-12 col-md-6 col-lg-4 xl-3">
3737
<BootstrapInputGroup>
38-
<BootstrapInputGroupLabel DisplayText="Step" />
39-
<BootstrapInput @bind-Value="@Step" />
38+
<BootstrapInputGroupLabel DisplayText="Step"></BootstrapInputGroupLabel>
39+
<BootstrapInput @bind-Value="@Step"></BootstrapInput>
4040
</BootstrapInputGroup>
4141
</div>
4242
<div class="col-12 col-md-6 col-lg-4 xl-3">
4343
<BootstrapInputGroup>
44-
<BootstrapInputGroupLabel DisplayText="IsDisabled" />
45-
<Checkbox @bind-Value="@IsDisabled" />
44+
<BootstrapInputGroupLabel DisplayText="IsDisabled"></BootstrapInputGroupLabel>
45+
<Checkbox @bind-Value="@IsDisabled"></Checkbox>
4646
</BootstrapInputGroup>
4747
</div>
4848
<div class="col-12 col-md-6 col-lg-4 xl-3">
4949
<BootstrapInputGroup>
50-
<BootstrapInputGroupLabel DisplayText="UseInput" />
51-
<Checkbox @bind-Value="@UseInput" />
50+
<BootstrapInputGroupLabel DisplayText="UseInput"></BootstrapInputGroupLabel>
51+
<Checkbox @bind-Value="@UseInput"></Checkbox>
5252
</BootstrapInputGroup>
5353
</div>
5454
<div class="col-12 col-md-6 col-lg-4 xl-3">
5555
<BootstrapInputGroup>
56-
<BootstrapInputGroupLabel DisplayText="ShowLabel" />
57-
<Checkbox @bind-Value="@ShowLabel" />
56+
<BootstrapInputGroupLabel DisplayText="ShowLabel"></BootstrapInputGroupLabel>
57+
<Checkbox @bind-Value="@ShowLabel"></Checkbox>
5858
</BootstrapInputGroup>
5959
</div>
6060
<div class="col-12 col-md-6 col-lg-4 xl-3">
6161
<BootstrapInputGroup>
62-
<BootstrapInputGroupLabel DisplayText="UseGroup" />
63-
<Checkbox @bind-Value="@UseGroup" />
62+
<BootstrapInputGroupLabel DisplayText="UseGroup"></BootstrapInputGroupLabel>
63+
<Checkbox @bind-Value="@UseGroup"></Checkbox>
6464
</BootstrapInputGroup>
6565
</div>
6666
</div>
6767
</section>
6868
@if (UseGroup)
6969
{
7070
<BootstrapInputGroup>
71-
<BootstrapInputGroupLabel DisplayText="@DisplayText" />
71+
<BootstrapInputGroupLabel DisplayText="@DisplayText" Width="100"></BootstrapInputGroupLabel>
7272
<Slider @bind-Value="@CurrentValue" Max="MaxValue" Min="MinValue" Step="Step" UseInputEvent="UseInput"
7373
DisplayText="@DisplayText" ShowLabel="ShowLabel" IsDisabled="IsDisabled" OnValueChanged="OnRangeSliderValueChanged"></Slider>
7474
</BootstrapInputGroup>
@@ -79,7 +79,7 @@
7979
DisplayText="@DisplayText" ShowLabel="ShowLabel" IsDisabled="IsDisabled" OnValueChanged="OnRangeSliderValueChanged"></Slider>
8080
}
8181
<section ignore>
82-
<ConsoleLogger @ref="Logger" />
82+
<ConsoleLogger @ref="Logger"></ConsoleLogger>
8383
</section>
8484
</DemoBlock>
8585

@@ -102,6 +102,6 @@
102102
</div>
103103
</DemoBlock>
104104

105-
<AttributeTable Items="@GetAttributes()" />
105+
<AttributeTable Items="@GetAttributes()"></AttributeTable>
106106

107-
<EventTable Items="@GetEvents()" />
107+
<EventTable Items="@GetEvents()"></EventTable>
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
@namespace BootstrapBlazor.Components
22
@inherits DisplayBase<string>
33

4-
@if (IsInnerLabel)
4+
@if (IsInputGroupLabel)
55
{
6-
<div @attributes="@AdditionalAttributes" class="@ClassString" required="@Required" style="@StyleString">
6+
<div @attributes="@AdditionalAttributes" class="@ClassString" style="@StyleString" required="@Required">
77
<span>@DisplayText</span>
88
</div>
99
}
1010
else
1111
{
12-
<label @attributes="@AdditionalAttributes" class="@ClassString" required="@Required">@DisplayText</label>
12+
<label @attributes="@AdditionalAttributes" class="@ClassString" style="@StyleString" required="@Required">@DisplayText</label>
1313
}

src/BootstrapBlazor/Components/Input/BootstrapInputGroupLabel.razor.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ namespace BootstrapBlazor.Components;
1111
public partial class BootstrapInputGroupLabel
1212
{
1313
private string? ClassString => CssBuilder.Default()
14-
.AddClass("input-group-text", IsInnerLabel)
15-
.AddClass("form-label", !IsInnerLabel)
14+
.AddClass("input-group-text", IsInputGroupLabel)
15+
.AddClass("form-label", !IsInputGroupLabel)
1616
.AddClass("justify-content-center", Alignment == Alignment.Center)
1717
.AddClass("justify-content-end", Alignment == Alignment.Right)
1818
.AddClassFromAttributes(AdditionalAttributes)
@@ -23,8 +23,6 @@ public partial class BootstrapInputGroupLabel
2323
.AddClassFromAttributes(AdditionalAttributes)
2424
.Build();
2525

26-
private bool IsInnerLabel { get; set; }
27-
2826
/// <summary>
2927
/// 获得/设置 标签宽度 默认 null 未设置自动适应
3028
/// </summary>
@@ -45,16 +43,16 @@ public partial class BootstrapInputGroupLabel
4543

4644
private string? Required => ShowRequiredMark ? "true" : null;
4745

46+
private bool IsInputGroupLabel => InputGroup != null;
47+
4848
/// <summary>
4949
/// OnParametersSet 方法
5050
/// </summary>
5151
protected override void OnParametersSet()
5252
{
5353
base.OnParametersSet();
5454

55-
IsInnerLabel = InputGroup != null;
56-
57-
if (IsInnerLabel)
55+
if (IsInputGroupLabel)
5856
{
5957
DisplayText ??= FieldIdentifier?.GetDisplayName();
6058
}

0 commit comments

Comments
 (0)