2024-05-04 09:08:18 +00:00
|
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
|
2024-08-21 06:30:01 +00:00
|
|
|
namespace AIStudio.Components;
|
2024-05-04 09:08:18 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Configuration component for any boolean option.
|
|
|
|
/// </summary>
|
2025-07-11 20:29:59 +00:00
|
|
|
public partial class ConfigurationOption : ConfigurationBaseCore
|
2024-05-04 09:08:18 +00:00
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Text to display when the option is true.
|
|
|
|
/// </summary>
|
|
|
|
[Parameter]
|
|
|
|
public string LabelOn { get; set; } = string.Empty;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Text to display when the option is false.
|
|
|
|
/// </summary>
|
|
|
|
[Parameter]
|
|
|
|
public string LabelOff { get; set; } = string.Empty;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// The boolean state of the option.
|
|
|
|
/// </summary>
|
|
|
|
[Parameter]
|
|
|
|
public Func<bool> State { get; set; } = () => false;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// An action which is called when the option is changed.
|
|
|
|
/// </summary>
|
|
|
|
[Parameter]
|
|
|
|
public Action<bool> StateUpdate { get; set; } = _ => { };
|
|
|
|
|
2025-07-22 05:55:15 +00:00
|
|
|
#region Overrides of ConfigurationBase
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
protected override bool Stretch => true;
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
protected override Variant Variant => Variant.Outlined;
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
protected override string Label => this.OptionDescription;
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
2024-05-04 09:08:18 +00:00
|
|
|
private async Task OptionChanged(bool updatedState)
|
|
|
|
{
|
|
|
|
this.StateUpdate(updatedState);
|
|
|
|
await this.SettingsManager.StoreSettings();
|
2024-07-24 13:17:45 +00:00
|
|
|
await this.InformAboutChange();
|
2024-05-04 09:08:18 +00:00
|
|
|
}
|
|
|
|
}
|