ant-design-blazor/site/AntDesign.Docs/Shared/Style.razor
2021-02-06 20:15:46 +08:00

33 lines
827 B
C#

@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);
}
}
}
}