Skip to content

Navbar 2

Floating pill navbar with a CTA and an expanding mobile menu.

02 / 02

Installation

Run this in a project that already uses shadcn/ui. The CLI adds the block, its components and npm dependencies.

pnpm dlx shadcn@latest add https://ui.sumansharma.info.np/r/navbar-2.json
Prefer to iterate with AI?Open in

Usage

The CLI writes the block to components/navbar-2.tsx. Import it anywhere:

Loading...

Source

The CLI writes this component to components/navbar-2.tsx.

'use client'

import { useState } from 'react'
import Link from 'next/link'
import { ArrowRight, Menu, X } from 'lucide-react'
import { Logo } from '@/components/logo'
import { Button } from '@/components/ui/button'
import { cn } from '@/lib/utils'

const links = [
    { label: 'Features', href: '#' },
    { label: 'Customers', href: '#' },
    { label: 'Pricing', href: '#' },
    { label: 'Blog', href: '#' },
]

export default function Navbar() {
    const [open, setOpen] = useState(false)

    return (
        <div className="min-h-[480px] bg-[radial-gradient(60%_50%_at_50%_0%,var(--color-muted),transparent)]">
            <header className="fixed inset-x-0 top-4 z-50 px-4">
                <nav
                    aria-label="Main"
                    className={cn('bg-background/70 mx-auto max-w-3xl border shadow-lg shadow-black/5 backdrop-blur-xl transition-[border-radius] duration-300', open ? 'rounded-2xl' : 'rounded-full')}>
                    <div className="flex h-14 items-center justify-between gap-4 pl-5 pr-2">
                        <Link
                            href="/"
                            aria-label="Home"
                            className="flex items-center gap-2 font-semibold">
                            <Logo className="size-5" />
                            <span>Lyra</span>
                        </Link>

                        <ul className="hidden items-center gap-6 md:flex">
                            {links.map((link) => (
                                <li key={link.label}>
                                    <Link
                                        href={link.href}
                                        className="text-muted-foreground hover:text-foreground text-sm transition-colors">
                                        {link.label}
                                    </Link>
                                </li>
                            ))}
                        </ul>

                        <div className="flex items-center gap-1">
                            <Button
                                asChild
                                size="sm"
                                className="group hidden rounded-full sm:inline-flex">
                                <Link href="#">
                                    Start free
                                    <ArrowRight className="size-3.5 transition-transform group-hover:translate-x-0.5" />
                                </Link>
                            </Button>
                            <Button
                                variant="ghost"
                                size="icon"
                                className="rounded-full md:hidden"
                                aria-expanded={open}
                                aria-controls="pill-menu"
                                aria-label={open ? 'Close menu' : 'Open menu'}
                                onClick={() => setOpen((v) => !v)}>
                                {open ? <X className="size-5" /> : <Menu className="size-5" />}
                            </Button>
                        </div>
                    </div>

                    {open && (
                        <div
                            id="pill-menu"
                            className="border-t px-5 pb-5 pt-2 md:hidden">
                            <ul>
                                {links.map((link) => (
                                    <li key={link.label}>
                                        <Link
                                            href={link.href}
                                            onClick={() => setOpen(false)}
                                            className="block py-2.5 font-medium">
                                            {link.label}
                                        </Link>
                                    </li>
                                ))}
                            </ul>
                            <Button
                                asChild
                                className="mt-3 w-full rounded-full">
                                <Link href="#">Start free</Link>
                            </Button>
                        </div>
                    )}
                </nav>
            </header>
        </div>
    )
}