Overview
The navigation system provides a responsive, multi-level menu with icons, dropdown submenus, and mobile optimization. It integrates with Material Design Icons through astro-icon.NavBar
The main navigation component with responsive design, dropdown menus, and integrated WhatsApp call-to-action.Props
No props required - the component reads navigation data from@/data/menu.json.
Features
Dynamic Menu
Menu structure loaded from JSON configuration file for easy management.
Dropdown Submenus
Multi-level navigation with animated dropdowns and toggle buttons.
Icon Integration
Material Design Icons for visual navigation enhancement.
Mobile Responsive
Hamburger menu with slide-out navigation for mobile devices.
WhatsApp Integration
Direct WhatsApp contact buttons for desktop and mobile.
Highlight Markers
Visual indicators for featured menu items (e.g., special offers).
Usage
Menu Configuration
The navigation menu is configured throughsrc/data/menu.json:
Menu Structure
Menu Schema
Unique identifier for the menu item. Use format like “1”, “2”, or “1-1” for submenu items.
Display text for the menu item. Typically uppercase for consistency.
URL path or external link for the menu item.
Material Design Icon identifier (e.g., “mdi:view-grid”). Used for visual enhancement.
Whether to apply highlight styling. Used for promotional or important items.
Array of submenu items. Each submenu item should have
id, titulo, and link properties.Complete Example
Component Structure
Header Layout
Menu Item Template
The component renders menu items dynamically:Styling
The NavBar uses an external CSS file for styling:The actual styling rules are maintained in
src/styles/NavBar.css for better organization and reusability.CSS Classes
Layout Classes
Layout Classes
.logo- Logo container with responsive sizing.navbar- Main navigation container.menu-item- Individual menu item wrapper.menu-link- Clickable menu link
Icon Classes
Icon Classes
.menu-icon- Icon displayed before menu text.dropdown-icon- Chevron icon for dropdown indicators.submenu-toggle- Mobile submenu toggle button
State Classes
State Classes
.highlight-marker- Highlighted menu item styling.hidden- Hidden submenu (toggled via JavaScript).visible- Visible submenu after toggle
Responsive Classes
Responsive Classes
.soloMovil- Visible only on mobile devices.soloPC- Visible only on desktop devices
JavaScript Functionality
The component includes client-side JavaScript for interactive behavior:Submenu Toggle
Mobile Toggle Button
Click Outside to Close
WhatsApp Integration
The NavBar includes two WhatsApp buttons with pre-filled messages:Mobile Button
Desktop Button
Icon Usage
The component uses astro-icon for Material Design Icons:Available Icons
mdi:view-grid
Grid view (used for Services)
mdi:tag
Tag/label (used for Offers)
mdi:account-group
User group (used for About)
mdi:text-box-outline
Document (used for Blog)
mdi:calculator
Calculator (used for Quote)
mdi:whatsapp
WhatsApp logo
mdi:menu
Hamburger menu
mdi:chevron-down
Dropdown indicator
Adding Custom Icons
Customization Examples
Adding a New Menu Item
Creating a Mega Menu
For complex submenus with multiple columns:For mega menus with more than 6 items, consider custom CSS to display in multiple columns.
Accessibility
Semantic HTML
Semantic HTML
- Uses
<header>for page header <nav>for navigation container- Proper
<ul>and<li>structure for menus
ARIA Labels
ARIA Labels
aria-label="Toggle submenu"on mobile toggle buttonsaria-label="Contactar por WhatsApp"on mobile WhatsApp button
Keyboard Navigation
Keyboard Navigation
Link Attributes
Link Attributes
rel="noopener noreferrer"on external linkstarget="_blank"for external navigation- Descriptive link text
Best Practices
Keep Menu Simple
Limit top-level items to 5-7 for optimal usability. Use submenus for additional pages.
Consistent Naming
Use consistent capitalization and terminology across menu items.
Icon Consistency
Choose icons that clearly represent their menu item and maintain a consistent style.
Test Mobile
Always test navigation on actual mobile devices, not just browser responsive mode.
Related Components
- Footer - Site footer with navigation links
- Breadcrumbs - Breadcrumb navigation for page hierarchy
- HeaderLink - Individual navigation link component
Source Code References
- NavBar component:
src/components/NavBar.astro:1-128 - Menu data:
src/data/menu.json - Styles:
src/styles/NavBar.css