Skip to content

Commit 6cd62bb

Browse files
authored
MudTransferList (#128)
* Initialize MudTransferList * Two Way Bind Collections * A Little Fix * More Features * Finalize
1 parent 76c6ec8 commit 6cd62bb

21 files changed

+649
-321
lines changed

CodeBeam.MudExtensions.UnitTests/Components/RenderTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,12 @@ public void TextFieldExtendedPageRenderTest()
7070
var comp = Context.RenderComponent<TextFieldExtendedPage>();
7171
comp.Markup.Should().NotBeNullOrEmpty();
7272
}
73+
74+
[Test]
75+
public void TransferListPageRenderTest()
76+
{
77+
var comp = Context.RenderComponent<TransferListPage>();
78+
comp.Markup.Should().NotBeNullOrEmpty();
79+
}
7380
}
7481
}

CodeBeam.MudExtensions/Components/ListExtended/MudListExtended.razor

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,17 @@
88
<CascadingValue Value="@this" IsFixed="true">
99
@if (MultiSelection && SelectAll && SelectAllPosition == SelectAllPosition.BeforeSearchBox && ParentList == null)
1010
{
11-
<MudListItemExtended T="T" IsFunctional="true" Icon="@SelectAllCheckBoxIcon" IconColor="@Color" Text="@SelectAllText" OverrideMultiSelectionComponent="MultiSelectionComponent.None" OnClick="@(() => SelectAllItems(_allSelected))" OnClickHandlerPreventDefault="true" Dense="@Dense" Class="mb-2" />
12-
<MudDivider />
11+
@if (SelectAllTemplate != null)
12+
{
13+
<div class="mud-ripple" @onclick="@(() => SelectAllItems(_allSelected))" tabindex="-1">
14+
@SelectAllTemplate
15+
</div>
16+
}
17+
else
18+
{
19+
<MudListItemExtended T="T" IsFunctional="true" Icon="@SelectAllCheckBoxIcon" IconColor="@Color" Text="@SelectAllText" OverrideMultiSelectionComponent="MultiSelectionComponent.None" OnClick="@(() => SelectAllItems(_allSelected))" OnClickHandlerPreventDefault="true" Dense="@Dense" Class="mb-2" />
20+
<MudDivider />
21+
}
1322
}
1423

1524
@if (ItemCollection != null)

CodeBeam.MudExtensions/Components/ListExtended/MudListExtended.razor.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using MudExtensions.Enums;
1212
using MudExtensions.Services;
1313
using static MudBlazor.CategoryTypes;
14+
using static MudBlazor.Colors;
1415

1516
namespace MudExtensions
1617
{
@@ -82,6 +83,13 @@ public partial class MudListExtended<T> : MudComponentBase, IDisposable
8283
[Category(CategoryTypes.FormComponent.ListBehavior)]
8384
public RenderFragment<MudListItemExtended<T>> ItemDisabledTemplate { get; set; }
8485

86+
/// <summary>
87+
/// Optional presentation template for select all item
88+
/// </summary>
89+
[Parameter]
90+
[Category(CategoryTypes.FormComponent.ListBehavior)]
91+
public RenderFragment SelectAllTemplate { get; set; }
92+
8593
[Parameter]
8694
[Category(CategoryTypes.List.Behavior)]
8795
public DefaultConverter<T> Converter { get; set; } = new DefaultConverter<T>();
@@ -372,7 +380,7 @@ protected void HandleCentralValueCommander(string changedValueType, bool updateS
372380
}
373381
else if (changedValueType == "MultiSelectionOff")
374382
{
375-
SelectedValue = SelectedValues.FirstOrDefault();
383+
SelectedValue = SelectedValues == null ? default(T) : SelectedValues.FirstOrDefault();
376384
var items = CollectAllMudListItems(true);
377385
SelectedValues = SelectedValue == null ? null : new HashSet<T>(_comparer) { SelectedValue };
378386
UpdateSelectedItem();
@@ -1313,6 +1321,20 @@ protected ICollection<T> GetSearchedItems()
13131321
return ItemCollection.Where(x => Converter.Set(x).Contains(_searchString, StringComparison.CurrentCultureIgnoreCase)).ToList();
13141322
}
13151323

1324+
public async Task ForceUpdate()
1325+
{
1326+
//if (!MultiSelection)
1327+
//{
1328+
// SelectedValues = new HashSet<T>(_comparer) { SelectedValue };
1329+
//}
1330+
//else
1331+
//{
1332+
// await SelectedValuesChanged.InvokeAsync(new HashSet<T>(SelectedValues, _comparer));
1333+
//}
1334+
await Task.Delay(1);
1335+
UpdateSelectedStyles();
1336+
}
1337+
13161338
#endregion
13171339
}
13181340
}

CodeBeam.MudExtensions/Components/ListExtended/MudListItemExtended.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
@using MudBlazor
55
@using MudExtensions.Enums
66

7-
<div tabindex="0" @attributes="UserAttributes" id="@ItemId" class="@Classname" @onclick="@(((MudListExtended?.Clickable == true || NestedList != null) && IsFunctional == false) ? OnClickHandler : OnlyOnClick)" @onclick:stopPropagation="true" style="@Style">
7+
<div tabindex="0" @attributes="UserAttributes" id="@ItemId" class="@Classname" @onclick="@(((MudListExtended?.Clickable == true || NestedList != null) && IsFunctional == false) ? OnClickHandler : OnlyOnClick)" @onclick:stopPropagation="@OnClickStopPropagation" style="@Style">
88

99
@if (MudListExtended?.ItemDisabledTemplate != null && Disabled == true)
1010
{

CodeBeam.MudExtensions/Components/ListExtended/MudListItemExtended.razor.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,13 @@ public bool Disabled
177177
[Category(CategoryTypes.List.Appearance)]
178178
public bool Inset { get; set; }
179179

180+
/// <summary>
181+
/// If true, stop propagation on click. Default is true.
182+
/// </summary>
183+
[Parameter]
184+
[Category(CategoryTypes.List.Appearance)]
185+
public bool OnClickStopPropagation { get; set; } = true;
186+
180187
private bool? _dense;
181188
/// <summary>
182189
/// If true, compact vertical padding will be used.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
@namespace MudExtensions
2+
@inherits MudComponentBase
3+
@typeparam T
4+
@using MudExtensions.Enums
5+
6+
<MudStack Class="@Class" Style="@Style" Row="!Vertical" Spacing="Spacing">
7+
<MudListExtended @ref="_startList" Class="@StartClassname" Style="@StartStylename" T="T" ItemCollection="@StartCollection" Disabled="Disabled" Clickable="true" MultiSelection="@MultiSelection" SelectAll="@MultiSelection" MultiSelectionComponent="@MultiSelectionComponent" MaxItems="@MaxItems" Color="@Color">
8+
<SelectAllTemplate>
9+
@if (SelectAllType == SelectAllType.SelectAllItem)
10+
{
11+
<MudListItemExtended T="T" IsFunctional="true" Text="@SelectAllText" SecondaryText="@($"{(_startList == null ? 0 : _startList.SelectedValues == null ? 0 : _startList.SelectedValues.Count())} / {StartCollection.Count}")" OnClickStopPropagation="false" />
12+
}
13+
</SelectAllTemplate>
14+
</MudListExtended>
15+
<div class="@($"{(Vertical ? "d-flex" : "d-flex flex-column")} gap-{ButtonSpacing} align-center justify-center")">
16+
@if (SelectAllType == SelectAllType.Buttons)
17+
{
18+
<MudIconButton Icon="@(Vertical ? Icons.Material.Filled.KeyboardDoubleArrowDown : Icons.Material.Filled.KeyboardDoubleArrowRight)" Disabled="Disabled" Color="@Color" Variant="@ButtonVariant" OnClick="@(() => TransferAll(true))" />
19+
}
20+
<MudIconButton Icon="@(Vertical ? Icons.Material.Filled.KeyboardArrowDown : Icons.Material.Filled.KeyboardArrowRight)" Disabled="Disabled" Color="@Color" Variant="@ButtonVariant" OnClick="@(() => Transfer(true))" />
21+
<MudIconButton Icon="@(Vertical ? Icons.Material.Filled.KeyboardArrowUp : Icons.Material.Filled.KeyboardArrowLeft)" Disabled="Disabled" Color="@Color" Variant="@ButtonVariant" OnClick="@(() => Transfer(false))" />
22+
@if (SelectAllType == SelectAllType.Buttons)
23+
{
24+
<MudIconButton Icon="@(Vertical ? Icons.Material.Filled.KeyboardDoubleArrowUp : Icons.Material.Filled.KeyboardDoubleArrowLeft)" Disabled="Disabled" Color="@Color" Variant="@ButtonVariant" OnClick="@(() => TransferAll(false))" />
25+
}
26+
</div>
27+
<MudListExtended @ref="_endList" Class="@EndClassname" Style="@EndStylename" T="T" ItemCollection="@EndCollection" Disabled="Disabled" Clickable="true" MultiSelection="@MultiSelection" SelectAll="@MultiSelection" MultiSelectionComponent="@MultiSelectionComponent" MaxItems="@MaxItems" Color="@Color">
28+
<SelectAllTemplate>
29+
@if (SelectAllType == SelectAllType.SelectAllItem)
30+
{
31+
<MudListItemExtended T="T" IsFunctional="true" Text="@SelectAllText" SecondaryText="@($"{(_endList == null ? 0 : _endList.SelectedValues == null ? 0 : _endList.SelectedValues.Count())} / {EndCollection.Count}")" OnClickStopPropagation="false" />
32+
}
33+
</SelectAllTemplate>
34+
</MudListExtended>
35+
</MudStack>

0 commit comments

Comments
 (0)