mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-10-17 23:18:00 +00:00
Refactor components (#80)
This commit is contained in:
1 parent
a18cb22263
commit
1d1af91f3e
137 files changed
+220
-220
No files matched your search
@@ -0,0 +1,79 @@
|
||||
using AIStudio.Settings;
|
||||
|
||||
using Microsoft.AspNetCore.Components;
|
||||
|
||||
namespace AIStudio.Components;
|
||||
|
||||
public partial class EnumSelection<T> : EnumSelectionBase where T : struct, Enum
|
||||
{
|
||||
[Parameter]
|
||||
public T Value { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public EventCallback<T> 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<string> OtherInputChanged { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public string Label { get; set; } = string.Empty;
|
||||
|
||||
[Parameter]
|
||||
public string LabelOther { get; set; } = "Other";
|
||||
|
||||
[Parameter]
|
||||
public Func<T, string?> ValidateSelection { get; set; } = _ => null;
|
||||
|
||||
[Parameter]
|
||||
public Func<string, string?> ValidateOther { get; set; } = _ => null;
|
||||
|
||||
[Parameter]
|
||||
public string Icon { get; set; } = Icons.Material.Filled.ArrowDropDown;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the custom name function for selecting the display name of an enum value.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The enum type.</typeparam>
|
||||
/// <param name="value">The enum value.</param>
|
||||
/// <returns>The display name of the enum value.</returns>
|
||||
[Parameter]
|
||||
public Func<T, string> NameFunc { get; set; } = value => value.ToString();
|
||||
|
||||
[Parameter]
|
||||
public Func<T, Task> 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);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user