mirror of
https://gitee.com/LongbowEnterprise/BootstrapBlazor.git
synced 2024-12-05 13:39:39 +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
|
@namespace BootstrapBlazor.Components
|
||||||
@inherits BootstrapComponentBase
|
@inherits BootstrapComponentBase
|
||||||
|
|
||||||
@if (ChildContent != null)
|
<a @attributes="@AdditionalAttributes" href="@Url" @onclick="@OnClickLink">@RenderChildContent()</a>
|
||||||
{
|
|
||||||
<a @attributes="@AdditionalAttributes" href="@Url" @onclick="@OnClickLink">@ChildContent</a>
|
|
||||||
}
|
|
||||||
|
@ -65,5 +65,27 @@ namespace BootstrapBlazor.Components
|
|||||||
TabItemOptions.Text = Text;
|
TabItemOptions.Text = Text;
|
||||||
TabItemOptions.Closable = Closable;
|
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 Microsoft.Extensions.DependencyInjection;
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace BootstrapBlazor.Components
|
namespace BootstrapBlazor.Components;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// NavigationManager 扩展方法
|
||||||
|
/// </summary>
|
||||||
|
public static class NavigationManagerExtensions
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
/// 导航并添加 TabItem 方法
|
||||||
/// </summary>
|
/// </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>
|
var option = provider.GetRequiredService<TabItemTextOptions>();
|
||||||
/// 导航并添加 TabItem 方法
|
option.Text = text;
|
||||||
/// </summary>
|
option.Icon = icon;
|
||||||
/// <param name="navigation"></param>
|
option.IsActive = true;
|
||||||
/// <param name="provider"></param>
|
option.Closable = closable ?? true;
|
||||||
/// <param name="url"></param>
|
navigation.NavigateTo(url);
|
||||||
/// <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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user