mirror of
https://gitee.com/LongbowEnterprise/BootstrapBlazor.git
synced 2024-12-05 05:29:47 +08:00
!2263 refactor(#I4OJRD): redesign Tab component
* doc: 格式化文档 * refactor: 更新 TabLink 内部逻辑
This commit is contained in:
parent
4278593c31
commit
d9c5f0cfbe
@ -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>
|
||||
|
@ -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);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -6,30 +6,29 @@ using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System;
|
||||
|
||||
namespace BootstrapBlazor.Components
|
||||
namespace BootstrapBlazor.Components;
|
||||
|
||||
/// <summary>
|
||||
/// NavigationManager 扩展方法
|
||||
/// </summary>
|
||||
public static class NavigationManagerExtensions
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// 导航并添加 TabItem 方法
|
||||
/// </summary>
|
||||
public static class NavigationManagerExtensions
|
||||
/// <param name="navigation"></param>
|
||||
/// <param name="provider"></param>
|
||||
/// <param name="url"></param>
|
||||
/// <param name="text"></param>
|
||||
/// <param name="icon"></param>
|
||||
/// <param name="closable"></param>
|
||||
public static void NavigateTo(this NavigationManager navigation, IServiceProvider provider, string url, string text, string? icon = null, bool? closable = null)
|
||||
{
|
||||
/// <summary>
|
||||
/// 导航并添加 TabItem 方法
|
||||
/// </summary>
|
||||
/// <param name="navigation"></param>
|
||||
/// <param name="provider"></param>
|
||||
/// <param name="url"></param>
|
||||
/// <param name="text"></param>
|
||||
/// <param name="icon"></param>
|
||||
/// <param name="closable"></param>
|
||||
public static void NavigateTo(this NavigationManager navigation, IServiceProvider provider, string url, string text, string? icon = null, bool? closable = null)
|
||||
{
|
||||
var option = provider.GetRequiredService<TabItemTextOptions>();
|
||||
option.Text = text;
|
||||
option.Icon = icon;
|
||||
option.IsActive = true;
|
||||
option.Closable = closable ?? true;
|
||||
navigation.NavigateTo(url);
|
||||
}
|
||||
var option = provider.GetRequiredService<TabItemTextOptions>();
|
||||
option.Text = text;
|
||||
option.Icon = icon;
|
||||
option.IsActive = true;
|
||||
option.Closable = closable ?? true;
|
||||
navigation.NavigateTo(url);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user