UI for Pandoc integration (#393)

Co-authored-by: Thorsten Sommer
This commit is contained in:
nilskruthoffandThorsten Sommer authored and GitHub committed 2025-05-29 14:01:56 +02:00
1 parent 1d31fd9a22
commit 5b685193ef
15 files changed
+766 -4

No files matched your search

@@ -0,0 +1,15 @@
@if (!this.IsInline)
{
@if (this.ParentTabs is null)
{
<MudPaper Class="code-block no-elevation" Style="@this.BlockPadding()">
<pre><code>@this.ChildContent</code></pre>
</MudPaper>
}
}
else
{
<span class="inline-code-block"><kbd>@this.ChildContent</kbd></span>
}
@@ -0,0 +1,40 @@
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Rendering;
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; }
[CascadingParameter]
public CodeTabs? ParentTabs { get; set; }
protected override void OnInitialized()
{
if (this.ParentTabs is not null && this.Title is not null)
{
void BlockSelf(RenderTreeBuilder builder)
{
builder.OpenComponent<CodeBlock>(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";
}
}
@@ -0,0 +1,11 @@
<MudTabs @bind-ActivePanelIndex="selectedIndex" PanelClass="code-block" MinimumTabWidth="30px" Class="mt-2">
@foreach (var block in blocks)
{
<MudTabPanel Text="@block.Title">
@block.Fragment
</MudTabPanel>
}
</MudTabs>
<CascadingValue Value="this">
@this.ChildContent
</CascadingValue>
@@ -0,0 +1,30 @@
using Microsoft.AspNetCore.Components;
namespace AIStudio.Components;
public partial class CodeTabs : ComponentBase
{
[Parameter]
public RenderFragment? ChildContent { get; set; }
private readonly List<CodeTabItem> blocks = new();
private int selectedIndex;
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; } = null!;
}
}