From 7fb42d97f3bae27cea04803fec5510e166b8c054 Mon Sep 17 00:00:00 2001 From: Saleh Yusefnejad Date: Wed, 18 Feb 2026 18:00:47 +0330 Subject: [PATCH 1/3] add new Icon parameters to BitNav #12107 --- .../Navs/Nav/BitNav.razor.internal.cs | 39 ++++++++++- .../Navs/Nav/BitNav.razor.parameters.cs | 12 +++- .../Components/Navs/Nav/BitNavItem.cs | 15 +++- .../Navs/Nav/BitNavNameSelectors.cs | 5 ++ .../Components/Navs/Nav/BitNavOption.razor.cs | 15 +++- .../Components/Navs/Nav/_BitNavChild.razor | 15 ++-- .../Components/Navs/Nav/BitNavDemo.razor.cs | 69 ++++++++++++++++++- .../Components/Navs/Nav/_BitNavItemDemo.razor | 9 ++- .../Navs/Nav/_BitNavItemDemo.razor.cs | 57 ++++++++++++++- 9 files changed, 220 insertions(+), 16 deletions(-) diff --git a/src/BlazorUI/Bit.BlazorUI/Components/Navs/Nav/BitNav.razor.internal.cs b/src/BlazorUI/Bit.BlazorUI/Components/Navs/Nav/BitNav.razor.internal.cs index 4752100592..b22316c812 100644 --- a/src/BlazorUI/Bit.BlazorUI/Components/Navs/Nav/BitNav.razor.internal.cs +++ b/src/BlazorUI/Bit.BlazorUI/Components/Navs/Nav/BitNav.razor.internal.cs @@ -1,4 +1,4 @@ -namespace Bit.BlazorUI; +namespace Bit.BlazorUI; public partial class BitNav { @@ -217,6 +217,43 @@ internal bool GetForceAnchor(TItem item) return item.GetValueFromProperty(NameSelectors.ForceAnchor.Name, false); } + internal BitIconInfo? GetIcon(TItem item) + { + if (item is BitNavItem navItem) + { + return BitIconInfo.From(navItem.Icon, navItem.IconName); + } + + if (item is BitNavOption navOption) + { + return BitIconInfo.From(navOption.Icon, navOption.IconName); + } + + if (NameSelectors is null) return null; + + BitIconInfo? icon = null; + if (NameSelectors.Icon.Selector is not null) + { + icon = NameSelectors.Icon.Selector!(item); + } + else + { + icon = item.GetValueFromProperty(NameSelectors.Icon.Name); + } + + string? iconName = null; + if (NameSelectors.IconName.Selector is not null) + { + iconName = NameSelectors.IconName.Selector!(item); + } + else + { + iconName = item.GetValueFromProperty(NameSelectors.IconName.Name); + } + + return BitIconInfo.From(icon, iconName); + } + internal string? GetIconName(TItem item) { if (item is BitNavItem navItem) diff --git a/src/BlazorUI/Bit.BlazorUI/Components/Navs/Nav/BitNav.razor.parameters.cs b/src/BlazorUI/Bit.BlazorUI/Components/Navs/Nav/BitNav.razor.parameters.cs index f9eb458d98..9e646a62a8 100644 --- a/src/BlazorUI/Bit.BlazorUI/Components/Navs/Nav/BitNav.razor.parameters.cs +++ b/src/BlazorUI/Bit.BlazorUI/Components/Navs/Nav/BitNav.razor.parameters.cs @@ -1,4 +1,4 @@ -namespace Bit.BlazorUI; +namespace Bit.BlazorUI; public partial class BitNav { @@ -13,10 +13,18 @@ public partial class BitNav /// [Parameter] public bool AllExpanded { get; set; } + /// + /// The icon for the chevron-down element of each nav item. + /// Takes precedence over when both are set. + /// Use this property to render icons from external libraries like FontAwesome, Material Icons, or Bootstrap Icons. + /// For built-in Fluent UI icons, use instead. + /// + [Parameter] public BitIconInfo? ChevronDownIcon { get; set; } + /// /// The custom icon name of the chevron-down element of each nav item. /// - [Parameter] public string? ChevronDownIcon { get; set; } + [Parameter] public string? ChevronDownIconName { get; set; } /// /// Items to render as children. diff --git a/src/BlazorUI/Bit.BlazorUI/Components/Navs/Nav/BitNavItem.cs b/src/BlazorUI/Bit.BlazorUI/Components/Navs/Nav/BitNavItem.cs index 635f43e122..e35a795918 100644 --- a/src/BlazorUI/Bit.BlazorUI/Components/Navs/Nav/BitNavItem.cs +++ b/src/BlazorUI/Bit.BlazorUI/Components/Navs/Nav/BitNavItem.cs @@ -1,4 +1,4 @@ -namespace Bit.BlazorUI; +namespace Bit.BlazorUI; public class BitNavItem { @@ -47,6 +47,19 @@ public class BitNavItem /// public bool ForceAnchor { get; set; } + /// + /// Icon to render next to the nav item. + /// Takes precedence over when both are set. + /// Use this property to render icons from external libraries like FontAwesome, Material Icons, or Bootstrap Icons. + /// For built-in Fluent UI icons, use instead. + /// + /// + /// Bootstrap: Icon="BitIconInfo.Bi("gear-fill")" + /// FontAwesome: Icon = BitIconInfo.Fa("solid house") + /// Custom CSS: Icon = BitIconInfo.Css("my-icon-class") + /// + public BitIconInfo? Icon { get; set; } + /// /// Name of an icon to render next to the nav item. /// diff --git a/src/BlazorUI/Bit.BlazorUI/Components/Navs/Nav/BitNavNameSelectors.cs b/src/BlazorUI/Bit.BlazorUI/Components/Navs/Nav/BitNavNameSelectors.cs index 3d3a816801..2d8d21926d 100644 --- a/src/BlazorUI/Bit.BlazorUI/Components/Navs/Nav/BitNavNameSelectors.cs +++ b/src/BlazorUI/Bit.BlazorUI/Components/Navs/Nav/BitNavNameSelectors.cs @@ -47,6 +47,11 @@ public class BitNavNameSelectors /// public BitNameSelectorPair ForceAnchor { get; set; } = new(nameof(BitNavItem.ForceAnchor)); + /// + /// The Icon field name and selector of the custom input class (see ). + /// + public BitNameSelectorPair Icon { get; set; } = new(nameof(BitNavItem.Icon)); + /// /// The IconName field name and selector of the custom input class (see ). /// diff --git a/src/BlazorUI/Bit.BlazorUI/Components/Navs/Nav/BitNavOption.razor.cs b/src/BlazorUI/Bit.BlazorUI/Components/Navs/Nav/BitNavOption.razor.cs index c553645173..c4c171a210 100644 --- a/src/BlazorUI/Bit.BlazorUI/Components/Navs/Nav/BitNavOption.razor.cs +++ b/src/BlazorUI/Bit.BlazorUI/Components/Navs/Nav/BitNavOption.razor.cs @@ -1,4 +1,4 @@ -namespace Bit.BlazorUI; +namespace Bit.BlazorUI; public partial class BitNavOption : ComponentBase, IDisposable { @@ -61,6 +61,19 @@ public partial class BitNavOption : ComponentBase, IDisposable /// [Parameter] public bool ForceAnchor { get; set; } + /// + /// Icon to render next to the nav option. + /// Takes precedence over when both are set. + /// Use this property to render icons from external libraries like FontAwesome, Material Icons, or Bootstrap Icons. + /// For built-in Fluent UI icons, use instead. + /// + /// + /// Bootstrap: Icon="BitIconInfo.Bi("gear-fill")" + /// FontAwesome: Icon="BitIconInfo.Fa("solid house")" + /// Custom CSS: Icon="BitIconInfo.Css("my-icon-class")" + /// + [Parameter] public BitIconInfo? Icon { get; set; } + /// /// Name of an icon to render next to the nav option. /// diff --git a/src/BlazorUI/Bit.BlazorUI/Components/Navs/Nav/_BitNavChild.razor b/src/BlazorUI/Bit.BlazorUI/Components/Navs/Nav/_BitNavChild.razor index 13b479a432..3ee519234e 100644 --- a/src/BlazorUI/Bit.BlazorUI/Components/Navs/Nav/_BitNavChild.razor +++ b/src/BlazorUI/Bit.BlazorUI/Components/Navs/Nav/_BitNavChild.razor @@ -1,4 +1,4 @@ -@namespace Bit.BlazorUI +@namespace Bit.BlazorUI @typeparam TItem
  • @@ -13,7 +13,8 @@ var text = Nav.GetText(Item); var childItems = Nav.GetChildItems(Item); var description = Nav.GetDescription(Item); - var iconName = Nav.GetIconName(Item); + var chevronIcon = BitIconInfo.From(Nav.ChevronDownIcon, Nav.ChevronDownIconName ?? $"ChevronRight {(isExpanded ? "bit-nav-exp" : "bit-ico-r90")}"); + var icon = Nav.GetIcon(Item); var url = Nav.GetUrl(Item); var title = Nav.GetTitle(Item); var target = Nav.GetTarget(Item); @@ -66,7 +67,7 @@
    @if (Nav.NoCollapse is false) { -