ant-design-blazor/site/AntDesign.Docs/Shared/Style.razor

33 lines
827 B
C#
Raw Normal View History

@using System.Net
@using AntDesign.Docs.Utils
@inherits ComponentBase
@inject HtmlRenderService HtmlRenderService
@((MarkupString)$"<style>{Styles}</style>")
@code {
[Parameter]
public RenderFragment ChildContent { get; set; }
[Parameter]
public string ScopeId { get; set; }
protected string Styles { get; set; }
protected override async Task OnInitializedAsync()
{
if (ChildContent != null)
{
var text = await HtmlRenderService.RenderAsync(ChildContent);
var style = WebUtility.HtmlDecode(text)?.Replace("<style>", "").Replace("</style>", "");
if (!string.IsNullOrEmpty(style))
{
var parser = new CSSParser(style);
Styles = parser.AddScopeIdToString(ScopeId);
}
}
}
}