Skip to content

feat: make flowbite-navbar-* usable as directive #110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

MGREMY
Copy link
Collaborator

@MGREMY MGREMY commented Jan 22, 2025

PR Checklist

Please check if your PR fulfills the following requirements:

  • Docs have been added/updated (for bug fixes/features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no API changes)
  • Build related changes
  • CI-related changes
  • Documentation content changes
  • Other... Please describe:

Issue Number

Issue Number: N/A

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

  • Documentation

    • Added comprehensive documentation for Navbar Component
    • Included examples for default, brand, dropdown, and responsive navbar configurations
  • New Features

    • Enhanced Navbar Component with multiple usage options
    • Added support for various HTML element selectors (nav, button, div, span, etc.)
  • Improvements

    • Expanded component flexibility across different template structures
    • Updated demo identifiers and file paths for better organization

Copy link
Contributor

coderabbitai bot commented Jan 22, 2025

Walkthrough

This pull request introduces comprehensive documentation and implementation for the Navbar Component in the Flowbite Angular library. The changes include creating a new documentation file, adding directive and component examples, and updating the component selectors to provide more flexibility in usage. The documentation covers various navbar configurations such as default, brand, dropdown, and responsive designs, with detailed HTML and TypeScript code snippets.

Changes

File Change Summary
apps/docs/docs/components/navbar/component.md New documentation file for Navbar Component
apps/docs/docs/components/navbar/index.md Updated metadata, demo identifiers, and file paths
apps/docs/docs/components/navbar/ng-doc.page.ts Updated imports and component aliases
libs/flowbite-angular/navbar/* Updated component selectors for more flexible usage

Sequence Diagram

sequenceDiagram
    participant User
    participant NavbarComponent
    participant NavbarContent
    participant NavbarItem
    participant NavbarBrand
    participant NavbarToggle

    User->>NavbarComponent: Initialize Navbar
    NavbarComponent->>NavbarBrand: Add Brand
    NavbarComponent->>NavbarContent: Add Navigation Items
    NavbarContent->>NavbarItem: Create Menu Items
    User->>NavbarToggle: Toggle Mobile Menu
    NavbarToggle->>NavbarContent: Show/Hide Content
Loading

Possibly related PRs

Poem

🐰 A Navbar's Tale of Delight

With directives dancing left and right,
Responsive, brand, and dropdown bright,
Flowbite's navbar takes its flight,
Flexible selectors, a coder's might!
Documentation shining clear and light 🌟

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

vercel bot commented Jan 22, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
flowbite-angular ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 22, 2025 2:45pm

@MGREMY
Copy link
Collaborator Author

MGREMY commented Jan 22, 2025

@coderabbitai review

Copy link
Contributor

coderabbitai bot commented Jan 22, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (3)
apps/docs/docs/components/navbar/ng-doc.page.ts (1)

1-9: Consider organizing imports for better readability.

Consider grouping related imports together and adding separators for better organization:

 import ComponentCategory from '../ng-doc.category';
+
 // Component versions
 import { FlowbiteBrandComponent as c_brand } from './component/_brand.component';
 import { FlowbiteDefaultComponent as c_default } from './component/_default.component';
 import { FlowbiteDropdownComponent as c_dropdown } from './component/_dropdown.component';
 import { FlowbiteResponsiveComponent as c_responsive } from './component/_responsive.component';
+
 // Directive versions
 import { FlowbiteBrandComponent as d_brand } from './directive/_brand.component';
 import { FlowbiteDefaultComponent as d_default } from './directive/_default.component';
 import { FlowbiteDropdownComponent as d_dropdown } from './directive/_dropdown.component';
 import { FlowbiteResponsiveComponent as d_responsive } from './directive/_responsive.component';
apps/docs/docs/components/navbar/directive/_dropdown.component.html (1)

1-4: Reconsider hardcoding isOpen to true.

Setting [isOpen]="true" permanently keeps the navbar open, which might not demonstrate the responsive behavior effectively. Consider removing this binding to show the default behavior.

 <nav
   flowbite-navbar
-  [isOpen]="true">
+  >
apps/docs/docs/components/navbar/component.md (1)

55-56: Fix grammar in the mobile device description.

Add missing commas for better readability.

-On mobile device the navigation bar will be collapsed and you will be able to use the hamburger menu
+On mobile devices, the navigation bar will be collapsed, and you will be able to use the hamburger menu
🧰 Tools
🪛 LanguageTool

[uncategorized] ~55-~55: Possible missing comma found.
Context: ..." ``` ## Responsive navbar On mobile device the navigation bar will be collapsed an...

(AI_HYDRA_LEO_MISSING_COMMA)


[uncategorized] ~55-~55: Use a comma before ‘and’ if it connects two independent clauses (unless they are closely connected and short).
Context: ...ice the navigation bar will be collapsed and you will be able to use the hamburger m...

(COMMA_COMPOUND_SENTENCE)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c6ebc43 and 98f1b7c.

📒 Files selected for processing (17)
  • apps/docs/docs/components/navbar/component.md (1 hunks)
  • apps/docs/docs/components/navbar/directive/_brand.component.html (1 hunks)
  • apps/docs/docs/components/navbar/directive/_brand.component.ts (1 hunks)
  • apps/docs/docs/components/navbar/directive/_default.component.html (1 hunks)
  • apps/docs/docs/components/navbar/directive/_default.component.ts (1 hunks)
  • apps/docs/docs/components/navbar/directive/_dropdown.component.html (1 hunks)
  • apps/docs/docs/components/navbar/directive/_dropdown.component.ts (1 hunks)
  • apps/docs/docs/components/navbar/directive/_responsive.component.html (1 hunks)
  • apps/docs/docs/components/navbar/directive/_responsive.component.ts (1 hunks)
  • apps/docs/docs/components/navbar/index.md (4 hunks)
  • apps/docs/docs/components/navbar/ng-doc.page.ts (2 hunks)
  • libs/flowbite-angular/navbar/navbar-brand.component.ts (1 hunks)
  • libs/flowbite-angular/navbar/navbar-content.component.ts (1 hunks)
  • libs/flowbite-angular/navbar/navbar-icon-button.component.ts (1 hunks)
  • libs/flowbite-angular/navbar/navbar-item.component.ts (1 hunks)
  • libs/flowbite-angular/navbar/navbar-toggle.component.ts (1 hunks)
  • libs/flowbite-angular/navbar/navbar.component.ts (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • apps/docs/docs/components/navbar/directive/_brand.component.html
  • apps/docs/docs/components/navbar/directive/_default.component.html
🧰 Additional context used
📓 Learnings (2)
libs/flowbite-angular/navbar/navbar.component.ts (1)
Learnt from: MGREMY
PR: themesberg/flowbite-angular#88
File: libs/flowbite-angular/navbar/navbar.component.ts:99-99
Timestamp: 2024-12-11T09:25:50.819Z
Learning: In `libs/flowbite-angular/navbar/navbar.component.ts`, the `NavbarContentComponent` was already required because the `verify` function threw an error if `navbarContentChild` was undefined or null. Therefore, changing `contentChild` to `contentChild.required` does not introduce a breaking change.
libs/flowbite-angular/navbar/navbar-content.component.ts (1)
Learnt from: MGREMY
PR: themesberg/flowbite-angular#88
File: libs/flowbite-angular/navbar/navbar.component.ts:99-99
Timestamp: 2024-12-11T09:25:50.819Z
Learning: In `libs/flowbite-angular/navbar/navbar.component.ts`, the `NavbarContentComponent` was already required because the `verify` function threw an error if `navbarContentChild` was undefined or null. Therefore, changing `contentChild` to `contentChild.required` does not introduce a breaking change.
🪛 LanguageTool
apps/docs/docs/components/navbar/component.md

[uncategorized] ~55-~55: Possible missing comma found.
Context: ..." ``` ## Responsive navbar On mobile device the navigation bar will be collapsed an...

(AI_HYDRA_LEO_MISSING_COMMA)


[uncategorized] ~55-~55: Use a comma before ‘and’ if it connects two independent clauses (unless they are closely connected and short).
Context: ...ice the navigation bar will be collapsed and you will be able to use the hamburger m...

(COMMA_COMPOUND_SENTENCE)

🔇 Additional comments (14)
libs/flowbite-angular/navbar/navbar-item.component.ts (1)

37-40: Great enhancement to the component's flexibility!

The updated selector allows the component to be used both as a standalone element (<flowbite-navbar-item>) and as an attribute on <li> elements (<li flowbite-navbar-item>). This change:

  • Improves flexibility in DOM structure
  • Maintains backward compatibility
  • Aligns with common navbar HTML patterns where items are typically <li> elements
apps/docs/docs/components/navbar/directive/_default.component.ts (1)

1-14: Clean implementation following Angular best practices!

The component is well-structured using the standalone component pattern with explicit imports, which aligns with modern Angular practices.

apps/docs/docs/components/navbar/directive/_responsive.component.ts (1)

1-22: Well-structured responsive navbar demo component!

The component correctly imports all necessary navbar components including the toggle component for responsive behavior.

apps/docs/docs/components/navbar/directive/_dropdown.component.ts (1)

1-23: Clean implementation with well-organized imports!

The component correctly combines both navbar and dropdown functionality. The imports are nicely organized by feature, making the code more maintainable.

apps/docs/docs/components/navbar/ng-doc.page.ts (1)

20-20: Verify the existence of referenced markdown files and demo components.

The configuration references multiple files. Let's verify their existence:

Also applies to: 24-31

✅ Verification successful

All referenced files exist and are properly placed

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the existence of referenced markdown files and demo components

# Check markdown files
echo "Checking markdown files..."
for md in "index.md" "component.md"; do
  if [ -f "apps/docs/docs/components/navbar/$md" ]; then
    echo "$md exists"
  else
    echo "$md not found"
  fi
done

# Check component files
echo -e "\nChecking component files..."
for type in "component" "directive"; do
  for name in "brand" "default" "dropdown" "responsive"; do
    if [ -f "apps/docs/docs/components/navbar/$type/_$name.component.ts" ]; then
      echo "$type/_$name.component.ts exists"
    else
      echo "$type/_$name.component.ts not found"
    fi
  done
done

Length of output: 2309

libs/flowbite-angular/navbar/navbar-brand.component.ts (1)

34-40: LGTM! Enhanced selector flexibility.

The updated selector now supports both element and attribute syntax, allowing the navbar brand to be used with semantic HTML elements (span, div, a, button). This change improves component flexibility while maintaining backward compatibility.

libs/flowbite-angular/navbar/navbar-icon-button.component.ts (1)

36-40: LGTM! Appropriate selector restrictions.

The updated selector properly restricts usage to interactive elements (button, a) while maintaining the original element syntax. This ensures semantic HTML usage for icon buttons.

libs/flowbite-angular/navbar/navbar-content.component.ts (2)

37-40: LGTM! Enhanced selector flexibility.

The updated selector now supports both element and attribute syntax while appropriately limiting to div elements for content containers.


42-44: Verify the impact of changing div to ul.

The template structure has been changed from a div to a ul element, which improves semantic HTML but might affect existing styles or child components expecting a div parent.

Run this script to check for potential styling issues:

✅ Verification successful

The change from div to ul is semantically correct and safe

The change aligns with the existing usage patterns where:

  • The directive version already uses <li> elements
  • The component consistently contains navigation items that semantically belong in a list
  • No styling conflicts were found that depend on the div structure

This change improves the semantic HTML structure without breaking existing functionality.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for CSS selectors targeting the navbar content div
# and components that might be affected by the parent element change

# Search for CSS selectors targeting navbar-content
rg -t css "flowbite-navbar-content|navbar-content" 

# Search for components using NavbarContentComponent
ast-grep --pattern $'@Component({
  $$$
  template: `$$$<div$$$>$$$</div>$$$`
  $$$
})\nexport class $_Component {
  $$$
  navbarContent$_: NavbarContentComponent;
  $$$
}'

Length of output: 225


Script:

#!/bin/bash
# Search for navbar-related styles in CSS/SCSS files
rg -t scss -t css "navbar" -A 2 -B 2

# Find usage of NavbarContentComponent in templates
rg -g "*.{html,ts}" "flowbite-navbar-content|<fb-navbar-content"

# Check parent component structure
ast-grep --pattern $'@Component({
  selector: $selector,
  template: $_
})
export class NavbarComponent'

Length of output: 1715


Script:

#!/bin/bash
# Check content structure in example usages
rg -g "*.{html,ts}" -A 5 -B 5 "<(flowbite-navbar-content|div flowbite-navbar-content)"

# Check component's styling and encapsulation
ast-grep --pattern $'@Component({
  $$$
  selector: "flowbite-navbar-content",
  $$$
  styles: [$_]
  $$$
})'

Length of output: 7990

libs/flowbite-angular/navbar/navbar-toggle.component.ts (1)

37-40: LGTM! Improved accessibility support.

The updated selector now supports button elements while maintaining the original syntax. Using the button element improves accessibility by providing proper semantic meaning for the toggle action.

libs/flowbite-angular/navbar/navbar.component.ts (1)

78-81: LGTM! Selector enhancement improves component flexibility.

The updated selector allows the navbar to be used both as a standalone element (<flowbite-navbar>) and as an attribute directive (<nav flowbite-navbar>), which aligns with Angular best practices and improves component flexibility.

apps/docs/docs/components/navbar/directive/_brand.component.ts (1)

1-15: LGTM! Well-structured demo component.

The component follows Angular best practices with proper imports and standalone component setup.

apps/docs/docs/components/navbar/index.md (1)

2-3: LGTM! Documentation updates align with directive implementation.

The changes consistently reflect the new directive-based approach:

  • Updated metadata to indicate directive documentation
  • Organized examples under the directive subdirectory
  • Updated demo identifiers with the 'd_' prefix

Also applies to: 8-8, 10-10, 14-14, 23-23, 25-25, 29-29, 38-38, 40-40, 44-44, 53-53, 55-55, 59-59

apps/docs/docs/components/navbar/component.md (1)

1-10: LGTM! Well-structured component documentation with clear deprecation notice.

The new file maintains documentation for the component-based approach while clearly indicating its deprecated status.

@MGREMY MGREMY merged commit 5fd4a3b into themesberg:feature-make-component-available-as-directive Jan 22, 2025
4 of 5 checks passed
@MGREMY MGREMY deleted the navbar_as_directive branch January 22, 2025 15:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant