From d9c5f0cfbec28e889f99c2a62c0ef2b7f784da3b Mon Sep 17 00:00:00 2001 From: Argo Date: Wed, 29 Dec 2021 04:44:06 +0000 Subject: [PATCH] =?UTF-8?q?!2263=20refactor(#I4OJRD):=20redesign=20Tab=20c?= =?UTF-8?q?omponent=20*=20doc:=20=E6=A0=BC=E5=BC=8F=E5=8C=96=E6=96=87?= =?UTF-8?q?=E6=A1=A3=20*=20refactor:=20=E6=9B=B4=E6=96=B0=20TabLink=20?= =?UTF-8?q?=E5=86=85=E9=83=A8=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/Tab/TabLink.razor | 5 +-- .../Components/Tab/TabLink.razor.cs | 22 ++++++++++ .../Extensions/NavigationManagerExtensions.cs | 41 +++++++++---------- 3 files changed, 43 insertions(+), 25 deletions(-) diff --git a/src/BootstrapBlazor/Components/Tab/TabLink.razor b/src/BootstrapBlazor/Components/Tab/TabLink.razor index 64e409c84..be8c30b28 100644 --- a/src/BootstrapBlazor/Components/Tab/TabLink.razor +++ b/src/BootstrapBlazor/Components/Tab/TabLink.razor @@ -1,7 +1,4 @@ @namespace BootstrapBlazor.Components @inherits BootstrapComponentBase -@if (ChildContent != null) -{ - @ChildContent -} +@RenderChildContent() diff --git a/src/BootstrapBlazor/Components/Tab/TabLink.razor.cs b/src/BootstrapBlazor/Components/Tab/TabLink.razor.cs index d2da82ad3..4137e2179 100644 --- a/src/BootstrapBlazor/Components/Tab/TabLink.razor.cs +++ b/src/BootstrapBlazor/Components/Tab/TabLink.razor.cs @@ -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); + } + }; } } diff --git a/src/BootstrapBlazor/Extensions/NavigationManagerExtensions.cs b/src/BootstrapBlazor/Extensions/NavigationManagerExtensions.cs index 8b7d5a2e8..f7ea741e5 100644 --- a/src/BootstrapBlazor/Extensions/NavigationManagerExtensions.cs +++ b/src/BootstrapBlazor/Extensions/NavigationManagerExtensions.cs @@ -6,30 +6,29 @@ using Microsoft.AspNetCore.Components; using Microsoft.Extensions.DependencyInjection; using System; -namespace BootstrapBlazor.Components +namespace BootstrapBlazor.Components; + +/// +/// NavigationManager 扩展方法 +/// +public static class NavigationManagerExtensions { /// - /// + /// 导航并添加 TabItem 方法 /// - public static class NavigationManagerExtensions + /// + /// + /// + /// + /// + /// + public static void NavigateTo(this NavigationManager navigation, IServiceProvider provider, string url, string text, string? icon = null, bool? closable = null) { - /// - /// 导航并添加 TabItem 方法 - /// - /// - /// - /// - /// - /// - /// - public static void NavigateTo(this NavigationManager navigation, IServiceProvider provider, string url, string text, string? icon = null, bool? closable = null) - { - var option = provider.GetRequiredService(); - option.Text = text; - option.Icon = icon; - option.IsActive = true; - option.Closable = closable ?? true; - navigation.NavigateTo(url); - } + var option = provider.GetRequiredService(); + option.Text = text; + option.Icon = icon; + option.IsActive = true; + option.Closable = closable ?? true; + navigation.NavigateTo(url); } }