using AIStudio.Settings; using Microsoft.AspNetCore.Components; namespace AIStudio.Components; public partial class EnumSelection : EnumSelectionBase where T : struct, Enum { [Parameter] public T Value { get; set; } [Parameter] public EventCallback ValueChanged { get; set; } [Parameter] public bool AllowOther { get; set; } [Parameter] public T OtherValue { get; set; } [Parameter] public string OtherInput { get; set; } = string.Empty; [Parameter] public EventCallback OtherInputChanged { get; set; } [Parameter] public string Label { get; set; } = string.Empty; [Parameter] public string LabelOther { get; set; } = "Other"; [Parameter] public Func ValidateSelection { get; set; } = _ => null; [Parameter] public Func ValidateOther { get; set; } = _ => null; [Parameter] public string Icon { get; set; } = Icons.Material.Filled.ArrowDropDown; /// /// Gets or sets the custom name function for selecting the display name of an enum value. /// /// The enum type. /// The enum value. /// The display name of the enum value. [Parameter] public Func NameFunc { get; set; } = value => value.ToString(); [Parameter] public Func SelectionUpdated { get; set; } = _ => Task.CompletedTask; [Inject] private SettingsManager SettingsManager { get; set; } = null!; #region Overrides of ComponentBase protected override async Task OnInitializedAsync() { // Configure the spellchecking for the user input: this.SettingsManager.InjectSpellchecking(USER_INPUT_ATTRIBUTES); await base.OnInitializedAsync(); } #endregion private async Task SelectionChanged(T value) { await this.ValueChanged.InvokeAsync(value); await this.SelectionUpdated(value); } private async Task OtherValueChanged(string value) { await this.OtherInputChanged.InvokeAsync(value); await this.SelectionUpdated(this.Value); } }