mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2025-04-28 22:19:48 +00:00
Added configuration component for numeric sliders
This commit is contained in:
parent
d18be45eb6
commit
834114249f
@ -0,0 +1,8 @@
|
|||||||
|
@typeparam T
|
||||||
|
@inherits ConfigurationBase
|
||||||
|
|
||||||
|
<MudField Label="@this.OptionDescription" Variant="Variant.Outlined" Class="mb-3">
|
||||||
|
<MudSlider @ref="@this.slider" T="@T" Size="Size.Medium" Value="@this.Value()" ValueChanged="@this.OptionChanged" Min="@this.Min" Max="@this.Max" Step="@this.Step" Immediate="@true">
|
||||||
|
@this.Value() @this.Unit
|
||||||
|
</MudSlider>
|
||||||
|
</MudField>
|
@ -0,0 +1,95 @@
|
|||||||
|
using System.Numerics;
|
||||||
|
|
||||||
|
using AIStudio.Tools;
|
||||||
|
|
||||||
|
using Microsoft.AspNetCore.Components;
|
||||||
|
|
||||||
|
namespace AIStudio.Components.Blocks;
|
||||||
|
|
||||||
|
public partial class ConfigurationSlider<T> : ConfigurationBase, IMessageBusReceiver where T : struct, INumber<T>
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The minimum value for the slider.
|
||||||
|
/// </summary>
|
||||||
|
[Parameter]
|
||||||
|
public T Min { get; set; } = T.Zero;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The maximum value for the slider.
|
||||||
|
/// </summary>
|
||||||
|
[Parameter]
|
||||||
|
public T Max { get; set; } = T.One;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The step size for the slider.
|
||||||
|
/// </summary>
|
||||||
|
[Parameter]
|
||||||
|
public T Step { get; set; } = T.One;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The unit to display next to the slider's value.
|
||||||
|
/// </summary>
|
||||||
|
[Parameter]
|
||||||
|
public string Unit { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The value used for the slider.
|
||||||
|
/// </summary>
|
||||||
|
[Parameter]
|
||||||
|
public Func<T> Value { get; set; } = () => T.Zero;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// An action which is called when the option is changed.
|
||||||
|
/// </summary>
|
||||||
|
[Parameter]
|
||||||
|
public Action<T> ValueUpdate { get; set; } = _ => { };
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Is the option disabled?
|
||||||
|
/// </summary>
|
||||||
|
[Parameter]
|
||||||
|
public Func<bool> Disabled { get; set; } = () => false;
|
||||||
|
|
||||||
|
private MudSlider<T> slider = null!;
|
||||||
|
|
||||||
|
#region Overrides of ComponentBase
|
||||||
|
|
||||||
|
protected override async Task OnInitializedAsync()
|
||||||
|
{
|
||||||
|
// Register this component with the message bus:
|
||||||
|
this.MessageBus.RegisterComponent(this);
|
||||||
|
this.MessageBus.ApplyFilters(this, [], [ Event.CONFIGURATION_CHANGED ]);
|
||||||
|
|
||||||
|
await base.OnInitializedAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private async Task OptionChanged(T updatedValue)
|
||||||
|
{
|
||||||
|
this.ValueUpdate(updatedValue);
|
||||||
|
await this.SettingsManager.StoreSettings();
|
||||||
|
await this.InformAboutChange();
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Implementation of IMessageBusReceiver
|
||||||
|
|
||||||
|
public Task ProcessMessage<TMsg>(ComponentBase? sendingComponent, Event triggeredEvent, TMsg? data)
|
||||||
|
{
|
||||||
|
switch (triggeredEvent)
|
||||||
|
{
|
||||||
|
case Event.CONFIGURATION_CHANGED:
|
||||||
|
this.StateHasChanged();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<TResult?> ProcessMessageWithResult<TPayload, TResult>(ComponentBase? sendingComponent, Event triggeredEvent, TPayload? data)
|
||||||
|
{
|
||||||
|
return Task.FromResult<TResult?>(default);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user