mirror of
https://gitee.com/ant-design-blazor/ant-design-blazor.git
synced 2024-12-15 01:11:52 +08:00
50 lines
1.6 KiB
C#
50 lines
1.6 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;
|
|||
|
[Parameter]
|
|||
|
public RenderFragment ChildContent { get; set; }
|
|||
|
|
|||
|
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 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();
|
|||
|
builder.CloseElement();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|