Navbar Floating
A header that shrinks into a floating glass pill on scroll, with a morphing mobile menu.
components/navbar-floating.tsx
"use client";
import type { ReactNode } from "react";
import { FloatingNav } from "@/components/floating-nav";
import { HoverNav } from "@/components/hover-nav";
import { MorphMenu } from "@/components/morph-menu";
import { MagneticButton } from "@/components/magnetic-button";
import { cn } from "@/lib/utils";
export type NavbarFloatingProps = {
/** Logo or brand name, linked to home. */
brand?: ReactNode;
/** Main links. Shown inline on desktop and in a morphing menu on small screens. */
links?: { label: string; href: string }[];
/** Highlighted link (matches a link's href). */
current?: string;
/** Call to action on the right. */
cta?: { label: string; href: string };
/** Use a scrollable element instead of the window. */
scrollContainer?: React.RefObject<HTMLElement | null>;
className?: string;
};
const DEFAULT_LINKS = [
{ label: "Product", href: "#product" },
{ label: "Pricing", href: "#pricing" },
{ label: "Customers", href: "#customers" },
{ label: "Blog", href: "#blog" },
];
/**
* A site header that sits flat at the top, then shrinks into a floating glass pill on scroll.
* Links get a sliding hover highlight; on small screens they move into a morphing menu.
*/
export function NavbarFloating({
brand = <DefaultBrand />,
links = DEFAULT_LINKS,
current,
cta = { label: "Get started", href: "#" },
scrollContainer,
className,
}: NavbarFloatingProps) {
return (
<FloatingNav scrollContainer={scrollContainer} className={className}>
<a href="/" className="shrink-0 rounded-lg outline-none focus-visible:ring-4 focus-visible:ring-ring/40">
{brand}
</a>
<HoverNav links={links} current={current} className="hidden md:flex" />
<div className="flex items-center gap-2">
<MagneticButton as="a" href={cta.href} className="hidden px-5 py-2.5 sm:inline-flex">
{cta.label}
</MagneticButton>
<MorphMenu links={[...links, cta]} align="right" className="md:hidden" />
</div>
</FloatingNav>
);
}
function DefaultBrand() {
return (
<span className="flex items-center gap-2 text-[15px] font-semibold tracking-[-0.02em]">
<svg viewBox="0 0 24 24" className="size-6 text-primary" fill="currentColor" aria-hidden>
<path d="M2 15c3 0 3-6 6-6s3 6 6 6 3-6 6-6v11H2z" />
</svg>
Lautan
</span>
);
}Installation
Installs the block and every component it uses.
npx shadcn@latest add https://ombakui.com/r/navbar-floating.jsonUsage
Every prop has a default, so it renders as shown. Pass your own copy and links.
import { NavbarFloating } from "@/components/navbar-floating";
export default function Page() {
return <NavbarFloating />;
}Props
| Prop | Type | Default | Description |
|---|---|---|---|
| brand | ReactNode | – | Logo or brand name, linked to home. |
| links | { label: string; href: string }[] | – | Main links. Shown inline on desktop and in a morphing menu on small screens. |
| current | string | – | Highlighted link (matches a link's href). |
| cta | { label: string; href: string } | – | Call to action on the right. |
| scrollContainer | React.RefObject<HTMLElement | null> | – | Use a scrollable element instead of the window. |
| className | string | – |