diff --git a/app/MindWork AI Studio/Components/CodeBlock.razor b/app/MindWork AI Studio/Components/CodeBlock.razor new file mode 100644 index 00000000..f0a4167a --- /dev/null +++ b/app/MindWork AI Studio/Components/CodeBlock.razor @@ -0,0 +1,15 @@ + +@if (!this.IsInline) +{ + @if (this.ParentTabs is null) + { + +
@this.ChildContent
+
+ } +} +else +{ + @this.ChildContent +} + diff --git a/app/MindWork AI Studio/Components/CodeBlock.razor.cs b/app/MindWork AI Studio/Components/CodeBlock.razor.cs new file mode 100644 index 00000000..da6caa3b --- /dev/null +++ b/app/MindWork AI Studio/Components/CodeBlock.razor.cs @@ -0,0 +1,42 @@ +using Microsoft.AspNetCore.Components; +using MudBlazor.Utilities; + +namespace AIStudio.Components; + +public partial class CodeBlock : ComponentBase +{ + [Parameter] + public RenderFragment? ChildContent { get; set; } + + [Parameter] + public string? Title { get; set; } = string.Empty; + + [Parameter] + public bool IsInline { get; set; } = false; + + [CascadingParameter] + public CodeTabs? ParentTabs { get; set; } + + private static readonly string DARK_BACKGROUND_COLOR = "#2d2d2d"; + private static readonly string DARK_FOREGROUND_COLOR = "#f8f8f2"; + + protected override void OnInitialized() + { + if (this.ParentTabs is not null && this.Title is not null) + { + RenderFragment blockSelf = builder => + { + builder.OpenComponent(0); + builder.AddAttribute(1, "Title", this.Title); + builder.AddAttribute(2, "ChildContent", this.ChildContent); + builder.CloseComponent(); + }; + this.ParentTabs.RegisterBlock(this.Title, blockSelf); + } + } + + private string BlockPadding() + { + return this.ParentTabs is null ? "padding: 16px !important;" : "padding: 8px !important"; + } +} \ No newline at end of file diff --git a/app/MindWork AI Studio/Components/CodeTabs.razor b/app/MindWork AI Studio/Components/CodeTabs.razor new file mode 100644 index 00000000..1a6dacc1 --- /dev/null +++ b/app/MindWork AI Studio/Components/CodeTabs.razor @@ -0,0 +1,11 @@ + + @foreach (var block in blocks) + { + + @block.Fragment + + } + + + @this.ChildContent + diff --git a/app/MindWork AI Studio/Components/CodeTabs.razor.cs b/app/MindWork AI Studio/Components/CodeTabs.razor.cs new file mode 100644 index 00000000..1640e51a --- /dev/null +++ b/app/MindWork AI Studio/Components/CodeTabs.razor.cs @@ -0,0 +1,28 @@ +using Microsoft.AspNetCore.Components; + +namespace AIStudio.Components; + +public partial class CodeTabs : ComponentBase +{ + [Parameter] + public RenderFragment? ChildContent { get; set; } + + private List blocks = new(); + private int selectedIndex = 0; + + internal void RegisterBlock(string title, RenderFragment fragment) + { + this.blocks.Add(new CodeTabItem + { + Title = title, + Fragment = fragment, + }); + this.StateHasChanged(); + } + + private class CodeTabItem + { + public string Title { get; init; } = string.Empty; + public RenderFragment Fragment { get; init; } + } +} \ No newline at end of file