Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Transfer): add Height parameter #5095

Merged
merged 5 commits into from
Jan 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/BootstrapBlazor/BootstrapBlazor.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<Version>9.2.7-beta03</Version>
<Version>9.2.7-beta05</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/BootstrapBlazor/Components/Transfer/Transfer.razor
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{
<BootstrapLabel required="@Required" ShowLabelTooltip="ShowLabelTooltip" Value="@DisplayText" />
}
<div @attributes="@AdditionalAttributes" class="transfer">
<div @attributes="@AdditionalAttributes" class="@ClassString" style="@StyleString">
<TransferPanel Items="@LeftItems" Text="@LeftPanelText" IsDisabled="@IsDisabled"
ShowSearch="@ShowSearch" SearchPlaceHolderString="@LeftPanelSearchPlaceHolderString"
OnSelectedItemsChanged="@SelectedItemsChanged" OnSetItemClass="OnSetItemClass"
Expand Down
19 changes: 16 additions & 3 deletions src/BootstrapBlazor/Components/Transfer/Transfer.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
// Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone

using Microsoft.Extensions.Localization;
using System.Reflection;

namespace BootstrapBlazor.Components;

Expand Down Expand Up @@ -50,9 +49,7 @@ public partial class Transfer<TValue>
/// </summary>
[Parameter]
[NotNull]
#if NET6_0_OR_GREATER
[EditorRequired]
#endif
public IEnumerable<SelectedItem>? Items { get; set; }

/// <summary>
Expand Down Expand Up @@ -188,10 +185,26 @@ public partial class Transfer<TValue>
[Parameter]
public RenderFragment<SelectedItem>? RightItemTemplate { get; set; }

/// <summary>
/// 获得/设置 组件高度 默认值 null 未设置
/// </summary>
[Parameter]
public string? Height { get; set; }

[Inject]
[NotNull]
private IIconTheme? IconTheme { get; set; }

private string? ClassString => CssBuilder.Default("transfer")
.AddClass("has-height", !string.IsNullOrEmpty(Height))
.AddClassFromAttributes(AdditionalAttributes)
.Build();

private string? StyleString => CssBuilder.Default()
.AddClass($"--bb-transfer-height: {Height};", !string.IsNullOrEmpty(Height))
.AddStyleFromAttributes(AdditionalAttributes)
.Build();

/// <summary>
/// OnInitialized 方法
/// </summary>
Expand Down
12 changes: 12 additions & 0 deletions src/BootstrapBlazor/Components/Transfer/Transfer.razor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@
display: flex;
flex-direction: row;
flex-wrap: nowrap;

&.has-height {
height: var(--bb-transfer-height);

.transfer-panel {
height: 100%;

.transfer-panel-body {
height: calc(100% - var(--bb-transfer-panel-header-height));
}
}
}
}

.transfer-panel {
Expand Down
10 changes: 10 additions & 0 deletions test/UnitTest/Components/TransferTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ public void Items_Ok()
cut.Contains("transfer-panel");
}

[Fact]
public void Height_Ok()
{
var cut = Context.RenderComponent<Transfer<string>>(pb =>
{
pb.Add(a => a.Height, "200px");
});
cut.Contains("--bb-transfer-height: 200px;");
}

[Fact]
public async Task EnumerableString_Value()
ArgoZhang marked this conversation as resolved.
Show resolved Hide resolved
{
Expand Down
Loading