|
1 | 1 | @namespace MudExtensions |
2 | 2 | @using MudExtensions.Enums; |
| 3 | +@using System.Runtime.InteropServices; |
3 | 4 | @typeparam T |
4 | 5 | @inherits MudBaseInputExtended<T> |
5 | 6 |
|
|
10 | 11 | Error="@Error" ErrorText="@ErrorText" ErrorId="@ErrorId" Disabled="@Disabled" @onmousedown="@ToggleMenu" Required="@Required" ForId="@FieldId"> |
11 | 12 | <InputContent> |
12 | 13 | @*DataVisualiserStyle="@($"min-height: 1.1876em;{(HasValue(Value) && Editable == true ? "padding-bottom: 0px" : null)}")"*@ |
13 | | - <MudInputExtended @ref="_inputReference" T="string" InputType="@(Editable && MultiSelection == false ? InputType.Text : InputType.Hidden)" |
| 14 | + <MudInputExtended @ref="_inputReference" T="string" InputType="@(Editable && !MultiSelection ? InputType.Text : InputType.Hidden)" |
14 | 15 | Class="@InputClassname" Style="@InputStyle" Margin="@Margin" Placeholder="@Placeholder" |
15 | 16 | Variant="@Variant" Immediate="true" |
16 | 17 | TextUpdateSuppression="false" |
|
27 | 28 |
|
28 | 29 | <DataVisualiser> |
29 | 30 | <div style="flex-basis: content; flex-grow: 0"> |
30 | | - @if (HasValue(Value) == false && string.IsNullOrEmpty(Placeholder) == false) |
| 31 | + @if (!HasValue(Value) && !string.IsNullOrWhiteSpace(Placeholder)) |
31 | 32 | { |
32 | 33 | <MudText Typo="Typo.body1" Class="mud-text-secondary">@Placeholder</MudText> |
33 | 34 | } |
34 | 35 | else if (InputPresenter == ValuePresenter.Chip) |
35 | 36 | { |
36 | | - <MudChipSet Class="d-flex flex-wrap mud-width-full" AllClosable="ChipCloseable" OnClose="ChipClosed"> |
37 | | - @foreach (var item in Items?.Where(x => (MultiSelection ? SelectedValues.Contains(x.Value) : Value?.Equals(x.Value) == true)) ?? new List<MudComboBoxItem<T>>()) |
38 | | - { |
39 | | - <MudChip Class="@ChipClass" Value="item.Value" Text="@(ToStringFunc != null ? ToStringFunc.Invoke(item.Value) : string.IsNullOrEmpty(item.Text) ? Converter.Set(item.Value) : item.Text)" Color="@Color" Size="@ChipSize" Variant="@ChipVariant" @onmousedown:stopPropagation /> |
| 37 | + <MudChipSet Class="d-flex flex-wrap mud-width-full" AllClosable="@ChipCloseable" OnClose="@ChipClosed"> |
| 38 | + @{ |
| 39 | + var collection = Items.Where(x => (MultiSelection ? SelectedValues.Contains(x.Value) : Value?.Equals(x.Value) == true))?.ToList(); |
| 40 | + if (collection is not null) |
| 41 | + { |
| 42 | + foreach (var item in CollectionsMarshal.AsSpan(collection)) |
| 43 | + { |
| 44 | + <MudChip Class="@ChipClass" Value="@item.Value" Text="@(ToStringFunc is not null ? ToStringFunc.Invoke(item.Value) : string.IsNullOrWhiteSpace(item.Text) ? Converter.Set(item.Value) : item.Text)" |
| 45 | + Color="@Color" Size="@ChipSize" Variant="@ChipVariant" @onmousedown:stopPropagation /> |
| 46 | + } |
| 47 | + } |
40 | 48 | } |
41 | | - @*@if (ItemCollection != null) |
| 49 | + @*@if (ItemCollection is not null) |
42 | 50 | { |
43 | 51 | foreach (var item in ItemCollection.Where(x => SelectedValues.Contains(x))) |
44 | 52 | { |
|
47 | 55 | } |
48 | 56 | else |
49 | 57 | { |
50 | | - foreach (var item in Items?.Where(x => (MultiSelection ? SelectedValues.Contains(x.Value) : Value?.Equals(x.Value) == true)) ?? new List<MudComboboxItem<T>>()) |
| 58 | + foreach (var item in Items.Where(x => (MultiSelection ? SelectedValues.Contains(x.Value) : Value?.Equals(x.Value) == true)) ?? new List<MudComboBoxItem<T>>()) |
51 | 59 | { |
52 | | - <MudChip Class="@ChipClass" Value="item.Value" Text="@(ToStringFunc != null ? ToStringFunc.Invoke(item.Value) : string.IsNullOrEmpty(item.Text) ? Converter.Set(item.Value) : item.Text)" Color="@Color" Size="@ChipSize" Variant="@ChipVariant" @onmousedown:stopPropagation /> |
| 60 | + <MudChip Class="@ChipClass" Value="item.Value" Text="@(ToStringFunc is not null ? ToStringFunc.Invoke(item.Value) : string.IsNullOrWhiteSpace(item.Text) ? Converter.Set(item.Value) : item.Text)" Color="@Color" Size="@ChipSize" Variant="@ChipVariant" @onmousedown:stopPropagation /> |
53 | 61 | } |
54 | 62 | }*@ |
55 | 63 | </MudChipSet> |
56 | 64 | } |
57 | | - else if (InputPresenter == ValuePresenter.Text && (Editable == false || (MultiSelection == true && Editable == true))) |
| 65 | + else if (InputPresenter == ValuePresenter.Text && (!Editable || (MultiSelection && Editable))) |
58 | 66 | { |
59 | 67 | <div style="white-space: break-spaces">@_dataVisualiserText</div> |
60 | 68 | } |
61 | 69 | else if (InputPresenter == ValuePresenter.ItemContent) |
62 | 70 | { |
63 | | - if (SelectedValues == null) |
| 71 | + if (SelectedValues is null) |
64 | 72 | { |
65 | 73 | <MudText Typo="Typo.body1" Class="mud-text-secondary">@Placeholder</MudText> |
66 | 74 |
|
67 | 75 | } |
68 | | - else if (ItemTemplate != null) |
| 76 | + else if (ItemTemplate is not null) |
69 | 77 | { |
70 | | - if (Value != null) |
| 78 | + if (Value is not null) |
71 | 79 | { |
72 | 80 | @ItemTemplate(Items.FirstOrDefault(x => x.Value.Equals(Value))) |
73 | 81 | } |
74 | | - else if (!string.IsNullOrEmpty(Placeholder)) |
| 82 | + else if (!string.IsNullOrWhiteSpace(Placeholder)) |
75 | 83 | { |
76 | 84 | <MudText Typo="Typo.body1" Class="mud-text-secondary">@Placeholder</MudText> |
77 | 85 | } |
78 | 86 | } |
79 | | - else if (Items.FirstOrDefault(x => x.Value.Equals(Value))?.ChildContent != null) |
| 87 | + else if (Items.FirstOrDefault(x => x.Value.Equals(Value))?.ChildContent is not null) |
80 | 88 | { |
81 | 89 | if (MultiSelection) |
82 | 90 | { |
83 | | - @foreach (var item in Items.Where(x => SelectedValues.Contains(x.Value))) |
| 91 | + foreach (var item in CollectionsMarshal.AsSpan(Items)) |
84 | 92 | { |
85 | | - <MudRender>@item.ChildContent</MudRender> |
| 93 | + if (SelectedValues.Contains(item.Value)) |
| 94 | + { |
| 95 | + <MudRender>@item.ChildContent</MudRender> |
| 96 | + } |
86 | 97 | } |
87 | 98 | } |
88 | 99 | else |
89 | 100 | { |
90 | 101 | <MudRender>@Items.FirstOrDefault(x => x.Value.Equals(Value))?.ChildContent</MudRender> |
91 | 102 | } |
92 | | - |
93 | 103 | } |
94 | 104 | else |
95 | 105 | { |
|
100 | 110 | </DataVisualiser> |
101 | 111 | <ChildContent> |
102 | 112 | <div class="@TemplateClass"> |
103 | | - @if (HasValue(Value) == false && string.IsNullOrEmpty(Placeholder) == false) |
| 113 | + @if (!HasValue(Value) && !string.IsNullOrWhiteSpace(Placeholder)) |
104 | 114 | { |
105 | 115 | <MudText Typo="Typo.body1" Class="mud-text-secondary">@Placeholder</MudText> |
106 | 116 | } |
|
120 | 130 | { |
121 | 131 | <div class="pa-2"> |
122 | 132 | <MudTextFieldExtended id="@($"{_elementId}-autocomplete")" @ref="@_searchbox" T="string" @bind-Value="@_searchString" Margin="Margin.Dense" |
123 | | - Variant="Variant.Outlined" Immediate="true" OnKeyDown="@SearchBoxHandleKeyDown" OnKeyUp="@SearchBoxHandleKeyUp" Clearable="@SearchBoxClearable"> |
| 133 | + Variant="Variant.Outlined" Immediate="true" OnKeyDown="@SearchBoxHandleKeyDown" OnKeyUp="@SearchBoxHandleKeyUp" |
| 134 | + Clearable="@SearchBoxClearable"> |
124 | 135 | <AdornmentEnd> |
125 | 136 | <MudIcon Icon="@Icons.Material.Filled.Search" Color="@Color" /> |
126 | 137 | </AdornmentEnd> |
|
131 | 142 | @if (SelectAll) |
132 | 143 | { |
133 | 144 | <div class="@($"mud-combobox-item mud-combobox-item-clickable mud-combobox-item-{Dense.ToDescriptionString()} mud-ripple d-flex")" @onclick="SelectAllItems" @onclick:stopPropagation="true"> |
134 | | - <MudCheckBox Class="mx-4" @bind-Checked="@_allSelected" Color="@Color" @onclick="@SelectAllItems" Dense="true" /> |
135 | | - <MudText Typo="GetTypo()">@SelectAllText</MudText> |
| 145 | + <MudCheckBox Class="mx-4" Dense |
| 146 | + @bind-Checked="@_allSelected" @onclick="@SelectAllItems" |
| 147 | + IndeterminateIcon="@IndeterminateIcon" |
| 148 | + Size="@CheckBoxSize" |
| 149 | + Color="@EffectiveCheckBoxCheckedColor" |
| 150 | + UnCheckedColor="@EffectiveCheckBoxUnCheckedColor" /> |
| 151 | + |
| 152 | + <MudText Typo="GetTypo()" Color="@TextColor">@SelectAllText</MudText> |
136 | 153 | </div> |
137 | 154 | <MudDivider /> |
138 | 155 | } |
139 | 156 | </div> |
140 | 157 | } |
141 | 158 |
|
142 | 159 | @ChildContent |
143 | | - @if (NoItemsContent != null && !HasEligibleItems()) |
| 160 | + @if (NoItemsContent is not null && !HasEligibleItems()) |
144 | 161 | { |
145 | 162 | <div class="pa-2"> |
146 | 163 | @NoItemsContent |
|
0 commit comments