ant-design-blazor/components/typography/AntTitle.cs
Bin Dong 46ca380a11 feat(typography): polish typograph copy related functions. (#16)
* doct: Add DemoCard component

* doc: Update Button demo page.

* doct: Add DemoCard component

* feat:(typography)( Add copyable icon render and corresponding trial functions.
Add a console.log() wrap up for jsinterop testing.
Temporarily use log instead of copy before copy is implemented.
Add copyable demo in demo project.

* feat (typography): polish typograph copy related functions.

* doct: Add DemoCard component

* feat:(typography)( Add copyable icon render and corresponding trial functions.
Add a console.log() wrap up for jsinterop testing.
Temporarily use log instead of copy before copy is implemented.
Add copyable demo in demo project.

* feat (typography): polish typograph copy related functions.
2020-03-12 16:35:23 +08:00

63 lines
2.1 KiB
C#

using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Rendering;
using System;
using System.Collections.Generic;
using System.Text;
namespace AntBlazor
{
public class AntTitle : AntTypographyBase
{
[Parameter]
public int level { get; set; } = 1;
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)
{
base.BuildRenderTree(builder);
// According to Ant-Design 4.0, Fallback to 1 if level is invalid.
int localLevel = level < 1 || level > 4 ? 1 : level;
builder.OpenElement(0, "h" + localLevel);
builder.AddAttribute(1, "class", this.ClassMapper.Class);
if (mark) builder.OpenElement(2, "mark");
if (delete) builder.OpenElement(3, "del");
if (underline) builder.OpenElement(4, "u");
builder.AddContent(5, ChildContent);
if (underline) builder.CloseElement();
if (delete) builder.CloseElement();
if (mark) builder.CloseElement();
if (copyable)
{
builder.OpenElement(6, "a");
builder.AddAttribute(7, "onclick", (Action)(async () => await Copy()));
builder.OpenComponent<AntIcon>(8);
builder.AddAttribute(9, "type", "copy");
builder.AddAttribute(10, "theme", AntIconThemeType.Outline);
builder.CloseComponent();
builder.CloseElement();
}
builder.CloseElement();
}
}
}