!2263 refactor(#I4OJRD): redesign Tab component

* doc: 格式化文档
* refactor: 更新 TabLink 内部逻辑
This commit is contained in:
Argo 2021-12-29 04:44:06 +00:00
parent 4278593c31
commit d9c5f0cfbe
3 changed files with 43 additions and 25 deletions

View File

@ -1,7 +1,4 @@
@namespace BootstrapBlazor.Components
@inherits BootstrapComponentBase
@if (ChildContent != null)
{
<a @attributes="@AdditionalAttributes" href="@Url" @onclick="@OnClickLink">@ChildContent</a>
}
<a @attributes="@AdditionalAttributes" href="@Url" @onclick="@OnClickLink">@RenderChildContent()</a>

View File

@ -65,5 +65,27 @@ namespace BootstrapBlazor.Components
TabItemOptions.Text = Text;
TabItemOptions.Closable = Closable;
}
private RenderFragment RenderChildContent() => builder =>
{
var index = 0;
if (ChildContent == null)
{
if (!string.IsNullOrEmpty(Icon))
{
builder.OpenElement(index++, "i");
builder.AddAttribute(index++, "class", Icon);
builder.CloseElement();
}
if (!string.IsNullOrEmpty(Text))
{
builder.AddContent(index++, Text);
}
}
else
{
builder.AddContent(index++, ChildContent);
}
};
}
}

View File

@ -6,13 +6,13 @@ using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.DependencyInjection;
using System;
namespace BootstrapBlazor.Components
namespace BootstrapBlazor.Components;
/// <summary>
/// NavigationManager 扩展方法
/// </summary>
public static class NavigationManagerExtensions
{
/// <summary>
///
/// </summary>
public static class NavigationManagerExtensions
{
/// <summary>
/// 导航并添加 TabItem 方法
/// </summary>
@ -31,5 +31,4 @@ namespace BootstrapBlazor.Components
option.Closable = closable ?? true;
navigation.NavigateTo(url);
}
}
}