Skip to content

Commit

Permalink
Reuse MudTreeViewItemToggleButton
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-strecker-sonarsource committed Jan 2, 2024
1 parent 70bb4a1 commit f31033e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 18 deletions.
3 changes: 1 addition & 2 deletions ProtoBufViewer.Blazor/Components/VirtualTreeView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,11 @@ private void SynchronizeViewList()
}
}

private void OnClick(ViewItem item)
private void OnClick(bool newIsExpanded, ViewItem item)
{
var viewListIndex = viewList.FindIndex(x => EqualityComparer<ViewItem>.Default.Equals(x, item));
if (viewListIndex >= 0)
{
var newIsExpanded = !item.IsExpanded;
viewList[viewListIndex] = item with { IsExpanded = newIsExpanded };
var children = ChildrenSelector?.Invoke(item.Item) ?? [];
if (newIsExpanded)
Expand Down
19 changes: 3 additions & 16 deletions ProtoBufViewer.Blazor/Components/VirtualTreeView.razor
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
@using MudBlazor.Utilities
@inherits ComponentBase
@typeparam T


<ul style="flex-shrink:0">
<ul>
<Virtualize Items="viewList" ItemSize="40" Context="viewListItem">
<li @key="@(viewListItem.Key)" style="flex-shrink:0;margin-left:@(viewListItem.Level * 32)pt;height:30pt;" class="@(ListItemClassname())">
<div class="@(ContentClassname(false))">
@if (ChildrenSelector?.Invoke(viewListItem.Item)?.Count > 0)
{
<div class="mud-treeview-item-arrow">
<MudIconButton Icon="@Icons.Material.Filled.ChevronRight" OnClick="() => OnClick(viewListItem)" Class="@(ButtonClassName(viewListItem.IsExpanded))" />
</div>
}
<MudTreeViewItemToggleButton Visible="ChildrenSelector?.Invoke(viewListItem.Item)?.Count > 0" Expanded="@viewListItem.IsExpanded" ExpandedChanged="newIsExpanded => OnClick(newIsExpanded, viewListItem)" />
@if (ItemTemplate == null)
{
@viewListItem.Item
Expand All @@ -34,12 +27,6 @@
protected string ContentClassname(bool isSelected) =>
new CssBuilder("mud-treeview-item-content")
.AddClass("cursor-pointer", false)
.AddClass($"mud-treeview-item-selected", isSelected)
.Build();

protected string ButtonClassName(bool isExpanded) =>
new CssBuilder()
.AddClass("mud-treeview-item-arrow-expand")
.AddClass("mud-transform", isExpanded)
.AddClass("mud-treeview-item-selected", isSelected)
.Build();
}

0 comments on commit f31033e

Please sign in to comment.