Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

ArgoZhang
Copy link
Member

@ArgoZhang ArgoZhang commented Aug 11, 2025

Link issues

fixes #6585

Summary By Copilot

Regression?

  • Yes
  • No

Risk

  • High
  • Medium
  • Low

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • Merge the latest code from the main branch

Summary by Sourcery

Introduce a full-featured Navbar component suite with responsive layout, subcomponents, styling, documentation, and tests

New Features:

  • Add Navbar component with responsive sizing and background options
  • Add NavbarBrand, NavbarToggleButton, NavbarCollapse, NavbarGroup, NavbarItem, NavbarLink, NavbarDropdown, NavbarDropdownItem, and NavbarDropdownDivider subcomponents
  • Create SCSS styling and import for Navbar
  • Add Navbars sample page with usage demonstrations

Enhancements:

  • Add "Navbar" entry to demo menu
  • Adjust dropdown item icon spacing and rename .navbar selector in site.css
  • Refine default Color settings for ButtonBase and Dropdown components

Documentation:

  • Include Navbars sample in documentation

Tests:

  • Add unit tests covering Navbar rendering and NavbarLink interactions

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @ArgoZhang - I've reviewed your changes - here's some feedback:

  • In Navbars.razor.cs sample code, initialize _dropdownItems using new List<SelectedItem>() (or new()) instead of the invalid [] literal.
  • You renamed the site CSS selector from .navbar to .navbar-header; make sure the Navbar component’s markup and classes align with this change so your styles still apply.
  • The media‐query blocks in Navbar.razor.scss are almost identical—consider using a mixin or loop to DRY up the repetitive code.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In Navbars.razor.cs sample code, initialize `_dropdownItems` using `new List<SelectedItem>()` (or `new()`) instead of the invalid `[]` literal.
- You renamed the site CSS selector from `.navbar` to `.navbar-header`; make sure the Navbar component’s markup and classes align with this change so your styles still apply.
- The media‐query blocks in Navbar.razor.scss are almost identical—consider using a mixin or loop to DRY up the repetitive code.

## Individual Comments

### Comment 1
<location> `src/BootstrapBlazor/Components/Navbar/NavbarGroup.razor.cs:31` </location>
<code_context>
+    [Parameter]
+    public string? Height { get; set; }
+
+    private string? ClassString => CssBuilder.Default("navbar-nav")
+        .AddClass("navbar-nav-scroll", IsScrolling)
+        .AddClassFromAttributes(AdditionalAttributes)
</code_context>

<issue_to_address>
Consider refactoring the repeated CSS builder logic into a shared base class or helper to centralize and simplify navbar component styling.

Consider extracting the duplicated CSS‐builder logic into a shared base class or helper. This both DRYs up your Navbar* components and avoids pulling in the same `AdditionalAttributes` twice (which can collide). For example:

1) Shared abstract base:

```csharp
// NavbarBase.cs
public abstract class NavbarBase : ComponentBase
{
    [Parameter] public bool    IsScrolling          { get; set; }
    [Parameter] public string? Height               { get; set; } = "200px";
    [Parameter(CaptureUnmatchedValues = true)]
    public IDictionary<string, object>? AdditionalAttributes { get; set; }

    protected string BuildNavClass(string defaultClass) => CssBuilder
        .Default(defaultClass)
        .AddClass("navbar-nav-scroll", IsScrolling)
        .AddClassFromAttributes(AdditionalAttributes)
        .Build();

    protected string BuildNavStyle() => CssBuilder
        .Default()
        .AddStyle("--bs-scroll-height", Height, IsScrolling)
        .AddStyleFromAttributes(AdditionalAttributes)
        .Build();
}
```

```csharp
// NavbarGroup.razor.cs
public partial class NavbarGroup : NavbarBase
{
    private string? ClassString => BuildNavClass("navbar-nav");
    private string? StyleString => BuildNavStyle();

    // … other parameters / logic …
}
```

2) Or as extension methods:

```csharp
public static class NavbarCssExtensions
{
    public static CssBuilder AddNavbarAttributes(this CssBuilder builder, bool scrolling, IDictionary<string, object>? attrs) =>
        builder.AddClass("navbar-nav-scroll", scrolling)
               .AddClassFromAttributes(attrs);

    public static CssBuilder AddNavbarAttributes(this CssBuilder builder, string? height, bool scrolling, IDictionary<string, object>? attrs) =>
        builder.AddStyle("--bs-scroll-height", height, scrolling)
               .AddStyleFromAttributes(attrs);
}
```

```csharp
// usage in NavbarGroup.razor.cs
private string? ClassString =>
    CssBuilder.Default("navbar-nav")
              .AddNavbarAttributes(IsScrolling, AdditionalAttributes)
              .Build();

private string? StyleString =>
    CssBuilder.Default()
              .AddNavbarAttributes(Height, IsScrolling, AdditionalAttributes)
              .Build();
```

Either approach removes the nearly‐identical pattern from every navbar subcomponent and centralizes the `class`/`style` merging logic.
</issue_to_address>

### Comment 2
<location> `src/BootstrapBlazor/Components/Navbar/NavbarItem.razor.cs:19` </location>
<code_context>
+    [Parameter]
+    public RenderFragment? ChildContent { get; set; }
+
+    private string? ClassString => CssBuilder.Default("navbar-item")
+        .AddClassFromAttributes(AdditionalAttributes)
+        .Build();
</code_context>

<issue_to_address>
Consider refactoring shared logic into a base class so each navigation child only overrides its default CSS class.

Consider extracting the common bits into a small base class so each nav-child only needs to override its default css class. For example:

```csharp
// NavItemBase.cs
public abstract class NavItemBase : ComponentBase
{
    [Parameter] public RenderFragment? ChildContent { get; set; }
    [Parameter(CaptureUnmatchedValues = true)]
    public IReadOnlyDictionary<string, object>? AdditionalAttributes { get; set; }

    protected abstract string DefaultCss { get; }
    protected string ClassString => CssBuilder
        .Default(DefaultCss)
        .AddClassFromAttributes(AdditionalAttributes)
        .Build();
}
```

Then your NavbarItem becomes trivial:

```csharp
// NavbarItem.razor.cs
public partial class NavbarItem : NavItemBase
{
    protected override string DefaultCss => "navbar-item";
}
```

If you have other siblings (e.g. `NavLink`, `NavDropdown`), they all just override `DefaultCss` and inherit the same `ChildContent` + `ClassString` logic.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@bb-auto bb-auto bot added the enhancement New feature or request label Aug 11, 2025
@bb-auto bb-auto bot added this to the 9.9.0 milestone Aug 11, 2025
@ArgoZhang ArgoZhang merged commit 8e51e37 into main Aug 11, 2025
4 checks passed
@ArgoZhang ArgoZhang deleted the feat-navbar branch August 11, 2025 00:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat(Navbar): add Navbar component
1 participant