-
Notifications
You must be signed in to change notification settings - Fork 101
Expand file tree
/
Copy pathIndex.razor.cs
More file actions
95 lines (83 loc) · 3.12 KB
/
Index.razor.cs
File metadata and controls
95 lines (83 loc) · 3.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
using Microsoft.AspNetCore.Components;
using MudBlazor;
using MudExtensions.Docs.Services;
using MudExtensions.Docs.Shared;
using static MudBlazor.Colors;
namespace MudExtensions.Docs.Pages
{
public partial class Index
{
[CascadingParameter]
MainLayout? MainLayout { get; set; }
List<MudExtensionComponentInfo> _components = new();
MudExtensionComponentInfo? _searchedComponent;
MudAnimate _animate = new();
bool _navigating = false;
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
_components = DocsService.GetAllComponentInfo();
}
private string Version
{
get
{
var v = typeof(MudAnimate).Assembly.GetName().Version;
return $"v {v?.Major}.{v?.Minor}.{v?.Build}";
}
}
private async Task<IEnumerable<MudExtensionComponentInfo>> ComponentSearch(string value, CancellationToken token)
{
// In real life use an asynchronous function for fetching data from an api.
await Task.Delay(1, token);
// if text is null or empty, show complete list
if (string.IsNullOrEmpty(value))
return _components;
return _components.Where(x => x?.Component?.Name.Contains(value, StringComparison.InvariantCultureIgnoreCase) == true || x?.Usage.ToDescriptionString().Equals(value, StringComparison.CurrentCultureIgnoreCase) == true || (value.ToLowerInvariant() == "material" && x.IsMaterial3 == true));
}
private async Task NavigateSelectedComponent()
{
_navigating = true;
StateHasChanged();
await Task.Delay(2000);
NavigationManager.NavigateTo($"/{_searchedComponent?.Component?.Name.Replace("`1", null).ToLowerInvariant()}");
if (_searchedComponent == null)
{
_navigating = false;
}
}
private async Task HandleCompCardClick(MudExtensionComponentInfo component)
{
if (component == null)
{
return;
}
_searchedComponent = component;
await NavigateSelectedComponent();
}
private string GetSectionIcon(ComponentUsage componentUsage)
{
if (componentUsage == ComponentUsage.Layout)
{
return Icons.Material.Filled.Dashboard;
}
else if (componentUsage == ComponentUsage.Button)
{
return Icons.Material.Filled.Dataset;
}
else if (componentUsage == ComponentUsage.Input)
{
return Icons.Material.Filled.AppRegistration;
}
else if (componentUsage == ComponentUsage.Display)
{
return Icons.Material.Filled.Ballot;
}
else if (componentUsage == ComponentUsage.Utility)
{
return Icons.Material.Filled.AutoAwesome;
}
return Icons.Material.Filled.Dashboard;
}
}
}