diff --git a/app/MindWork AI Studio/Assistants/Dynamic/AssistantDynamic.razor b/app/MindWork AI Studio/Assistants/Dynamic/AssistantDynamic.razor index 9e10140c..434cd066 100644 --- a/app/MindWork AI Studio/Assistants/Dynamic/AssistantDynamic.razor +++ b/app/MindWork AI Studio/Assistants/Dynamic/AssistantDynamic.razor @@ -103,9 +103,23 @@ } break; case AssistantComponentType.SWITCH: - if (component is AssistantSwitch assistantSwitch) + if (component is AssistantSwitch switchComponent) { - + var assistantSwitch = switchComponent; + var currentValue = this.switchFields[assistantSwitch.Name]; + + + @(currentValue ? assistantSwitch.LabelOn : assistantSwitch.LabelOff) + + } break; case AssistantComponentType.HEADING: diff --git a/app/MindWork AI Studio/Plugins/assistants/plugin.lua b/app/MindWork AI Studio/Plugins/assistants/plugin.lua index 86ff9300..cabe3838 100644 --- a/app/MindWork AI Studio/Plugins/assistants/plugin.lua +++ b/app/MindWork AI Studio/Plugins/assistants/plugin.lua @@ -107,9 +107,15 @@ ASSISTANT = { ["Name"] = "", -- required ["Label"] = "", -- required ["Value"] = true, -- initial switch state + ["Disabled"] = false, -- if true, disables user interaction but the value can still be used in the user prompt (use for presentation purposes) ["UserPrompt"] = "", - ["LabelOn"] = "", -- required - ["LabelOff"] = "" -- required + ["LabelOn"] = "", + ["LabelOff"] = "", + ["LabelPlacement"] = "", -- Defaults to End (right of the switch) + ["Icon"] = "Icons.Material.Filled.Bolt", -- places a thumb icon inside the switch + ["IconColor"] = "", -- color of the thumb icon. Defaults to `Inherit` + ["CheckedColor"] = "", -- color of the switch if state is true. Defaults to `Inherit` + ["UncheckedColor"] = "", -- color of the switch if state is false. Defaults to `Inherit` } }, { diff --git a/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/AssistantSwitch.cs b/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/AssistantSwitch.cs index d07b94ac..7de760ac 100644 --- a/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/AssistantSwitch.cs +++ b/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/AssistantSwitch.cs @@ -1,3 +1,5 @@ +using AIStudio.Tools.PluginSystem.Assistants.Icons; + namespace AIStudio.Tools.PluginSystem.Assistants.DataModel; internal sealed class AssistantSwitch : AssistantComponentBase @@ -23,6 +25,12 @@ internal sealed class AssistantSwitch : AssistantComponentBase get => AssistantComponentPropHelper.ReadBool(this.Props, nameof(this.Value), false); set => AssistantComponentPropHelper.WriteBool(this.Props, nameof(this.Value), value); } + + public bool Disabled + { + get => AssistantComponentPropHelper.ReadBool(this.Props, nameof(this.Disabled), false); + set => AssistantComponentPropHelper.WriteBool(this.Props, nameof(this.Disabled), value); + } public string UserPrompt { @@ -41,5 +49,38 @@ internal sealed class AssistantSwitch : AssistantComponentBase get => AssistantComponentPropHelper.ReadString(this.Props, nameof(this.LabelOff)); set => AssistantComponentPropHelper.WriteString(this.Props, nameof(this.LabelOff), value); } + + public string LabelPlacement + { + get => AssistantComponentPropHelper.ReadString(this.Props, nameof(this.LabelPlacement)); + set => AssistantComponentPropHelper.WriteString(this.Props, nameof(this.LabelPlacement), value); + } + public string CheckedColor + { + get => AssistantComponentPropHelper.ReadString(this.Props, nameof(this.CheckedColor)); + set => AssistantComponentPropHelper.WriteString(this.Props, nameof(this.CheckedColor), value); + } + + public string UncheckedColor + { + get => AssistantComponentPropHelper.ReadString(this.Props, nameof(this.UncheckedColor)); + set => AssistantComponentPropHelper.WriteString(this.Props, nameof(this.UncheckedColor), value); + } + + public string Icon + { + get => AssistantComponentPropHelper.ReadString(this.Props, nameof(this.Icon)); + set => AssistantComponentPropHelper.WriteString(this.Props, nameof(this.Icon), value); + } + + public string IconColor + { + get => AssistantComponentPropHelper.ReadString(this.Props, nameof(this.IconColor)); + set => AssistantComponentPropHelper.WriteString(this.Props, nameof(this.IconColor), value); + } + + public MudBlazor.Color GetColor(string colorString) => Enum.TryParse(colorString, out var color) ? color : MudBlazor.Color.Inherit; + public Placement GetLabelPlacement() => Enum.TryParse(this.LabelPlacement, out var placement) ? placement : Placement.Right; + public string GetIconSvg() => MudBlazorIconRegistry.TryGetSvg(this.Icon, out var svg) ? svg : string.Empty; } diff --git a/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/ComponentPropSpecs.cs b/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/ComponentPropSpecs.cs index 4cdbb8c4..6525f7f7 100644 --- a/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/ComponentPropSpecs.cs +++ b/app/MindWork AI Studio/Tools/PluginSystem/Assistants/DataModel/ComponentPropSpecs.cs @@ -34,8 +34,8 @@ public static class ComponentPropSpecs optional: ["ValidationMessage", "Class", "Style"] ), [AssistantComponentType.SWITCH] = new( - required: ["Name", "Label", "LabelOn", "LabelOff", "Value"], - optional: ["UserPrompt"] + required: ["Name", "Label", "Value"], + optional: [ "LabelOn", "LabelOff", "LabelPlacement", "Icon", "IconColor", "UserPrompt", "CheckedColor", "UncheckedColor", "Disabled"] ), [AssistantComponentType.HEADING] = new( required: ["Text", "Level"],