Skip to content

Commit aa1e770

Browse files
committed
Merge branch 'main' into doc-home
2 parents d87aca7 + a65e246 commit aa1e770

File tree

15 files changed

+294
-81
lines changed

15 files changed

+294
-81
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,10 @@
152152
</div>
153153
</DemoBlock>
154154

155+
<DemoBlock Title="@Localizer["ToggleButton"]" Introduction="@Localizer["ToggleIntroduction"]" Name="Toggle">
156+
<ToggleButton Text="Toggle" Color="Color.Danger"></ToggleButton>
157+
</DemoBlock>
158+
155159
<AttributeTable Items="@GetAttributes()" />
156160

157161
<EventTable Items="@GetEvents()" />

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@
187187
Introduction="@Localizer["SortableListTableIntro"]"
188188
Name="Table">
189189
<SortableList Option="_optionTable" OnUpdate="OnUpdateTable">
190-
<Table TItem="Foo" Items="@Items" IsStriped="true" ShowLineNo="true">
190+
<Table TItem="Foo" Items="@Items" IsStriped="true" ShowLineNo="true" RenderMode="TableRenderMode.Table">
191191
<TableColumns>
192192
<TableColumn @bind-Field="@context.DateTime" Width="180" />
193193
<TableColumn @bind-Field="@context.Name" />

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2211,7 +2211,9 @@
22112211
"TooltipText": "Button",
22122212
"TooltipTitle": "Tooltip",
22132213
"TooltipIntro": "Set <code>TooltipText</code> <code>TooltipPlacement</code> <code>TooltipTrigger</code> shortcut button prompt bar information, position, and triggering method. For more functions, please use the <code>Tooltip</code> component to implement. In this example, the second button is in the <b>disabled</b> state, and the prompt bar is still available",
2214-
"TooltipDisabledText": "Disabled"
2214+
"TooltipDisabledText": "Disabled",
2215+
"ToggleButton": "Toggle",
2216+
"ToggleIntroduction": "Get the current button <code>Toggle</code> state by setting the <code>IsActiveChanged</code> or <code>OnToggleAsync</code> callback method"
22152217
},
22162218
"BootstrapBlazor.Server.Components.Samples.PulseButtons": {
22172219
"Block1Title": "Basic usage",

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2211,7 +2211,9 @@
22112211
"TooltipText": "按钮",
22122212
"TooltipTitle": "按钮提示栏",
22132213
"TooltipIntro": "通过设置 <code>TooltipText</code> <code>TooltipPlacement</code> <code>TooltipTrigger</code> 快捷设置按钮提示栏信息、位置、触发方式,更多功能请使用 <code>Tooltip</code> 组件实现,本例中第二个按钮是 <b>禁用</b> 状态,提示栏仍然可用",
2214-
"TooltipDisabledText": "禁用按钮"
2214+
"TooltipDisabledText": "禁用按钮",
2215+
"ToggleButton": "状态切换按钮",
2216+
"ToggleIntroduction": "通过设置 <code>IsActiveChanged</code> 或者 <code>OnToggleAsync</code> 回调方法获得当前按钮 <code>Toggle</code> 状态"
22152217
},
22162218
"BootstrapBlazor.Server.Components.Samples.PulseButtons": {
22172219
"Block1Title": "基础用法",

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>9.9.1-beta03</Version>
4+
<Version>9.9.1-beta05</Version>
55
</PropertyGroup>
66

77
<ItemGroup>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
@namespace BootstrapBlazor.Components
2+
@inherits ButtonBase
3+
4+
<button @attributes="@AdditionalAttributes" @onclick="@OnClickButton" id="@Id" class="@ToggleClassName" disabled="@Disabled"
5+
role="button" data-bs-placement="@PlacementString" data-bs-trigger="@TriggerString"
6+
aria-disabled="@DisabledString" tabindex="@Tab" data-bs-toggle="button"
7+
@onclick:stopPropagation="@StopPropagation">
8+
@if(IsAsyncLoading)
9+
{
10+
<i class="@LoadingIcon"></i>
11+
}
12+
else if (!string.IsNullOrEmpty(Icon))
13+
{
14+
<i class="@Icon"></i>
15+
}
16+
@if (!string.IsNullOrEmpty(Text))
17+
{
18+
<span>@Text</span>
19+
}
20+
<CascadingValue Value="this" IsFixed="true">
21+
@ChildContent
22+
</CascadingValue>
23+
</button>
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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([email protected]) Website: https://www.blazor.zone
5+
6+
namespace BootstrapBlazor.Components;
7+
8+
/// <summary>
9+
/// Toggle Button 按钮组件
10+
/// </summary>
11+
public partial class ToggleButton
12+
{
13+
/// <summary>
14+
/// 获得/设置 状态切换回调方法
15+
/// </summary>
16+
[Parameter]
17+
public Func<bool, Task>? OnToggleAsync { get; set; }
18+
19+
/// <summary>
20+
/// 获得/设置 当前状态是否为激活状态 默认 false
21+
/// </summary>
22+
[Parameter]
23+
public bool IsActive { get; set; }
24+
25+
/// <summary>
26+
/// 获得/设置 激活状态回调方法
27+
/// </summary>
28+
[Parameter]
29+
public EventCallback<bool> IsActiveChanged { get; set; }
30+
31+
private string? ToggleClassName => CssBuilder.Default(ClassName)
32+
.AddClass("active", IsActive)
33+
.Build();
34+
35+
private async Task OnClickButton()
36+
{
37+
if (IsAsync)
38+
{
39+
IsAsyncLoading = true;
40+
IsDisabled = true;
41+
}
42+
43+
await HandlerClick();
44+
45+
// 恢复按钮
46+
if (IsAsync)
47+
{
48+
IsDisabled = IsKeepDisabled;
49+
IsAsyncLoading = false;
50+
}
51+
}
52+
53+
private async Task HandlerClick()
54+
{
55+
IsActive = !IsActive;
56+
if (OnClickWithoutRender != null)
57+
{
58+
if (!IsAsync)
59+
{
60+
IsNotRender = true;
61+
}
62+
63+
await OnClickWithoutRender();
64+
}
65+
66+
if (OnClick.HasDelegate)
67+
{
68+
await OnClick.InvokeAsync();
69+
}
70+
71+
if (IsActiveChanged.HasDelegate)
72+
{
73+
await IsActiveChanged.InvokeAsync(IsActive);
74+
}
75+
76+
if (OnToggleAsync != null)
77+
{
78+
await OnToggleAsync(IsActive);
79+
}
80+
}
81+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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([email protected]) Website: https://www.blazor.zone
5+
6+
namespace BootstrapBlazor.Components;
7+
8+
/// <summary>
9+
/// SortableList 组件接口
10+
/// </summary>
11+
public interface ISortableList
12+
{
13+
14+
}

src/BootstrapBlazor/Components/Table/Table.razor

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@
243243
}
244244
else
245245
{
246-
<DynamicElement class="@GetRowClassString(item, "table-row")" @key="item"
246+
<DynamicElement class="@GetRowClassString(item, "table-row")" @key="GetKeyByITem(item)"
247247
TriggerContextMenu="ContextMenuZone != null" OnContextMenu="e => OnContextMenu(e, item)"
248248
@ontouchstart="e => OnTouchStart(e, item)"
249249
@ontouchend="OnTouchEnd"
@@ -692,7 +692,7 @@
692692
</thead>;
693693

694694
RenderFragment<TItem> RenderRow => item =>
695-
@<DynamicElement TagName="tr" class="@GetRowClassString(item)" @key="item"
695+
@<DynamicElement TagName="tr" class="@GetRowClassString(item)" @key="GetKeyByITem(item)"
696696
TriggerContextMenu="ContextMenuZone != null" OnContextMenu="e => OnContextMenu(e, item)"
697697
@ontouchstart="e => OnTouchStart(e, item)" @ontouchend="OnTouchEnd"
698698
TriggerClick="@(ClickToSelect || OnClickRowCallback != null)" OnClick="() => ClickRow(item)"

src/BootstrapBlazor/Components/Table/Table.razor.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,12 @@ private string GetSortTooltip(ITableColumn col) => SortName != col.GetFieldName(
198198
[Parameter]
199199
public bool ShowColumnWidthTooltip { get; set; }
200200

201+
///// <summary>
202+
///// 获得/设置 行 Key 回调方法
203+
///// </summary>
204+
//[Parameter]
205+
//public Func<TItem, object?>? OnGetRowKey { get; set; }
206+
201207
private string ScrollWidthString => $"width: {ActualScrollWidth}px;";
202208

203209
private string? GetScrollStyleString(bool condition) => condition
@@ -780,6 +786,9 @@ public async Task ExpandDetailRow(TItem item)
780786
[CascadingParameter]
781787
private ContextMenuZone? ContextMenuZone { get; set; }
782788

789+
[CascadingParameter]
790+
private ISortableList? SortableList { get; set; }
791+
783792
[Inject]
784793
[NotNull]
785794
private IIconTheme? IconTheme { get; set; }
@@ -1681,6 +1690,8 @@ private void OnTouchEnd()
16811690
TouchStart = false;
16821691
}
16831692

1693+
private object? GetKeyByITem(TItem item) => SortableList != null ? item : null; //OnGetRowKey?.Invoke(item);
1694+
16841695
/// <summary>
16851696
/// Dispose 方法
16861697
/// </summary>

0 commit comments

Comments
 (0)