Get Back
October 17, 2024
Mohamed Rafik Portfolio Navbar
tricks

i thought that it will be a generous act from me to just send some parts of my portfolio/blog components available here. and today we going throughout a very important piece which is Navigation Bar

Imports

  • useState from React: This hook allows managing component state variables like show, Hover, etc.
  • Libraries
    • framer-motion: Used for animations (entry, exit, hover).
    • lucide-react: Provides icons like ArrowRight, X, etc.
    • next/link: Enables creating navigation links within Next.js.
    • react-icons/tb: Imports icons like TbMenu, TbMessageDots from React Icons.
  • Custom components
    • Button: Likely a custom button component for styling and functionality.
    • ModeToggle: Presumably a component for handling a dark/light mode toggle.
  • supabase (commented out): Appears to be an unused import for a database connection.

Component Structure:

  • Navigation: The main functional component responsible for rendering the navigation bar.
    • State Variables:
      • show: Controls the visibility of the navigation menu (boolean).
      • Hover: Tracks the currently hovered navigation item (string).
      • showMessage: Controls the visibility of the contact form (boolean).
      • Various state variables for handling the contact form (name, email, message, error, loading, succ).
    • JSX Structure:
      1. Top Menu:
        • Brand logo (Link component) with a click handler to reset show.
        • Menu icons (TbMenu, TbMessageDots) to toggle the navigation menu and contact form, respectively.
        • ModeToggle component (presumably).
      2. Navigation Menu (Conditional):
        • Animated with motion.div for entry/exit effects.
        • Renders only if show is true.
        • Contains the navigation items:
          • Loops through navItems array (data likely imported elsewhere).
          • Each item is a Link component with hover effects using motion.div and conditional classes.
          • Optionally displays social media links from socials array.
      3. Contact Form (Conditional):
        • Animated with motion.div for entry/exit effects.
        • Renders only if showMessage is true.
        • Includes input fields for name, email, and message.
        • Displays error/success messages based on form validation and submission (commented out supabase integration).
        • Submit button (Button component) triggers the form submission logic (commented out).
      4. Click Overlay (Conditional):
        • Animated motion.div displayed when either menu or form is visible.
        • Provides a click area to close both menus.

Key Functionalities:

  • Clicking the menu icon (TbMenu) toggles the visibility of the navigation menu (show).
  • Clicking the message icon (TbMessageDots) toggles the visibility of the contact form (showMessage).
  • Hovering over navigation items highlights them with an opacity change.
  • Clicking anywhere outside the menus closes them (handled by the click overlay).

Additional Notes:

  • The code utilizes Framer Motion for various animations (menu entry/exit, hover effects).
  • Styling is likely defined in separate CSS files (not included).

This breakdown provides a general understanding of the component's functionality. You can customize it further by modifying the data structures (e.g., navItems, socials), styling, and potentially adding functionalities like the commented-out contact form submission logic.

Check Code In Github Gist ↗
Made With Kisses By Mohamed Rafik