-
Notifications
You must be signed in to change notification settings - Fork 380
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
1,181 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
examples/Demo/Shared/Pages/TreeView/Examples/TreeViewFlat.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
<FluentTreeView RenderCollapsedNodes=true> | ||
<FluentTreeView> | ||
<FluentTreeItem InitiallySelected="true">Daisy</FluentTreeItem> | ||
<FluentTreeItem>Sunflower</FluentTreeItem> | ||
<FluentTreeItem>Rose</FluentTreeItem> | ||
<FluentDivider></FluentDivider> | ||
<FluentTreeItem>Petunia</FluentTreeItem> | ||
<FluentTreeItem>Tulip</FluentTreeItem> | ||
</FluentTreeView> | ||
</FluentTreeView> |
55 changes: 55 additions & 0 deletions
55
examples/Demo/Shared/Pages/TreeView/Examples/TreeViewWithItems.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<FluentTreeView Items="@Items" @bind-SelectedItem="@SelectedItem" LazyLoadItems="true"> | ||
<ItemTemplate> | ||
@context.Text | ||
<span style="color: var(--accent-fill-rest); margin: 0 4px;"> | ||
@(context.Items == null ? "" : $"[{context.Items.Count()}]") | ||
</span> | ||
</ItemTemplate> | ||
</FluentTreeView> | ||
|
||
<div> | ||
<b>Total items:</b> @Count | ||
</div> | ||
<div> | ||
<b>Selected item:</b> @SelectedItem?.Text | ||
</div> | ||
|
||
@code | ||
{ | ||
private ITreeViewItem? SelectedItem; | ||
|
||
private Icon IconCollapsed = new Icons.Regular.Size20.Folder(); | ||
private Icon IconExpanded = new Icons.Regular.Size20.FolderOpen(); | ||
|
||
private int Count = -1; | ||
private IEnumerable<ITreeViewItem>? Items = new List<ITreeViewItem>(); | ||
|
||
protected override void OnInitialized() | ||
{ | ||
Items = CreateTree(maxLevel: 5, maxItemsPerLevel: 12).Items; | ||
SelectedItem = Items?.ElementAt(3); | ||
} | ||
|
||
// Recursive method to create tree | ||
private TreeViewItem CreateTree(int maxLevel, int maxItemsPerLevel, int level = 0) | ||
{ | ||
Count++; | ||
|
||
int nbItems = Random.Shared.Next(maxItemsPerLevel - 3, maxItemsPerLevel); | ||
|
||
var treeItem = new TreeViewItem | ||
{ | ||
Text = $"Item {Count}", | ||
Disabled = level >= 2 && Count % 7 == 0, | ||
IconCollapsed = IconCollapsed, | ||
IconExpanded = IconExpanded, | ||
Expanded = level >= 2 && Count % 5 == 0, | ||
Items = level == maxLevel | ||
? null | ||
: new List<TreeViewItem>(Enumerable.Range(1, nbItems) | ||
.Select(i => CreateTree(maxLevel, maxItemsPerLevel, level + 1))), | ||
}; | ||
|
||
return treeItem; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
examples/Demo/Shared/Pages/TreeView/Examples/TreeViewWithUnlimitedItems.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<FluentTreeView Items="@Items" @bind-SelectedItem="@SelectedItem" /> | ||
|
||
<div> | ||
Selected Item: @SelectedItem?.Text | ||
</div> | ||
|
||
@code | ||
{ | ||
private ITreeViewItem? SelectedItem; | ||
private IEnumerable<ITreeViewItem>? Items = new List<ITreeViewItem>(); | ||
|
||
protected override void OnInitialized() | ||
{ | ||
Items = GetItems(); | ||
} | ||
|
||
private Task OnExpandedAsync(TreeViewItemExpandedEventArgs e) | ||
{ | ||
if (e.Expanded) | ||
{ | ||
e.CurrentItem.Items = GetItems(); | ||
} | ||
else | ||
{ | ||
// Remove sub-items and add a "Fake" item to simulate the [+] | ||
e.CurrentItem.Items = TreeViewItem.LoadingTreeViewItems; | ||
} | ||
|
||
return Task.CompletedTask; | ||
} | ||
|
||
private IEnumerable<ITreeViewItem> GetItems() | ||
{ | ||
var nbItems = Random.Shared.Next(3, 9); | ||
|
||
return Enumerable.Range(1, nbItems).Select(i => new TreeViewItem() | ||
{ | ||
Text = $"Item {Random.Shared.Next(1, 9999)}", | ||
OnExpandedAsync = OnExpandedAsync, | ||
Items = TreeViewItem.LoadingTreeViewItems, // "Fake" sub-item to simulate the [+] | ||
}).ToArray(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.