forked from CodeBeamOrg/CodeBeam.MudBlazor.Extensions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelectExtendedExample6.razor
More file actions
116 lines (104 loc) · 5.39 KB
/
SelectExtendedExample6.razor
File metadata and controls
116 lines (104 loc) · 5.39 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
@namespace MudExtensions.Docs.Examples
<MudGrid>
<MudItem xs="12" sm="8" Class="d-flex gap-4">
<MudSelectExtended @bind-Value="@_selectedState" MultiSelection="@_multiselection" SearchBox="true" SearchBoxAutoFocus="@_searchBoxAutoFocus" Label="Standard (RenderFragment)" AnchorOrigin="Origin.BottomCenter" Variant="Variant.Outlined" HelperText="Search with 'Contains' logic" SearchBoxClearable="_searchBoxClearable">
@foreach (var state in _states)
{
<MudSelectItemExtended Value="@state" Text="@state">@state</MudSelectItemExtended>
}
</MudSelectExtended>
<MudSelectExtended MultiSelection="@_multiselection" ItemCollection="_states" SearchBox="true" SearchBoxAutoFocus="@_searchBoxAutoFocus" T="string" Label="Standard (ItemCollection)" AnchorOrigin="Origin.BottomCenter" Variant="Variant.Outlined" HelperText="Search with 'Contains' logic" SearchBoxClearable="_searchBoxClearable" />
<MudSelectExtended MultiSelection="@_multiselection" ItemCollection="_states" SearchBox="true" SearchBoxAutoFocus="@_searchBoxAutoFocus" SearchFunc="@(new Func<string, string, bool>(SearchItems))" T="string" Label="Custom Search Func" AnchorOrigin="Origin.BottomCenter" Variant="Variant.Outlined" SearchBoxPlaceholder="Some Placeholder" HelperText="Search with 'StartsWith' logic" SearchBoxClearable="_searchBoxClearable" />
</MudItem>
<MudItem xs="12" sm="4">
<MudStack>
<MudSwitchM3 @bind-Value="_multiselection" Color="Color.Secondary" Label="MultiSelection" />
<MudSwitchM3 @bind-Value="_searchBoxAutoFocus" Color="Color.Secondary" Label="AutoFocus (SearchBox)" />
<MudSwitchM3 @bind-Value="_searchBoxClearable" Color="Color.Secondary" Label="Clearable (SearchBox)" />
</MudStack>
</MudItem>
</MudGrid>
<MudGrid Class="mt-8">
<MudItem xs="12">
<MudText Typo="Typo.h6" Class="mb-4">Complex Type with ToStringFunc and Search</MudText>
</MudItem>
<MudItem xs="12" sm="8" Class="d-flex gap-4">
<MudSelectExtended MultiSelection="true"
ItemCollection="TestHouses"
@bind-Value="_selectedHouse"
SearchBox="true"
T="TestHouse"
Label="Houses (Complex Type)"
ToStringFunc="@((TestHouse house) => $"{house.Number} - {house.Name}")"
AnchorOrigin="Origin.BottomCenter"
Variant="Variant.Outlined"
aria-label="House Selection"
HelperText="Search by number or name (e.g., '1 -' or 'Test3')"
SearchBoxClearable="true" />
</MudItem>
<MudItem xs="12" sm="4">
<MudPaper Class="pa-4" Elevation="0" Outlined="true">
<MudText Typo="Typo.subtitle2" Class="mb-2"><strong>Selected House:</strong></MudText>
@if (_selectedHouse != null)
{
<MudText Typo="Typo.body2">Number: @_selectedHouse.Number</MudText>
<MudText Typo="Typo.body2">Name: @_selectedHouse.Name</MudText>
<MudText Typo="Typo.body2">Postcode: @_selectedHouse.Postcode</MudText>
}
else
{
<MudText Typo="Typo.body2" Color="Color.Secondary">None selected</MudText>
}
</MudPaper>
</MudItem>
</MudGrid>
@code {
bool _multiselection;
bool _searchBoxAutoFocus;
bool _searchBoxClearable;
private string? _selectedState;
private TestHouse? _selectedHouse;
private string[] _states =
{
"Alabama", "Alaska", "American Samoa", "Arizona",
"Arkansas", "California", "Colorado", "Connecticut",
"Delaware", "District of Columbia", "Federated States of Micronesia",
"Florida", "Georgia", "Guam", "Hawaii", "Idaho",
"Illinois", "Indiana", "Iowa", "Kansas", "Kentucky",
"Louisiana", "Maine", "Marshall Islands", "Maryland",
"Massachusetts", "Michigan", "Minnesota", "Mississippi",
"Missouri", "Montana", "Nebraska", "Nevada",
"New Hampshire", "New Jersey", "New Mexico", "New York",
"North Carolina", "North Dakota", "Northern Mariana Islands", "Ohio",
"Oklahoma", "Oregon", "Palau", "Pennsylvania", "Puerto Rico",
"Rhode Island", "South Carolina", "South Dakota", "Tennessee",
"Texas", "Utah", "Vermont", "Virgin Island", "Virginia",
"Washington", "West Virginia", "Wisconsin", "Wyoming",
};
private class TestHouse
{
public int Number { get; set; }
public string? Name { get; set; }
public string? Postcode { get; set; }
}
private List<TestHouse> TestHouses = new()
{
new TestHouse { Number = 1, Name = "Test1", Postcode = "12345" },
new TestHouse { Number = 2, Name = "Test2", Postcode = "54321" },
new TestHouse { Number = 3, Name = "Test3", Postcode = "67890" },
new TestHouse { Number = 4, Name = "Test4", Postcode = "09876" },
new TestHouse { Number = 5, Name = "Test5", Postcode = "11223" },
};
private bool SearchItems(string value, string searchString)
{
if (searchString == "")
{
return true;
}
if (value.StartsWith(searchString, StringComparison.CurrentCultureIgnoreCase))
{
return true;
}
return false;
}
}