src/components/navbar-2/navbar-architecture.md# Navbar2 Architecture## OverviewNavbar2 is a modular component system organized in `/src/components/navbar-2/`. It shares the same architecture as the main Navbar but with its own configuration for different navigation layouts.## File Structure```src/components/navbar-2/├── index.tsx # Main navbar component (Navbar2)├── types.ts # TypeScript interfaces├── config.ts # Navigation data (links, social, homeLink)├── desktop-nav.tsx # Desktop navigation with dropdowns├── mobile-nav.tsx # Mobile navigation menu content├── mobile-nav-button.tsx # Mobile hamburger button with Dialog sidebar├── search-button.tsx # Search functionality├── social-media-nav.tsx # Social media icons└── sticky-navbar.tsx # Sticky navbar on scroll```## Component Breakdown### `index.tsx`- **Purpose**: Main entry point for the navbar- **Export**: `Navbar2`- **Responsibilities**:- Tracks scroll position via `useOffsetTop` hook- Manages scroll state for sticky navbar behavior- Renders both desktop and mobile navigation- Renders sticky navbar that appears on scroll- **Props**:- `className?: string` - Additional CSS classes- `dark?: boolean` - When true, renders white text/icons for dark backgrounds (default: false)- `hero?: boolean` - When true, positions navbar absolutely over content (default: false)### `types.ts`- **Purpose**: Centralized TypeScript type definitions- **Key Types**:- `NavbarProps`: Main navbar props (className, dark, hero)- `NavLink`: Navigation link structure with optional dropdowns- `DropdownItem`: Dropdown menu item structure- `SocialLink`: Social media link structure- `PopoverRenderProps`: Headless UI popover render props### `config.ts`- **Purpose**: Centralized configuration data for Navbar2- **Contents**:- `homeLink`: Logo link destination- `links`: Array of main navigation links with optional dropdowns- `socialLinks`: Array of social media links- **Benefits**: Easy to add/remove/modify navigation items without touching component logic- **Note**: This config is independent from the main Navbar config### `desktop-nav.tsx`- **Purpose**: Desktop navigation with dropdowns- **Features**:- Popover-based dropdown menus using Headless UI- `PopoverBackdrop` for click-outside-to-close behavior- `CloseButton` wrapping Links for close-on-navigation- Multi-column dropdown support (1, 2, or 3 columns)- Dropdown positioning (left, center, right)- Icon support for dropdown items- Dark mode support for white text on dark backgrounds- **Props**: `isScrolling?: boolean`, `forceCloseOnHide?: boolean`, `dark?: boolean`### `mobile-nav.tsx`- **Purpose**: Mobile navigation menu content- **Features**:- Expandable accordion sections using Headless UI Disclosure- Framer Motion animations- Integrated search button- Social media links at bottom- Closes menu when clicking navigation links- **Props**: `close: () => void` - Function to close the mobile menu### `mobile-nav-button.tsx`- **Purpose**: Mobile hamburger button with sliding sidebar- **Features**:- Opens Dialog sidebar from the right- Animated backdrop overlay- Passes `closeModal` to MobileNav for close-on-click behavior- Mobile/tablet only (hidden on desktop)- **Props**: `dark?: boolean`### `search-button.tsx`- **Purpose**: Search toggle with keyboard shortcuts- **Features**:- Keyboard shortcut listener (Cmd/Ctrl+K)- Opens search modal- Dark mode support for white icon- **Props**: `enableShortcut?: boolean`, `dark?: boolean`### `social-media-nav.tsx`- **Purpose**: Desktop social media icons- **Features**:- Renders social links from config- Desktop-only display (hidden on mobile)- Uses Iconify icons- Dark mode support for white icons- **Props**: `dark?: boolean`### `sticky-navbar.tsx`- **Purpose**: Sticky navbar that appears on scroll- **Features**:- Framer Motion slide animation- Slides in when scrolling up, slides out when scrolling down- Uses same DesktopNav component with `forceCloseOnHide` for proper dropdown behavior- Includes desktop nav, search, social links, and mobile button- **Props**: `isScrolling?: boolean`, `scrollingDirection?: string`## Dark ModeThe navbar supports a `dark` prop for use on dark backgrounds:\`\`\`tsx <Navbar2 dark={true} /> \`\`\`When `dark={true}`:- Logo switches to white version- Desktop nav links use white text with `hover:bg-white/10`- Social media icons use white color- Search icon uses white color## Hero ModeThe navbar supports a `hero` prop for overlaying content:\`\`\`tsx <Navbar2 hero={true} /> \`\`\`When `hero={true}`:- Navbar is positioned absolutely over the content below- Typically used with dark backgrounds where `dark={true}` is also set## Dropdown Close BehaviorDesktop dropdowns close when:1. **Clicking the backdrop** - `PopoverBackdrop` covers the screen behind the dropdown2. **Clicking a menu item** - `CloseButton as={Link}` closes the popover and navigates3. **Pressing Escape** - Built-in Headless UI behaviorMobile menu closes when:1. **Clicking the backdrop** - Dialog backdrop click2. **Clicking a navigation link** - `onClick={close}` on all links3. **Pressing Escape** - Built-in Headless UI behavior## Data FlowAll navigation data is centralized in `config.ts`. Components import directly from this file:\`\`\` config.ts ├── homeLink → index.tsx, sticky-navbar.tsx ├── links → desktop-nav.tsx, mobile-nav.tsx └── socialLinks → social-media-nav.tsx, mobile-nav.tsx \`\`\`## Benefits of This Architecture1. **Modularity**: Each component has a single responsibility2. **Maintainability**: Easy to locate and modify specific features3. **Centralized Config**: All navigation data in one place4. **Type Safety**: Centralized types prevent inconsistencies5. **Reusability**: Components can be reused in different contexts6. **Readability**: Clear separation of concerns## Making Changes### Adding a new navigation linkEdit `config.ts` and add to the `links` array### Adding a dropdown to a linkAdd a `dropdown` property with `items`, optional `columns` (1-3), and optional `position` ('left', 'center', 'right')### Modifying social linksEdit `config.ts` and update the `socialLinks` array### Changing the logo link destinationEdit `homeLink` in `config.ts`### Using dark modePass `dark={true}` to the Navbar2 component for dark backgrounds### Using hero modePass `hero={true}` to position navbar absolutely over content### Updating mobile menu behaviorEdit `mobile-nav.tsx` for the menu content or `mobile-nav-button.tsx` for the sidebar container