-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlazorTag.cs
More file actions
27 lines (23 loc) · 1.02 KB
/
BlazorTag.cs
File metadata and controls
27 lines (23 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
using Microsoft.AspNetCore.Components.Rendering;
using Microsoft.AspNetCore.Components;
using Microsoft.DotNet.Interactive.Formatting.TabularData;
using Microsoft.DotNet.Interactive.Formatting;
namespace Naratteu.DotNet.Interactive.Formatting.Blazor;
public class BlazorTag : ComponentBase
{
[Parameter] public required string Name { get; init; }
[Parameter] public Dictionary<string, object>? Attr { get; init; }
[Parameter] public RenderFragment? ChildContent { get; set; }
protected override void BuildRenderTree(RenderTreeBuilder builder)
{
builder.OpenElement(0, Name);
builder.AddMultipleAttributes(1, Attr);
builder.AddContent(2, ChildContent);
builder.CloseElement();
}
}
public static class BlazorTagExtension
{
public static RenderFragment ToDisplayHtml(this object o) => BlazorTagStatic.ToBlazorHtml(o.ToDisplayString(HtmlFormatter.MimeType));
public static RenderFragment ToTableHtml<T>(this IEnumerable<T> t) => t.ToTabularDataResource().ToDisplayHtml();
}