Skip to content

Commit 375d4a2

Browse files
authored
feat(Split): add SetLeftWidth method (#4818)
* feat: 增加 SetLeftWidth 方法 * chore: 增加脚本支持 * doc: 更新文档 * doc: 增加本地化 * test: 增加单元测试 * chore: bump version 9.1.3-beta04
1 parent 4dde0d5 commit 375d4a2

File tree

9 files changed

+58
-5
lines changed

9 files changed

+58
-5
lines changed

src/BootstrapBlazor.Shared/Components/Samples/Splits.razor

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,24 @@
122122
</div>
123123
</DemoBlock>
124124

125+
<DemoBlock Title="@Localizer["SplitSetLeftTitle"]"
126+
Introduction="@Localizer["SplitSetLeftIntro"]"
127+
Name="SetLeft">
128+
<section ignore>
129+
<Button Text="25%" OnClickWithoutRender="@(async () => await OnSetLeft("25%"))"></Button>
130+
<Button Text="50%" OnClickWithoutRender="@(async () => await OnSetLeft("50%"))"></Button>
131+
<Button Text="100%" OnClickWithoutRender="@(async () => await OnSetLeft("100%"))"></Button>
132+
</section>
133+
<div class="border split-demo split-demo-horizontal">
134+
<Split Basis="40%" IsCollapsible="true" @ref="Split1">
135+
<FirstPaneTemplate>
136+
<div class="d-flex justify-content-center align-items-center h-100">@Localizer["SplitsPanel1"]</div>
137+
</FirstPaneTemplate>
138+
<SecondPaneTemplate>
139+
<div class="d-flex justify-content-center align-items-center h-100">@Localizer["SplitsPanel2"]</div>
140+
</SecondPaneTemplate>
141+
</Split>
142+
</div>
143+
</DemoBlock>
144+
125145
<AttributeTable Items="@GetAttributes()" />

src/BootstrapBlazor.Shared/Components/Samples/Splits.razor.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ private Task OnResizedAsync(SplitterResizedEventArgs args)
5252
return Task.CompletedTask;
5353
}
5454

55+
private Split Split1 = default!;
56+
57+
private Task OnSetLeft(string leftWidth) => Split1.SetLeftWidth(leftWidth);
58+
5559
/// <summary>
5660
/// 获得属性方法
5761
/// </summary>

src/BootstrapBlazor.Shared/Components/Samples/Splittings.razor

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@
3939
Introduction="@Localizer["SplittingColumnsIntro"]"
4040
Name="Columns">
4141
<div class="splitting-demo">
42-
<p>
42+
<section ignore>
4343
<BootstrapInputGroup>
4444
<BootstrapInputGroupLabel DisplayText="@Localizer["SplittingColumnsText"]" />
4545
<Slider @bind-Value="@_columns" Min="10" Max="50" />
4646
<BootstrapInputNumber @bind-Value="@_columns" Min="10" Max="50"></BootstrapInputNumber>
4747
</BootstrapInputGroup>
48-
</p>
48+
</section>
4949
<Splitting Columns="@_columns" Text="@Localizer["SplittingText"]"></Splitting>
5050
</div>
5151
</DemoBlock>

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1742,7 +1742,9 @@
17421742
"SplitsCollapsibleTrue": "Collapse button shown",
17431743
"SplitsCollapsibleFalse": "Collapse button hidden",
17441744
"SplitsFirstPaneMinimumSize": "The minimum size of the first pane supports any unit such as 10px 20% 5em 1rem. If no unit is provided, it defaults to px.",
1745-
"SplitsSecondPaneMinimumSize": "The minimum size of the second pane supports any unit such as 10px 20% 5em 1rem. If no unit is provided, it defaults to px."
1745+
"SplitsSecondPaneMinimumSize": "The minimum size of the second pane supports any unit such as 10px 20% 5em 1rem. If no unit is provided, it defaults to px.",
1746+
"SplitSetLeftTitle": "Code to set panel width",
1747+
"SplitSetLeftIntro": "Use the component instance method <code>SetLeftWidth</code> to set the width of the left/top panel, and the width of the right/bottom panel will be adaptive"
17461748
},
17471749
"BootstrapBlazor.Shared.Components.Samples.Dropdowns": {
17481750
"Title": "Dropdown",

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1742,7 +1742,9 @@
17421742
"SplitsCollapsibleTrue": "显示调整按钮",
17431743
"SplitsCollapsibleFalse": "隐藏调整按钮",
17441744
"SplitsFirstPaneMinimumSize": "第一个窗格最小尺寸支持任意单位如 10px 20% 5em 1rem 未提供单位时默认为 px",
1745-
"SplitsSecondPaneMinimumSize": "第二个窗格最小尺寸支持任意单位如 10px 20% 5em 1rem 未提供单位时默认为 px"
1745+
"SplitsSecondPaneMinimumSize": "第二个窗格最小尺寸支持任意单位如 10px 20% 5em 1rem 未提供单位时默认为 px",
1746+
"SplitSetLeftTitle": "代码设置面板宽度",
1747+
"SplitSetLeftIntro": "通过组件实例方法 <code>SetLeftWidth</code> 设置左侧/上侧面板宽度,右侧/下侧面板宽度自适应"
17461748
},
17471749
"BootstrapBlazor.Shared.Components.Samples.Dropdowns": {
17481750
"Title": "Dropdown 下拉菜单",

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.1.3-beta03</Version>
4+
<Version>9.1.3-beta04</Version>
55
</PropertyGroup>
66

77
<ItemGroup>

src/BootstrapBlazor/Components/Split/Split.razor.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,13 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
124124
IsKeepOriginalSize
125125
});
126126

127+
/// <summary>
128+
/// 设置左侧窗格宽度
129+
/// </summary>
130+
/// <param name="leftWidth">可以是百分比或者其他单位</param>
131+
/// <returns></returns>
132+
public Task SetLeftWidth(string leftWidth) => InvokeVoidAsync("setLeft", Id, leftWidth);
133+
127134
/// <summary>
128135
/// 窗格折叠时回调方法 由 JavaScript 调用
129136
/// </summary>

src/BootstrapBlazor/Components/Split/Split.razor.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,13 @@ const getMax = split => {
170170
return ret;
171171
}
172172

173+
export function setLeft(id, leftBasis) {
174+
const split = Data.get(id)
175+
if (split) {
176+
split.splitLeft.style.setProperty('flex-basis', leftBasis);
177+
}
178+
}
179+
173180
const setLeftBasis = (split, triggerLeft) => {
174181
const { option, splitLeft, invoke, method } = split;
175182
let leftBasis = splitLeft.style.flexBasis;

test/UnitTest/Components/SplitTest.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,17 @@ public async Task OnResizedAsync_Ok()
109109
Assert.False(state.IsCollapsed);
110110
}
111111

112+
[Fact]
113+
public async Task SetLeft_Ok()
114+
{
115+
var cut = Context.RenderComponent<Split>(pb =>
116+
{
117+
pb.Add(b => b.FirstPaneTemplate, RenderSplitView("I am Pane1"));
118+
pb.Add(b => b.SecondPaneTemplate, RenderSplitView("I am Pane2"));
119+
});
120+
await cut.InvokeAsync(() => cut.Instance.SetLeftWidth("25%"));
121+
}
122+
112123
static RenderFragment RenderSplitView(string name = "I am Pane1") => builder =>
113124
{
114125
builder.OpenElement(1, "div");

0 commit comments

Comments
 (0)