Makes Combobox item Value generic

This commit is contained in:
BinaryAlley committed 2024-09-04 17:55:34 +03:00
1 parent 98a3a23aab
commit cf7981aad4
2 files changed
+10 -7

No files matched your search

@@ -3,7 +3,8 @@
/// <summary>
/// Represents an item in a combobox.
/// </summary>
public class ComboboxItem
/// <typeparam name="TValue">The type used for the <see cref="Value"/> property of the item.</typeparam>
public class ComboboxItem<TValue>
{
#region ==================================================================== PROPERTIES =================================================================================
/// <summary>
@@ -14,6 +15,6 @@ public class ComboboxItem
/// <summary>
/// Gets or sets the value of the item, that is used by the application.
/// </summary>
public string? Value { get; set; }
public TValue? Value { get; set; }
#endregion
}
@@ -1,10 +1,12 @@
@using Lumina.Presentation.Web.Common.Models.UI
@using Lumina.Presentation.Web.Core.Services.UI
@inject ComboboxService _comboboxService
@typeparam TValue
@implements IDisposable
@inject ComboboxService _comboboxService
<div class="enlightenment-combobox inline-block w-100 @(IsOpen ? "open" : string.Empty) @CssClass">
<div class="shine-effect"></div>
<input type="checkbox" class="enlightenment-toggle-checkbox" @bind="IsOpen" id="@Id" @onclick="ToggleDropdown">
@@ -25,9 +27,9 @@
</div>
@code {
[Parameter] public List<ComboboxItem> Items { get; set; } = [];
[Parameter] public ComboboxItem? SelectedItem { get; set; }
[Parameter] public EventCallback<ComboboxItem> SelectedItemChanged { get; set; }
[Parameter] public List<ComboboxItem<TValue>> Items { get; set; } = [];
[Parameter] public ComboboxItem<TValue>? SelectedItem { get; set; }
[Parameter] public EventCallback<ComboboxItem<TValue>> SelectedItemChanged { get; set; }
[Parameter] public string? CssClass { get; set; }
private bool IsOpen { get; set; }
@@ -68,7 +70,7 @@
/// Selects the provided <paramref name="item"/>.
/// </summary>
/// <param name="item">The item to select.</param>
private async Task SelectItem(ComboboxItem? item)
private async Task SelectItem(ComboboxItem<TValue>? item)
{
SelectedItem = item;
IsOpen = false;