AI-Studio/app/MindWork AI Studio/Components/EnumSelection.razor.cs
nilskruthoff a1d2ff32fc
Some checks are pending
Build and Release / Determine run mode (push) Waiting to run
Build and Release / Read metadata (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-apple-darwin, osx-arm64, macos-latest, aarch64-apple-darwin, dmg,app,updater, dmg) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-pc-windows-msvc.exe, win-arm64, windows-latest, aarch64-pc-windows-msvc, nsis,updater, nsis) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-unknown-linux-gnu, linux-arm64, ubuntu-22.04-arm, aarch64-unknown-linux-gnu, appimage,updater, appimage) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-apple-darwin, osx-x64, macos-latest, x86_64-apple-darwin, dmg,app,updater, dmg) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-pc-windows-msvc.exe, win-x64, windows-latest, x86_64-pc-windows-msvc, nsis,updater, nsis) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-unknown-linux-gnu, linux-x64, ubuntu-22.04, x86_64-unknown-linux-gnu, appimage,updater, appimage) (push) Blocked by required conditions
Build and Release / Prepare & create release (push) Blocked by required conditions
Build and Release / Publish release (push) Blocked by required conditions
Added a no-code assistant builder (#823)
2026-07-05 17:48:00 +02:00

88 lines
2.4 KiB
C#

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 whether the selection controls are disabled.
/// </summary>
[Parameter]
public bool Disabled { get; set; }
[Parameter]
public Size IconSize { get; set; } = Size.Medium;
/// <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);
}
}