Navbar 27
NavbarsLogo LeftMenu CenterMenu RightMega MenuMultiple ImagesBackground Image

Code
relume-navbar27.tsx
"use client";
import { useState } from "react";
import { motion } from "motion/react";
import { useMediaQuery } from "@/hooks/use-media-query";
import { Button, type ButtonProps } from "@/components/ui/button";
import { KeyboardArrowDown } from "relume-icons";
type ImageProps = {
url?: string;
src: string;
alt?: string;
};
type SubMenuLink = {
title: string;
url: string;
};
type CategoryGroup = {
title: string;
subLinks: SubMenuLink[];
};
type CollectionProps = {
title: string;
description: string;
button: ButtonProps;
image?: ImageProps;
};
type MegaMenuProps = {
categories?: CategoryGroup[];
image?: ImageProps;
collections?: CollectionProps[];
};
type LinkProps = {
title: string;
url: string;
megaMenu?: MegaMenuProps;
};
type Props = {
logo: ImageProps;
links: LinkProps[];
buttons: ButtonProps[];
};
export type Navbar27Props = React.ComponentPropsWithoutRef<"section"> & Partial<Props>;
export const Navbar27 = (props: Navbar27Props) => {
const { logo, links, buttons } = {
...Navbar27Defaults,
...props,
};
const [isMobileMenuOpen, setIsMobileMenuOpen] = useState(false);
const isMobile = useMediaQuery("(max-width: 991px)");
return (
<section className="relative z-[999] flex w-full items-center justify-between border-b border-scheme-border bg-scheme-background lg:min-h-18 lg:px-[5%]">
<div className="size-full lg:flex lg:items-center lg:justify-between">
<div className="lg:flex">
<div className="flex min-h-16 items-center justify-between px-[5%] md:min-h-18 lg:min-h-full lg:px-0">
<a href={logo.url}>
<img src={logo.src} alt={logo.alt} />
</a>
<button
className="-mr-2 flex size-12 flex-col items-center justify-center lg:hidden"
onClick={() => setIsMobileMenuOpen((prev) => !prev)}
>
<motion.span
className="my-[3px] h-0.5 w-6 bg-neutral-darkest"
animate={isMobileMenuOpen ? ["open", "rotatePhase"] : "closed"}
variants={topLineVariants}
/>
<motion.span
className="my-[3px] h-0.5 w-6 bg-neutral-darkest"
animate={isMobileMenuOpen ? "open" : "closed"}
variants={middleLineVariants}
/>
<motion.span
className="my-[3px] h-0.5 w-6 bg-neutral-darkest"
animate={isMobileMenuOpen ? ["open", "rotatePhase"] : "closed"}
variants={bottomLineVariants}
/>
</button>
</div>
<motion.div
variants={{
open: {
height: "var(--height-open, 100dvh)",
},
close: {
height: "var(--height-closed, 0)",
},
}}
initial="close"
exit="close"
animate={isMobileMenuOpen ? "open" : "close"}
transition={{ duration: 0.4 }}
className="overflow-auto px-[5%] lg:ml-6 lg:flex lg:items-center lg:px-0 lg:[--height-closed:auto] lg:[--height-open:auto]"
>
{links.map((link, index) =>
link.megaMenu ? (
<SubMenu
key={index}
megaMenu={link.megaMenu}
title={link.title}
isMobile={isMobile}
/>
) : (
<a
key={index}
href={link.url}
className="text-md block py-3 first:pt-7 lg:px-4 lg:py-6 lg:text-base first:lg:pt-6"
>
{link.title}
</a>
),
)}
<div className="mt-6 flex w-full flex-col gap-y-4 pb-24 lg:hidden lg:pb-0">
{buttons.map((button, index) => (
<Button key={index} className="w-full" {...button}>
{button.title}
</Button>
))}
</div>
</motion.div>
</div>
<div className="hidden lg:flex lg:gap-4">
{buttons.map((button, index) => (
<Button key={index} {...button}>
{button.title}
</Button>
))}
</div>
</div>
</section>
);
};
const SubMenu = ({
title,
isMobile,
megaMenu,
}: {
title: string;
isMobile: boolean;
megaMenu: MegaMenuProps;
}) => {
const [isDropdownOpen, setIsDropdownOpen] = useState(false);
return (
<div
onMouseEnter={() => !isMobile && setIsDropdownOpen(true)}
onMouseLeave={() => !isMobile && setIsDropdownOpen(false)}
>
<button
className="text-md flex w-full items-center justify-between gap-x-2 py-3 text-center lg:w-auto lg:flex-none lg:justify-start lg:px-4 lg:py-6 lg:text-base"
onClick={() => setIsDropdownOpen((prev) => !prev)}
>
<span>{title}</span>
<motion.span
variants={{
rotated: { rotate: 180 },
initial: { rotate: 0 },
}}
animate={isDropdownOpen ? "rotated" : "initial"}
transition={{ duration: 0.3 }}
>
<KeyboardArrowDown className="text-scheme-text" />
</motion.span>
</button>
<motion.div
variants={{
open: {
visibility: "visible",
opacity: 1,
height: "var(--height-open, auto)",
},
close: {
visibility: "hidden",
opacity: "0",
height: "var(--height-close, 0)",
},
}}
initial="close"
exit="close"
animate={isDropdownOpen ? "open" : "close"}
transition={{ duration: 0.3 }}
className="top-full bottom-auto left-0 w-full max-w-full min-w-full overflow-hidden bg-scheme-background lg:absolute lg:w-[100vw] lg:border-b lg:border-scheme-border lg:px-[5%] lg:[--height-close:auto]"
>
<div className="flex w-full flex-col flex-nowrap gap-6 pt-6 md:gap-12 md:py-8 lg:flex-row lg:gap-20">
<div className="grid w-full auto-cols-fr grid-cols-1 items-start justify-start gap-6 md:grid-cols-2 md:gap-12 lg:max-w-[26rem]">
{megaMenu?.categories?.map((category, index) => (
<div key={index} className="text-left">
<p className="mb-4 font-semibold">{category.title}</p>
<div className="flex flex-col items-start">
{category.subLinks.map((link, linkIndex) => (
<a key={linkIndex} href={link.url} className="block py-2 text-sm">
{link.title}
</a>
))}
</div>
</div>
))}
</div>
<div className="w-full justify-items-stretch lg:max-w-xl">
<div className="grid h-full grid-cols-1 gap-6 md:grid-cols-2">
{megaMenu?.collections?.map((collection, collectionIndex) => (
<div
key={collectionIndex}
className="relative flex h-full flex-col items-stretch justify-between overflow-hidden p-6 sm:p-8"
>
<div className="absolute inset-0 z-0 bg-neutral-darkest/50">
<div className="absolute inset-0 z-10 bg-neutral-darkest/50" />
<img
src={collection.image?.src}
alt={collection.image?.alt}
className="absolute inset-0 size-full object-cover"
/>
</div>
<div className="relative flex flex-1 flex-col justify-between text-white">
<h5 className="mb-5 text-2xl font-bold md:mb-6 md:text-3xl md:leading-[1.3] lg:text-4xl">
{collection.title}
</h5>
<p>{collection.description}</p>
<div className="mt-6 flex flex-wrap items-center gap-4 md:mt-8">
<Button {...collection.button}>{collection.button.title}</Button>
</div>
</div>
</div>
))}
</div>
</div>
</div>
</motion.div>
</div>
);
};
export const Navbar27Defaults: Props = {
logo: {
url: "#",
src: "https://d22po4pjz3o32e.cloudfront.net/logo-image.svg",
alt: "Logo image",
},
links: [
{ title: "Link One", url: "#" },
{ title: "Link Two", url: "#" },
{ title: "Link Three", url: "#" },
{
title: "Link Four",
url: "#",
megaMenu: {
categories: [
{
title: "Product categories",
subLinks: [
{ title: "Category One", url: "#" },
{ title: "Category Two", url: "#" },
{ title: "Category Three", url: "#" },
{ title: "Category Four", url: "#" },
{ title: "Category Five", url: "#" },
],
},
{
title: "Product categories",
subLinks: [
{ title: "Category Six", url: "#" },
{ title: "Category Seven", url: "#" },
{ title: "Category Eight", url: "#" },
{ title: "Category Nine", url: "#" },
{ title: "Category Ten", url: "#" },
],
},
],
collections: [
{
title: "Collection",
description:
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse varius enim in eros elementum tristique.",
button: { title: "View all", variant: "secondary-alt", size: "sm" },
image: {
src: "https://d22po4pjz3o32e.cloudfront.net/placeholder-image.svg",
alt: "Relume placeholder image",
},
},
{
title: "Collection",
description:
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse varius enim in eros elementum tristique.",
button: { title: "View all", variant: "secondary-alt", size: "sm" },
image: {
src: "https://d22po4pjz3o32e.cloudfront.net/placeholder-image.svg",
alt: "Relume placeholder image",
},
},
],
},
},
],
buttons: [
{
title: "Button",
variant: "secondary",
size: "sm",
},
{
title: "Button",
size: "sm",
},
],
};
const topLineVariants = {
open: {
translateY: 8,
transition: { delay: 0.1 },
},
rotatePhase: {
rotate: -45,
transition: { delay: 0.2 },
},
closed: {
translateY: 0,
rotate: 0,
transition: { duration: 0.2 },
},
};
const middleLineVariants = {
open: {
width: 0,
transition: { duration: 0.1 },
},
closed: {
width: "1.5rem",
transition: { delay: 0.3, duration: 0.2 },
},
};
const bottomLineVariants = {
open: {
translateY: -8,
transition: { delay: 0.1 },
},
rotatePhase: {
rotate: 45,
transition: { delay: 0.2 },
},
closed: {
translateY: 0,
rotate: 0,
transition: { duration: 0.2 },
},
};npm i @radix-ui/react-accordion @radix-ui/react-dialog @radix-ui/react-slot @radix-ui/react-tabs class-variance-authority@0.7.1 clsx@^2.1.1 embla-carousel-react@^8.5.2 framer-motion motion@^12.15.0 relume-icons@1.3.0 tailwind-merge@^2.2.2


