Blox/
Horizontal Navigation
A responsive top navigation bar with dropdown menus, mobile hamburger menu, and call-to-action buttons. Ideal for marketing sites and web applications.
DropdownsMobile MenuResponsiveCTA Buttons
Installation
Terminal
TSXReactTailwind
npx @uiblox/cli add horizontal-navPreview
Source Code
Copy this code into your project. The navigation includes desktop dropdowns and a responsive mobile menu.
horizontal-nav.tsx
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172"use client"; import { useState } from "react"; import Link from "next/link"; import { cn } from "@/lib/utils"; interface NavItem { label: string; href?: string; children?: { label: string; href: string; description?: string }[]; } const navItems: NavItem[] = [ { label: "Home", href: "/" }, { label: "Products", children: [ { label: "Analytics", href: "/products/analytics", description: "Measure and optimize" }, { label: "Automation", href: "/products/automation", description: "Streamline workflows" }, { label: "Integration", href: "/products/integration", description: "Connect your tools" }, ], }, { label: "Solutions", children: [ { label: "Enterprise", href: "/solutions/enterprise", description: "For large teams" }, { label: "Startups", href: "/solutions/startups", description: "Scale fast" }, { label: "Developers", href: "/solutions/developers", description: "Build with ease" }, ], }, { label: "Pricing", href: "/pricing" }, { label: "Docs", href: "/docs" }, ]; export function HorizontalNav() { const [mobileOpen, setMobileOpen] = useState(false); const [activeDropdown, setActiveDropdown] = useState<string | null>(null); return ( <header className="bg-white dark:bg-slate-900 border-b border-slate-200 dark:border-slate-800"> <nav className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8"> <div className="flex items-center justify-between h-16"> {/* Logo */} <Link href="/" className="flex items-center gap-2"> <div className="w-8 h-8 rounded-lg bg-gradient-to-br from-purple-500 to-indigo-600 flex items-center justify-center text-white font-bold"> B </div> <span className="text-xl font-bold text-slate-900 dark:text-white">Brand</span> </Link> {/* Desktop Navigation */} <div className="hidden md:flex items-center gap-1"> {navItems.map((item) => ( <div key={item.label} className="relative" onMouseEnter={() => item.children && setActiveDropdown(item.label)} onMouseLeave={() => setActiveDropdown(null)} > {item.href ? ( <Link href={item.href} className="px-4 py-2 text-sm font-medium text-slate-600 dark:text-slate-300 hover:text-slate-900 dark:hover:text-white rounded-lg hover:bg-slate-100 dark:hover:bg-slate-800 transition-colors" > {item.label} </Link> ) : ( <button className="flex items-center gap-1 px-4 py-2 text-sm font-medium text-slate-600 dark:text-slate-300 hover:text-slate-900 dark:hover:text-white rounded-lg hover:bg-slate-100 dark:hover:bg-slate-800 transition-colors"> {item.label} <ChevronDownIcon className="w-4 h-4" /> </button> )} {/* Dropdown */} {item.children && activeDropdown === item.label && ( <div className="absolute top-full left-0 mt-1 w-64 bg-white dark:bg-slate-900 rounded-xl shadow-lg border border-slate-200 dark:border-slate-700 py-2 z-50"> {item.children.map((child) => ( <Link key={child.href} href={child.href} className="block px-4 py-3 hover:bg-slate-50 dark:hover:bg-slate-800 transition-colors" > <span className="block text-sm font-medium text-slate-900 dark:text-white"> {child.label} </span> {child.description && ( <span className="block text-xs text-slate-500 dark:text-slate-400 mt-0.5"> {child.description} </span> )} </Link> ))} </div> )} </div> ))} </div> {/* Right Section */} <div className="hidden md:flex items-center gap-3"> <Link href="/login" className="px-4 py-2 text-sm font-medium text-slate-600 dark:text-slate-300 hover:text-slate-900 dark:hover:text-white"> Sign in </Link> <Link href="/signup" className="px-4 py-2 text-sm font-medium text-white bg-purple-600 hover:bg-purple-700 rounded-lg transition-colors"> Get Started </Link> </div> {/* Mobile Menu Button */} <button onClick={() => setMobileOpen(!mobileOpen)} className="md:hidden p-2 text-slate-600 dark:text-slate-300 hover:bg-slate-100 dark:hover:bg-slate-800 rounded-lg" > {mobileOpen ? <XIcon /> : <MenuIcon />} </button> </div> </nav> {/* Mobile Menu */} {mobileOpen && ( <div className="md:hidden border-t border-slate-200 dark:border-slate-800 bg-white dark:bg-slate-900"> <nav className="px-4 py-4 space-y-1"> {navItems.map((item) => ( <div key={item.label}> {item.href ? ( <Link href={item.href} className="block px-4 py-3 text-slate-700 dark:text-slate-200 hover:bg-slate-100 dark:hover:bg-slate-800 rounded-lg"> {item.label} </Link> ) : ( <div> <span className="block px-4 py-2 text-xs font-semibold text-slate-500 uppercase tracking-wide"> {item.label} </span> {item.children?.map((child) => ( <Link key={child.href} href={child.href} className="block px-4 py-2 pl-8 text-slate-600 dark:text-slate-300 hover:bg-slate-100 dark:hover:bg-slate-800 rounded-lg"> {child.label} </Link> ))} </div> )} </div> ))} </nav> </div> )} </header> ); } function ChevronDownIcon({ className }: { className?: string }) { return ( <svg className={className} fill="none" viewBox="0 0 24 24" stroke="currentColor"> <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M19 9l-7 7-7-7" /> </svg> ); } function MenuIcon() { return ( <svg className="w-6 h-6" fill="none" viewBox="0 0 24 24" stroke="currentColor"> <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M4 6h16M4 12h16M4 18h16" /> </svg> ); } function XIcon() { return ( <svg className="w-6 h-6" fill="none" viewBox="0 0 24 24" stroke="currentColor"> <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M6 18L18 6M6 6l12 12" /> </svg> ); }