ant-design-blazor/components/typography/Paragraph.cs

76 lines
2.6 KiB
C#
Raw Normal View History

using System;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Rendering;
namespace AntDesign
{
public class Paragraph : TypographyBase
{
[Parameter]
public bool Code { get; set; } = false;
[Parameter]
public bool Keyboard { get; set; } = false;
protected override void OnInitialized()
{
base.OnInitialized();
SetClassMap();
}
protected void SetClassMap()
{
string prefixName = "ant-typography";
ClassMapper.Clear()
.Add("ant-typography")
.If($"{prefixName}-{Type}", () => !string.IsNullOrEmpty(Type))
.If($"{prefixName}-disabled", () => Disabled);
}
protected override void OnParametersSet()
{
base.OnParametersSet();
SetClassMap();
}
protected override void BuildRenderTree(RenderTreeBuilder builder)
{
2020-04-24 18:32:50 +08:00
if (builder != null)
{
int i = 0;
2020-04-24 18:32:50 +08:00
base.BuildRenderTree(builder);
builder.OpenElement(i++, "div");
builder.AddAttribute(i++, "class", this.ClassMapper.Class);
builder.AddAttribute(i++, "style", Style);
builder.OpenElement(i++, "span");
if (Mark) builder.OpenElement(i++, "mark");
if (Delete) builder.OpenElement(i++, "del");
if (Underline) builder.OpenElement(i++, "u");
if (Code) builder.OpenElement(i++, "code");
if (Keyboard) builder.OpenElement(i++, "kbd");
if (Strong) builder.OpenElement(i++, "strong");
builder.AddContent(i++, ChildContent);
2020-04-24 18:32:50 +08:00
if (Strong) builder.CloseElement();
if (Code) builder.CloseElement();
if (Keyboard) builder.CloseElement();
2020-04-24 18:32:50 +08:00
if (Underline) builder.CloseElement();
if (Delete) builder.CloseElement();
if (Mark) builder.CloseElement();
builder.CloseElement();
if (Copyable)
{
builder.OpenElement(i++, "a");
builder.AddAttribute(i++, "onclick", (Action)(async () => await Copy()));
builder.OpenComponent<Icon>(i++);
builder.AddAttribute(i++, "type", "copy");
builder.AddAttribute(i++, "theme", IconThemeType.Outline);
2020-04-24 18:32:50 +08:00
builder.CloseComponent();
builder.CloseElement();
}
builder.CloseElement();
}
}
}
}