Tailwind CSS Navbar - React

Use our responsive React and Tailwind CSS navigation for your website. You can add links, icons, links with icons, search bars, and brand text.

See below our navbar examples that you can use in your Tailwind CSS and React project. The examples comes in different styles and colors, so you can adapt it easily to your needs.


Here's how to implement a simple and responsive navbar component with your logo, nav links and a auth button.

import * as React from "react";
import {
Button,
IconButton,
Typography,
Collapse,
Navbar,
} from "@material-tailwind/react";
import {
Archive,
Menu,
MultiplePages,
ProfileCircle,
SelectFace3d,
Xmark,
} from "iconoir-react";

const LINKS = [
{
icon: MultiplePages,
title: "Pages",
href: "#",
},
{
icon: ProfileCircle,
title: "Account",
href: "#",
},
{
icon: SelectFace3d,
title: "Blocks",
href: "#",
},
{
icon: Archive,
title: "Docs",
href: "#",
},
];

function NavList() {
return (
<ul className="mt-4 flex flex-col gap-x-3 gap-y-1.5 lg:mt-0 lg:flex-row lg:items-center">
{LINKS.map(({ icon: Icon, title, href }) => (
<li key={title}>
<Typography
as="a"
href={href}
type="small"
className="flex items-center gap-x-2 p-1 hover:text-primary"
>
<Icon className="h-4 w-4" />
{title}
</Typography>
</li>
))}
</ul>
);
}

export function NavbarDemo() {
const [openNav, setOpenNav] = React.useState(false);

React.useEffect(() => {
window.addEventListener(
"resize",
() => window.innerWidth >= 960 && setOpenNav(false),
);
}, []);

return (
<Navbar className="mx-auto w-full max-w-screen-xl">
<div className="flex items-center">
<Typography
as="a"
href="#"
type="small"
className="ml-2 mr-2 block py-1 font-semibold"
>
Material Tailwind
</Typography>
<hr className="ml-1 mr-1.5 hidden h-5 w-px border-l border-t-0 border-secondary-dark lg:block" />
<div className="hidden lg:block">
<NavList />
</div>
<Button size="sm" className="hidden lg:ml-auto lg:inline-block">
Sign In
</Button>
<IconButton
size="sm"
variant="ghost"
color="secondary"
onClick={() => setOpenNav(!openNav)}
className="ml-auto grid lg:hidden"
>
{openNav ? (
<Xmark className="h-4 w-4" />
) : (
<Menu className="h-4 w-4" />
)}
</IconButton>
</div>
<Collapse open={openNav}>
<NavList />
<Button isFullWidth size="sm" className="mt-4">
Sign In
</Button>
</Collapse>
</Navbar>
);
}
import * as React from "react";
import {
Button,
IconButton,
Typography,
Collapse,
Navbar,
} from "@material-tailwind/react";
import {
Archive,
Menu,
MultiplePages,
ProfileCircle,
SelectFace3d,
Xmark,
} from "iconoir-react";

const LINKS = [
{
icon: MultiplePages,
title: "Pages",
href: "#",
},
{
icon: ProfileCircle,
title: "Account",
href: "#",
},
{
icon: SelectFace3d,
title: "Blocks",
href: "#",
},
{
icon: Archive,
title: "Docs",
href: "#",
},
];

function NavList() {
return (
<ul className="mt-4 flex flex-col gap-x-3 gap-y-1.5 lg:mt-0 lg:flex-row lg:items-center">
{LINKS.map(({ icon: Icon, title, href }) => (
<li key={title}>
<Typography
as="a"
href={href}
type="small"
className="flex items-center gap-x-2 p-1 hover:text-primary"
>
<Icon className="h-4 w-4" />
{title}
</Typography>
</li>
))}
</ul>
);
}

export function NavbarDemo() {
const [openNav, setOpenNav] = React.useState(false);

React.useEffect(() => {
window.addEventListener(
"resize",
() => window.innerWidth >= 960 && setOpenNav(false),
);
}, []);

return (
<Navbar className="mx-auto w-full max-w-screen-xl">
<div className="flex items-center">
<Typography
as="a"
href="#"
type="small"
className="ml-2 mr-2 block py-1 font-semibold"
>
Material Tailwind
</Typography>
<hr className="ml-1 mr-1.5 hidden h-5 w-px border-l border-t-0 border-secondary-dark lg:block" />
<div className="hidden lg:block">
<NavList />
</div>
<Button size="sm" className="hidden lg:ml-auto lg:inline-block">
Sign In
</Button>
<IconButton
size="sm"
variant="ghost"
color="secondary"
onClick={() => setOpenNav(!openNav)}
className="ml-auto grid lg:hidden"
>
{openNav ? (
<Xmark className="h-4 w-4" />
) : (
<Menu className="h-4 w-4" />
)}
</IconButton>
</div>
<Collapse open={openNav}>
<NavList />
<Button isFullWidth size="sm" className="mt-4">
Sign In
</Button>
</Collapse>
</Navbar>
);
}

Use this navbar example for a sticky navbar that stays at the top of the page when you scroll down. It comes with your logo, nav links + icons and a auth button.

In the example below we've used the Iconoir icons, but you can use any other icon library you prefer.

import * as React from "react";
import {
Button,
IconButton,
Typography,
Collapse,
Navbar,
} from "@material-tailwind/react";
import {
Archive,
Menu,
MultiplePages,
ProfileCircle,
SelectFace3d,
Xmark,
MediaImage,
} from "iconoir-react";

const LINKS = [
{
icon: MultiplePages,
title: "Pages",
href: "#",
},
{
icon: ProfileCircle,
title: "Account",
href: "#",
},
{
icon: SelectFace3d,
title: "Blocks",
href: "#",
},
{
icon: Archive,
title: "Docs",
href: "#",
},
];

function NavList() {
return (
<ul className="mt-4 flex flex-col gap-x-3 gap-y-1.5 lg:mt-0 lg:flex-row lg:items-center">
{LINKS.map(({ icon: Icon, title, href }) => (
<li key={title}>
<Typography
as="a"
href={href}
type="small"
className="flex items-center gap-x-2 p-1 hover:text-primary"
>
<Icon className="h-4 w-4" />
{title}
</Typography>
</li>
))}
</ul>
);
}

export function StickyNavbar() {
const [openNav, setOpenNav] = React.useState(false);

React.useEffect(() => {
window.addEventListener(
"resize",
() => window.innerWidth >= 960 && setOpenNav(false),
);
}, []);

return (
<div className="h-96 w-full overflow-scroll">
<Navbar className="sticky top-0 mx-auto w-full max-w-screen-xl">
<div className="flex items-center">
<Typography
as="a"
href="#"
type="small"
className="ml-2 mr-2 block py-1 font-semibold"
>
Material Tailwind
</Typography>
<hr className="ml-1 mr-1.5 hidden h-5 w-px border-l border-t-0 border-secondary-dark lg:block" />
<div className="hidden lg:block">
<NavList />
</div>
<Button size="sm" className="hidden lg:ml-auto lg:inline-block">
Sign In
</Button>
<IconButton
size="sm"
variant="ghost"
color="secondary"
onClick={() => setOpenNav(!openNav)}
className="ml-auto grid lg:hidden"
>
{openNav ? (
<Xmark className="h-4 w-4" />
) : (
<Menu className="h-4 w-4" />
)}
</IconButton>
</div>
<Collapse open={openNav}>
<NavList />
<Button isFullWidth size="sm" className="mt-4">
Sign In
</Button>
</Collapse>
</Navbar>
<main className="w-full">
<div className="mx-auto max-w-xl">
<div className="my-8">
<div className="mb-2 h-2 w-full rounded-full bg-surface"></div>
<div className="mb-2 h-2 w-full rounded-full bg-surface"></div>
<div className="mb-2 h-2 w-full rounded-full bg-surface"></div>
<div className="mb-2 h-2 w-full rounded-full bg-surface"></div>
<div className="mb-2 h-2 w-full rounded-full bg-surface"></div>
<div className="mb-2 h-2 w-full rounded-full bg-surface"></div>
</div>
<div className="mb-6 max-w-xl">
<div className="flex h-56 w-full items-center justify-center rounded bg-surface">
<MediaImage className="h-16 w-16 text-surface-dark" />
</div>
</div>
<div className="my-8">
<div className="mb-2 h-2 w-full rounded-full bg-surface"></div>
<div className="mb-2 h-2 w-full rounded-full bg-surface"></div>
<div className="mb-2 h-2 w-full rounded-full bg-surface"></div>
<div className="mb-2 h-2 w-full rounded-full bg-surface"></div>
<div className="mb-2 h-2 w-full rounded-full bg-surface"></div>
<div className="mb-2 h-2 w-full rounded-full bg-surface"></div>
</div>
<div className="my-8">
<div className="mb-2 h-2 w-full rounded-full bg-surface"></div>
<div className="mb-2 h-2 w-full rounded-full bg-surface"></div>
<div className="mb-2 h-2 w-full rounded-full bg-surface"></div>
<div className="mb-2 h-2 w-full rounded-full bg-surface"></div>
</div>
<div className="my-8">
<div className="mb-2 h-2 w-full rounded-full bg-surface"></div>
<div className="mb-2 h-2 w-full rounded-full bg-surface"></div>
<div className="mb-2 h-2 w-full rounded-full bg-surface"></div>
<div className="mb-2 h-2 w-full rounded-full bg-surface"></div>
<div className="mb-2 h-2 w-full rounded-full bg-surface"></div>
<div className="mb-2 h-2 w-full rounded-full bg-surface"></div>
<div className="mb-2 h-2 w-full rounded-full bg-surface"></div>
<div className="mb-2 h-2 w-full rounded-full bg-surface"></div>
</div>
<div className="my-8">
<div className="mb-2 h-2 w-full rounded-full bg-surface"></div>
<div className="mb-2 h-2 w-full rounded-full bg-surface"></div>
<div className="mb-2 h-2 w-full rounded-full bg-surface"></div>
<div className="mb-2 h-2 w-full rounded-full bg-surface"></div>
<div className="mb-2 h-2 w-full rounded-full bg-surface"></div>
<div className="mb-2 h-2 w-full rounded-full bg-surface"></div>
</div>
</div>
</main>
</div>
);
}
import * as React from "react";
import {
Button,
IconButton,
Typography,
Collapse,
Navbar,
} from "@material-tailwind/react";
import {
Archive,
Menu,
MultiplePages,
ProfileCircle,
SelectFace3d,
Xmark,
MediaImage,
} from "iconoir-react";

const LINKS = [
{
icon: MultiplePages,
title: "Pages",
href: "#",
},
{
icon: ProfileCircle,
title: "Account",
href: "#",
},
{
icon: SelectFace3d,
title: "Blocks",
href: "#",
},
{
icon: Archive,
title: "Docs",
href: "#",
},
];

function NavList() {
return (
<ul className="mt-4 flex flex-col gap-x-3 gap-y-1.5 lg:mt-0 lg:flex-row lg:items-center">
{LINKS.map(({ icon: Icon, title, href }) => (
<li key={title}>
<Typography
as="a"
href={href}
type="small"
className="flex items-center gap-x-2 p-1 hover:text-primary"
>
<Icon className="h-4 w-4" />
{title}
</Typography>
</li>
))}
</ul>
);
}

export function StickyNavbar() {
const [openNav, setOpenNav] = React.useState(false);

React.useEffect(() => {
window.addEventListener(
"resize",
() => window.innerWidth >= 960 && setOpenNav(false),
);
}, []);

return (
<div className="h-96 w-full overflow-scroll">
<Navbar className="sticky top-0 mx-auto w-full max-w-screen-xl">
<div className="flex items-center">
<Typography
as="a"
href="#"
type="small"
className="ml-2 mr-2 block py-1 font-semibold"
>
Material Tailwind
</Typography>
<hr className="ml-1 mr-1.5 hidden h-5 w-px border-l border-t-0 border-secondary-dark lg:block" />
<div className="hidden lg:block">
<NavList />
</div>
<Button size="sm" className="hidden lg:ml-auto lg:inline-block">
Sign In
</Button>
<IconButton
size="sm"
variant="ghost"
color="secondary"
onClick={() => setOpenNav(!openNav)}
className="ml-auto grid lg:hidden"
>
{openNav ? (
<Xmark className="h-4 w-4" />
) : (
<Menu className="h-4 w-4" />
)}
</IconButton>
</div>
<Collapse open={openNav}>
<NavList />
<Button isFullWidth size="sm" className="mt-4">
Sign In
</Button>
</Collapse>
</Navbar>
<main className="w-full">
<div className="mx-auto max-w-xl">
<div className="my-8">
<div className="mb-2 h-2 w-full rounded-full bg-surface"></div>
<div className="mb-2 h-2 w-full rounded-full bg-surface"></div>
<div className="mb-2 h-2 w-full rounded-full bg-surface"></div>
<div className="mb-2 h-2 w-full rounded-full bg-surface"></div>
<div className="mb-2 h-2 w-full rounded-full bg-surface"></div>
<div className="mb-2 h-2 w-full rounded-full bg-surface"></div>
</div>
<div className="mb-6 max-w-xl">
<div className="flex h-56 w-full items-center justify-center rounded bg-surface">
<MediaImage className="h-16 w-16 text-surface-dark" />
</div>
</div>
<div className="my-8">
<div className="mb-2 h-2 w-full rounded-full bg-surface"></div>
<div className="mb-2 h-2 w-full rounded-full bg-surface"></div>
<div className="mb-2 h-2 w-full rounded-full bg-surface"></div>
<div className="mb-2 h-2 w-full rounded-full bg-surface"></div>
<div className="mb-2 h-2 w-full rounded-full bg-surface"></div>
<div className="mb-2 h-2 w-full rounded-full bg-surface"></div>
</div>
<div className="my-8">
<div className="mb-2 h-2 w-full rounded-full bg-surface"></div>
<div className="mb-2 h-2 w-full rounded-full bg-surface"></div>
<div className="mb-2 h-2 w-full rounded-full bg-surface"></div>
<div className="mb-2 h-2 w-full rounded-full bg-surface"></div>
</div>
<div className="my-8">
<div className="mb-2 h-2 w-full rounded-full bg-surface"></div>
<div className="mb-2 h-2 w-full rounded-full bg-surface"></div>
<div className="mb-2 h-2 w-full rounded-full bg-surface"></div>
<div className="mb-2 h-2 w-full rounded-full bg-surface"></div>
<div className="mb-2 h-2 w-full rounded-full bg-surface"></div>
<div className="mb-2 h-2 w-full rounded-full bg-surface"></div>
<div className="mb-2 h-2 w-full rounded-full bg-surface"></div>
<div className="mb-2 h-2 w-full rounded-full bg-surface"></div>
</div>
<div className="my-8">
<div className="mb-2 h-2 w-full rounded-full bg-surface"></div>
<div className="mb-2 h-2 w-full rounded-full bg-surface"></div>
<div className="mb-2 h-2 w-full rounded-full bg-surface"></div>
<div className="mb-2 h-2 w-full rounded-full bg-surface"></div>
<div className="mb-2 h-2 w-full rounded-full bg-surface"></div>
<div className="mb-2 h-2 w-full rounded-full bg-surface"></div>
</div>
</div>
</main>
</div>
);
}

Complex Navbar

Use this navbar example to create a more complex navbar with your logo, nav links + icons, dropdown menu and a user profile menu.

In the example below we've used the Iconoir icons, but you can use any other icon library you prefer.

import * as React from "react";
import {
IconButton,
Typography,
Collapse,
Navbar,
Card,
List,
Avatar,
Menu,
Tooltip,
Accordion,
type MenuItemProps,
} from "@material-tailwind/react";
import {
Archive,
HeadsetHelp,
LogOut,
Menu as MenuIcon,
MultiplePages,
NavArrowDown,
ProfileCircle,
Rocket,
SelectFace3d,
Settings,
UserCircle,
Xmark,
} from "iconoir-react";

const LINKS = [
{
icon: ProfileCircle,
title: "Account",
href: "#",
},
{
icon: SelectFace3d,
title: "Blocks",
href: "#",
},
{
icon: Archive,
title: "Docs",
href: "#",
},
];

function NavList() {
return (
<>
{LINKS.map(({ icon: Icon, title, href }) => (
<List.Item key={title} as="a" href={href}>
<List.ItemStart className="mr-1.5">
<Icon className="h-4 w-4" />
</List.ItemStart>
<Typography type="small">{title}</Typography>
</List.Item>
))}
</>
);
}

function ProfileMenu() {
return (
<Menu>
<Menu.Trigger
as={Avatar}
src="https://dub.sh/iu8bOfU"
alt="profile-picture"
size="sm"
className="border border-primary p-0.5 lg:ml-auto"
/>
<Menu.Content>
<Menu.Item>
<UserCircle className="mr-2 h-[18px] w-[18px]" /> My Profile
</Menu.Item>
<Menu.Item>
<Settings className="mr-2 h-[18px] w-[18px]" /> Edit Profile
</Menu.Item>
<Menu.Item>
<HeadsetHelp className="mr-2 h-[18px] w-[18px]" /> Support
</Menu.Item>
<hr className="!my-1 -mx-1 border-surface" />
<Menu.Item className="text-error hover:bg-error/10 hover:text-error focus:bg-error/10 focus:text-error">
<LogOut className="mr-2 h-[18px] w-[18px]" />
Logout
</Menu.Item>
</Menu.Content>
</Menu>
);
}

const MenuItem = React.forwardRef<
typeof Menu.Item,
{
title: string;
description: string;
} & MenuItemProps
>(({ title, description, ...rest }, ref) => {
return (
<Menu.Item ref={ref} {...rest} className="flex-col items-start">
<Typography color="default" className="font-semibold">
{title}
</Typography>
<Typography type="small" className="text-foreground">
{description}
</Typography>
</Menu.Item>
);
});

export function ComplexNavbar() {
const [openNav, setOpenNav] = React.useState(false);

React.useEffect(() => {
window.addEventListener(
"resize",
() => window.innerWidth >= 960 && setOpenNav(false),
);
}, []);

return (
<Navbar className="mx-auto w-full max-w-screen-xl">
<div className="flex items-center">
<Typography
as="a"
href="#"
type="small"
className="ml-2 mr-2 block py-1 font-semibold"
>
Material Tailwind
</Typography>
<hr className="mx-1 hidden h-5 w-px border-l border-t-0 border-secondary-dark lg:block" />
<div className="hidden lg:block">
<List className="mt-4 flex flex-col gap-1 lg:mt-0 lg:flex-row lg:items-center">
<Tooltip placement="bottom" interactive>
<Tooltip.Trigger>
<List.Item>
<List.ItemStart className="me-1.5">
<MultiplePages className="h-4 w-4" />
</List.ItemStart>
<Typography type="small">Pages</Typography>
<List.ItemEnd className="ps-0.5">
<NavArrowDown className="h-3.5 w-3.5 group-data-[open=true]:rotate-180" />
</List.ItemEnd>
</List.Item>
</Tooltip.Trigger>
<Tooltip.Content className="grid max-w-lg grid-cols-5 gap-1 rounded-lg border border-surface bg-background p-1 shadow-xl shadow-surface/5 dark:border-surface dark:bg-background">
<Card
color="primary"
className="col-span-2 grid place-items-center rounded-[5px] px-8 py-4 text-primary-foreground shadow-none"
>
<div>
<Rocket className="mx-auto h-12 w-12" />
<Typography
type="h6"
className="mt-5 text-center leading-snug"
>
Material Tailwind PRO
</Typography>
</div>
</Card>
<ul className="col-span-3 !m-0">
<MenuItem
title="@material-tailwind/html"
description="Learn how to use @material-tailwind/html, packed with rich components and widgets."
/>
<MenuItem
title="@material-tailwind/react"
description="Learn how to use @material-tailwind/react, packed with rich components for React."
/>
<MenuItem
title="Material Tailwind PRO"
description="A complete set of UI Elements for building faster websites in less time."
/>
</ul>
<Tooltip.Arrow />
</Tooltip.Content>
</Tooltip>
<NavList />
</List>
</div>
<IconButton
size="sm"
variant="ghost"
color="secondary"
onClick={() => setOpenNav(!openNav)}
className="ml-auto mr-2 grid lg:hidden"
>
{openNav ? (
<Xmark className="h-4 w-4" />
) : (
<MenuIcon className="h-4 w-4" />
)}
</IconButton>
<ProfileMenu />
</div>
<Collapse open={openNav}>
<Accordion>
<Accordion.Item value="react" className="mt-2 border-none">
<Accordion.Trigger className="p-0">
<List.Item className="w-full">
<List.ItemStart className="me-1.5">
<MultiplePages className="h-4 w-4" />
</List.ItemStart>
<Typography type="small">Pages</Typography>
<List.ItemEnd className="ps-1">
<NavArrowDown className="h-3.5 w-3.5 group-data-[open=true]:rotate-180" />
</List.ItemEnd>
</List.Item>
</Accordion.Trigger>
<Accordion.Content>
<MenuItem
title="@material-tailwind/html"
description="Learn how to use @material-tailwind/html, packed with rich components and widgets."
/>
<MenuItem
title="@material-tailwind/react"
description="Learn how to use @material-tailwind/react, packed with rich components for React."
/>
<MenuItem
title="Material Tailwind PRO"
description="A complete set of UI Elements for building faster websites in less time."
/>
</Accordion.Content>
</Accordion.Item>
</Accordion>
<NavList />
</Collapse>
</Navbar>
);
}
import * as React from "react";
import {
IconButton,
Typography,
Collapse,
Navbar,
Card,
List,
Avatar,
Menu,
Tooltip,
Accordion,
type MenuItemProps,
} from "@material-tailwind/react";
import {
Archive,
HeadsetHelp,
LogOut,
Menu as MenuIcon,
MultiplePages,
NavArrowDown,
ProfileCircle,
Rocket,
SelectFace3d,
Settings,
UserCircle,
Xmark,
} from "iconoir-react";

const LINKS = [
{
icon: ProfileCircle,
title: "Account",
href: "#",
},
{
icon: SelectFace3d,
title: "Blocks",
href: "#",
},
{
icon: Archive,
title: "Docs",
href: "#",
},
];

function NavList() {
return (
<>
{LINKS.map(({ icon: Icon, title, href }) => (
<List.Item key={title} as="a" href={href}>
<List.ItemStart className="mr-1.5">
<Icon className="h-4 w-4" />
</List.ItemStart>
<Typography type="small">{title}</Typography>
</List.Item>
))}
</>
);
}

function ProfileMenu() {
return (
<Menu>
<Menu.Trigger
as={Avatar}
src="https://dub.sh/iu8bOfU"
alt="profile-picture"
size="sm"
className="border border-primary p-0.5 lg:ml-auto"
/>
<Menu.Content>
<Menu.Item>
<UserCircle className="mr-2 h-[18px] w-[18px]" /> My Profile
</Menu.Item>
<Menu.Item>
<Settings className="mr-2 h-[18px] w-[18px]" /> Edit Profile
</Menu.Item>
<Menu.Item>
<HeadsetHelp className="mr-2 h-[18px] w-[18px]" /> Support
</Menu.Item>
<hr className="!my-1 -mx-1 border-surface" />
<Menu.Item className="text-error hover:bg-error/10 hover:text-error focus:bg-error/10 focus:text-error">
<LogOut className="mr-2 h-[18px] w-[18px]" />
Logout
</Menu.Item>
</Menu.Content>
</Menu>
);
}

const MenuItem = React.forwardRef<
typeof Menu.Item,
{
title: string;
description: string;
} & MenuItemProps
>(({ title, description, ...rest }, ref) => {
return (
<Menu.Item ref={ref} {...rest} className="flex-col items-start">
<Typography color="default" className="font-semibold">
{title}
</Typography>
<Typography type="small" className="text-foreground">
{description}
</Typography>
</Menu.Item>
);
});

export function ComplexNavbar() {
const [openNav, setOpenNav] = React.useState(false);

React.useEffect(() => {
window.addEventListener(
"resize",
() => window.innerWidth >= 960 && setOpenNav(false),
);
}, []);

return (
<Navbar className="mx-auto w-full max-w-screen-xl">
<div className="flex items-center">
<Typography
as="a"
href="#"
type="small"
className="ml-2 mr-2 block py-1 font-semibold"
>
Material Tailwind
</Typography>
<hr className="mx-1 hidden h-5 w-px border-l border-t-0 border-secondary-dark lg:block" />
<div className="hidden lg:block">
<List className="mt-4 flex flex-col gap-1 lg:mt-0 lg:flex-row lg:items-center">
<Tooltip placement="bottom" interactive>
<Tooltip.Trigger>
<List.Item>
<List.ItemStart className="me-1.5">
<MultiplePages className="h-4 w-4" />
</List.ItemStart>
<Typography type="small">Pages</Typography>
<List.ItemEnd className="ps-0.5">
<NavArrowDown className="h-3.5 w-3.5 group-data-[open=true]:rotate-180" />
</List.ItemEnd>
</List.Item>
</Tooltip.Trigger>
<Tooltip.Content className="grid max-w-lg grid-cols-5 gap-1 rounded-lg border border-surface bg-background p-1 shadow-xl shadow-surface/5 dark:border-surface dark:bg-background">
<Card
color="primary"
className="col-span-2 grid place-items-center rounded-[5px] px-8 py-4 text-primary-foreground shadow-none"
>
<div>
<Rocket className="mx-auto h-12 w-12" />
<Typography
type="h6"
className="mt-5 text-center leading-snug"
>
Material Tailwind PRO
</Typography>
</div>
</Card>
<ul className="col-span-3 !m-0">
<MenuItem
title="@material-tailwind/html"
description="Learn how to use @material-tailwind/html, packed with rich components and widgets."
/>
<MenuItem
title="@material-tailwind/react"
description="Learn how to use @material-tailwind/react, packed with rich components for React."
/>
<MenuItem
title="Material Tailwind PRO"
description="A complete set of UI Elements for building faster websites in less time."
/>
</ul>
<Tooltip.Arrow />
</Tooltip.Content>
</Tooltip>
<NavList />
</List>
</div>
<IconButton
size="sm"
variant="ghost"
color="secondary"
onClick={() => setOpenNav(!openNav)}
className="ml-auto mr-2 grid lg:hidden"
>
{openNav ? (
<Xmark className="h-4 w-4" />
) : (
<MenuIcon className="h-4 w-4" />
)}
</IconButton>
<ProfileMenu />
</div>
<Collapse open={openNav}>
<Accordion>
<Accordion.Item value="react" className="mt-2 border-none">
<Accordion.Trigger className="p-0">
<List.Item className="w-full">
<List.ItemStart className="me-1.5">
<MultiplePages className="h-4 w-4" />
</List.ItemStart>
<Typography type="small">Pages</Typography>
<List.ItemEnd className="ps-1">
<NavArrowDown className="h-3.5 w-3.5 group-data-[open=true]:rotate-180" />
</List.ItemEnd>
</List.Item>
</Accordion.Trigger>
<Accordion.Content>
<MenuItem
title="@material-tailwind/html"
description="Learn how to use @material-tailwind/html, packed with rich components and widgets."
/>
<MenuItem
title="@material-tailwind/react"
description="Learn how to use @material-tailwind/react, packed with rich components for React."
/>
<MenuItem
title="Material Tailwind PRO"
description="A complete set of UI Elements for building faster websites in less time."
/>
</Accordion.Content>
</Accordion.Item>
</Accordion>
<NavList />
</Collapse>
</Navbar>
);
}

Use this navbar example to create a navbar with a search bar. It comes with your logo, nav links + icons and a search bar.

In the example below we've used the Iconoir icons, but you can use any other icon library you prefer.

import * as React from "react";
import {
IconButton,
Typography,
Collapse,
Navbar,
Input,
} from "@material-tailwind/react";
import {
Archive,
Menu,
MultiplePages,
ProfileCircle,
Search,
SelectFace3d,
Xmark,
} from "iconoir-react";

const LINKS = [
{
icon: MultiplePages,
title: "Pages",
href: "#",
},
{
icon: ProfileCircle,
title: "Account",
href: "#",
},
{
icon: SelectFace3d,
title: "Blocks",
href: "#",
},
{
icon: Archive,
title: "Docs",
href: "#",
},
];

function NavList() {
return (
<ul className="mt-4 flex flex-col gap-x-3 gap-y-1.5 lg:mt-0 lg:flex-row lg:items-center">
{LINKS.map(({ icon: Icon, title, href }) => (
<li key={title}>
<Typography
as="a"
href={href}
type="small"
className="flex items-center gap-x-2 p-1 hover:text-primary"
>
<Icon className="h-4 w-4" />
{title}
</Typography>
</li>
))}
</ul>
);
}

export function NavbarWithSearch() {
const [openNav, setOpenNav] = React.useState(false);

React.useEffect(() => {
window.addEventListener(
"resize",
() => window.innerWidth >= 960 && setOpenNav(false),
);
}, []);

return (
<Navbar className="mx-auto w-full max-w-screen-xl">
<div className="flex items-center">
<Typography
as="a"
href="#"
type="small"
className="ml-2 mr-2 block py-1 font-semibold"
>
Material Tailwind
</Typography>
<hr className="ml-1 mr-1.5 hidden h-5 w-px border-l border-t-0 border-secondary-dark lg:block" />
<div className="hidden lg:block">
<NavList />
</div>
<Input size="sm" className="ml-auto w-40">
<Input.Icon>
<Search className="h-full w-full" />
</Input.Icon>
<Input.Field type="search" placeholder="Search here..." />
</Input>
<IconButton
size="sm"
variant="ghost"
onClick={() => setOpenNav(!openNav)}
className="ml-1 grid lg:hidden"
>
{openNav ? (
<Xmark className="h-4 w-4" />
) : (
<Menu className="h-4 w-4" />
)}
</IconButton>
</div>
<Collapse open={openNav}>
<NavList />
</Collapse>
</Navbar>
);
}
import * as React from "react";
import {
IconButton,
Typography,
Collapse,
Navbar,
Input,
} from "@material-tailwind/react";
import {
Archive,
Menu,
MultiplePages,
ProfileCircle,
Search,
SelectFace3d,
Xmark,
} from "iconoir-react";

const LINKS = [
{
icon: MultiplePages,
title: "Pages",
href: "#",
},
{
icon: ProfileCircle,
title: "Account",
href: "#",
},
{
icon: SelectFace3d,
title: "Blocks",
href: "#",
},
{
icon: Archive,
title: "Docs",
href: "#",
},
];

function NavList() {
return (
<ul className="mt-4 flex flex-col gap-x-3 gap-y-1.5 lg:mt-0 lg:flex-row lg:items-center">
{LINKS.map(({ icon: Icon, title, href }) => (
<li key={title}>
<Typography
as="a"
href={href}
type="small"
className="flex items-center gap-x-2 p-1 hover:text-primary"
>
<Icon className="h-4 w-4" />
{title}
</Typography>
</li>
))}
</ul>
);
}

export function NavbarWithSearch() {
const [openNav, setOpenNav] = React.useState(false);

React.useEffect(() => {
window.addEventListener(
"resize",
() => window.innerWidth >= 960 && setOpenNav(false),
);
}, []);

return (
<Navbar className="mx-auto w-full max-w-screen-xl">
<div className="flex items-center">
<Typography
as="a"
href="#"
type="small"
className="ml-2 mr-2 block py-1 font-semibold"
>
Material Tailwind
</Typography>
<hr className="ml-1 mr-1.5 hidden h-5 w-px border-l border-t-0 border-secondary-dark lg:block" />
<div className="hidden lg:block">
<NavList />
</div>
<Input size="sm" className="ml-auto w-40">
<Input.Icon>
<Search className="h-full w-full" />
</Input.Icon>
<Input.Field type="search" placeholder="Search here..." />
</Input>
<IconButton
size="sm"
variant="ghost"
onClick={() => setOpenNav(!openNav)}
className="ml-1 grid lg:hidden"
>
{openNav ? (
<Xmark className="h-4 w-4" />
) : (
<Menu className="h-4 w-4" />
)}
</IconButton>
</div>
<Collapse open={openNav}>
<NavList />
</Collapse>
</Navbar>
);
}

Dark Navbar

Use this navbar example to create a dark navbar with your logo, nav links + icons and auth button for dark surfaces and themes in your website.

In the example below we've used the Iconoir icons, but you can use any other icon library you prefer.

import * as React from "react";
import {
Button,
IconButton,
Typography,
Collapse,
Navbar,
} from "@material-tailwind/react";
import {
Archive,
Menu,
MultiplePages,
ProfileCircle,
SelectFace3d,
Xmark,
} from "iconoir-react";

const LINKS = [
{
icon: MultiplePages,
title: "Pages",
href: "#",
},
{
icon: ProfileCircle,
title: "Account",
href: "#",
},
{
icon: SelectFace3d,
title: "Blocks",
href: "#",
},
{
icon: Archive,
title: "Docs",
href: "#",
},
];

function NavList() {
return (
<ul className="mt-4 flex flex-col gap-x-3 gap-y-1.5 lg:mt-0 lg:flex-row lg:items-center">
{LINKS.map(({ icon: Icon, title, href }) => (
<li key={title}>
<Typography
as="a"
href={href}
type="small"
className="flex items-center gap-x-2 p-1 text-white hover:text-white"
>
<Icon className="h-4 w-4" />
{title}
</Typography>
</li>
))}
</ul>
);
}

export function DarkNavbar() {
const [openNav, setOpenNav] = React.useState(false);

React.useEffect(() => {
window.addEventListener(
"resize",
() => window.innerWidth >= 960 && setOpenNav(false),
);
}, []);

return (
<Navbar className="mx-auto w-full max-w-screen-xl bg-black dark:bg-surface-dark">
<div className="flex items-center text-white">
<Typography
as="a"
href="#"
type="small"
className="ml-2 mr-2 block py-1 font-semibold"
>
Material Tailwind
</Typography>
<hr className="ml-1 mr-1.5 hidden h-5 w-px border-l border-t-0 border-surface/25 lg:block dark:border-surface" />
<div className="hidden lg:block">
<NavList />
</div>
<Button
size="sm"
className="hidden border-white bg-white text-black hover:border-white hover:bg-white hover:text-black lg:ml-auto lg:inline-block"
>
Sign In
</Button>
<IconButton
size="sm"
color="secondary"
onClick={() => setOpenNav(!openNav)}
className="ml-auto grid lg:hidden"
>
{openNav ? (
<Xmark className="h-4 w-4" />
) : (
<Menu className="h-4 w-4" />
)}
</IconButton>
</div>
<Collapse open={openNav}>
<NavList />
<Button
size="sm"
isFullWidth
className="mt-4 border-white bg-white text-black hover:border-white hover:bg-white hover:text-black"
>
Sign In
</Button>
</Collapse>
</Navbar>
);
}
import * as React from "react";
import {
Button,
IconButton,
Typography,
Collapse,
Navbar,
} from "@material-tailwind/react";
import {
Archive,
Menu,
MultiplePages,
ProfileCircle,
SelectFace3d,
Xmark,
} from "iconoir-react";

const LINKS = [
{
icon: MultiplePages,
title: "Pages",
href: "#",
},
{
icon: ProfileCircle,
title: "Account",
href: "#",
},
{
icon: SelectFace3d,
title: "Blocks",
href: "#",
},
{
icon: Archive,
title: "Docs",
href: "#",
},
];

function NavList() {
return (
<ul className="mt-4 flex flex-col gap-x-3 gap-y-1.5 lg:mt-0 lg:flex-row lg:items-center">
{LINKS.map(({ icon: Icon, title, href }) => (
<li key={title}>
<Typography
as="a"
href={href}
type="small"
className="flex items-center gap-x-2 p-1 text-white hover:text-white"
>
<Icon className="h-4 w-4" />
{title}
</Typography>
</li>
))}
</ul>
);
}

export function DarkNavbar() {
const [openNav, setOpenNav] = React.useState(false);

React.useEffect(() => {
window.addEventListener(
"resize",
() => window.innerWidth >= 960 && setOpenNav(false),
);
}, []);

return (
<Navbar className="mx-auto w-full max-w-screen-xl bg-black dark:bg-surface-dark">
<div className="flex items-center text-white">
<Typography
as="a"
href="#"
type="small"
className="ml-2 mr-2 block py-1 font-semibold"
>
Material Tailwind
</Typography>
<hr className="ml-1 mr-1.5 hidden h-5 w-px border-l border-t-0 border-surface/25 lg:block dark:border-surface" />
<div className="hidden lg:block">
<NavList />
</div>
<Button
size="sm"
className="hidden border-white bg-white text-black hover:border-white hover:bg-white hover:text-black lg:ml-auto lg:inline-block"
>
Sign In
</Button>
<IconButton
size="sm"
color="secondary"
onClick={() => setOpenNav(!openNav)}
className="ml-auto grid lg:hidden"
>
{openNav ? (
<Xmark className="h-4 w-4" />
) : (
<Menu className="h-4 w-4" />
)}
</IconButton>
</div>
<Collapse open={openNav}>
<NavList />
<Button
size="sm"
isFullWidth
className="mt-4 border-white bg-white text-black hover:border-white hover:bg-white hover:text-black"
>
Sign In
</Button>
</Collapse>
</Navbar>
);
}

Simple Navbar

Use this navbar example to create a simple navbar with your logo and nav links for your website.

import * as React from "react";
import {
IconButton,
Typography,
Collapse,
Navbar,
} from "@material-tailwind/react";
import { Menu, Xmark } from "iconoir-react";

const LINKS = [
{
title: "Pages",
href: "#",
},
{
title: "Account",
href: "#",
},
{
title: "Blocks",
href: "#",
},
{
title: "Docs",
href: "#",
},
];

function NavList() {
return (
<ul className="m-2 flex flex-col gap-x-3 gap-y-1 lg:m-0 lg:flex-row lg:items-center">
{LINKS.map(({ title, href }) => (
<li key={title}>
<Typography
as="a"
href={href}
type="small"
className="p-1 hover:text-primary"
>
{title}
</Typography>
</li>
))}
</ul>
);
}

export function SimpleNavbar() {
const [openNav, setOpenNav] = React.useState(false);

React.useEffect(() => {
window.addEventListener(
"resize",
() => window.innerWidth >= 960 && setOpenNav(false),
);
}, []);

return (
<Navbar className="mx-auto w-full max-w-screen-xl">
<div className="flex items-center">
<Typography
as="a"
href="#"
type="small"
className="mx-2 block py-1 font-semibold"
>
Material Tailwind
</Typography>
<div className="hidden lg:ml-auto lg:mr-2 lg:block">
<NavList />
</div>
<IconButton
size="sm"
variant="ghost"
color="secondary"
onClick={() => setOpenNav(!openNav)}
className="ml-auto grid lg:hidden"
>
{openNav ? (
<Xmark className="h-4 w-4" />
) : (
<Menu className="h-4 w-4" />
)}
</IconButton>
</div>
<Collapse open={openNav}>
<NavList />
</Collapse>
</Navbar>
);
}
import * as React from "react";
import {
IconButton,
Typography,
Collapse,
Navbar,
} from "@material-tailwind/react";
import { Menu, Xmark } from "iconoir-react";

const LINKS = [
{
title: "Pages",
href: "#",
},
{
title: "Account",
href: "#",
},
{
title: "Blocks",
href: "#",
},
{
title: "Docs",
href: "#",
},
];

function NavList() {
return (
<ul className="m-2 flex flex-col gap-x-3 gap-y-1 lg:m-0 lg:flex-row lg:items-center">
{LINKS.map(({ title, href }) => (
<li key={title}>
<Typography
as="a"
href={href}
type="small"
className="p-1 hover:text-primary"
>
{title}
</Typography>
</li>
))}
</ul>
);
}

export function SimpleNavbar() {
const [openNav, setOpenNav] = React.useState(false);

React.useEffect(() => {
window.addEventListener(
"resize",
() => window.innerWidth >= 960 && setOpenNav(false),
);
}, []);

return (
<Navbar className="mx-auto w-full max-w-screen-xl">
<div className="flex items-center">
<Typography
as="a"
href="#"
type="small"
className="mx-2 block py-1 font-semibold"
>
Material Tailwind
</Typography>
<div className="hidden lg:ml-auto lg:mr-2 lg:block">
<NavList />
</div>
<IconButton
size="sm"
variant="ghost"
color="secondary"
onClick={() => setOpenNav(!openNav)}
className="ml-auto grid lg:hidden"
>
{openNav ? (
<Xmark className="h-4 w-4" />
) : (
<Menu className="h-4 w-4" />
)}
</IconButton>
</div>
<Collapse open={openNav}>
<NavList />
</Collapse>
</Navbar>
);
}

Use this navbar example to create a navbar with mega menu of links and categories, this is useful for e-commerce and SaaS websites.

In the example below we've used the Iconoir icons, but you can use any other icon library you prefer.

import * as React from "react";
import {
IconButton,
Typography,
Collapse,
Card,
Navbar,
List,
Avatar,
Menu,
Tooltip,
} from "@material-tailwind/react";
import {
Archive,
Community,
Globe,
GridPlus,
Hashtag,
HeadsetHelp,
JournalPage,
LogOut,
Menu as MenuIcon,
MultiplePages,
NavArrowDown,
Phone,
Post,
ProfileCircle,
SelectFace3d,
Settings,
SunLight,
UserCircle,
Xmark,
} from "iconoir-react";

const LINKS = [
{
icon: ProfileCircle,
title: "Account",
href: "#",
},
{
icon: SelectFace3d,
title: "Blocks",
href: "#",
},
{
icon: Archive,
title: "Docs",
href: "#",
},
];

const navListMenuItems = [
{
title: "Products",
description: "Find the perfect solution for your needs.",
icon: GridPlus,
},
{
title: "About Us",
description: "Meet and learn about our dedication",
icon: Community,
},
{
title: "Blog",
description: "Find the perfect solution for your needs.",
icon: Post,
},
{
title: "Services",
description: "Learn how we can help you achieve your goals.",
icon: SunLight,
},
{
title: "Support",
description: "Reach out to us for assistance or inquiries",
icon: Globe,
},
{
title: "Contact",
description: "Find the perfect solution for your needs.",
icon: Phone,
},
{
title: "News",
description: "Read insightful articles, tips, and expert opinions.",
icon: JournalPage,
},
{
title: "Products",
description: "Find the perfect solution for your needs.",
icon: SelectFace3d,
},
{
title: "Special Offers",
description: "Explore limited-time deals and bundles",
icon: Hashtag,
},
];

function NavList() {
return (
<>
{LINKS.map(({ icon: Icon, title, href }) => (
<List.Item key={title} as="a" href={href}>
<List.ItemStart className="mr-1.5">
<Icon className="h-4 w-4" />
</List.ItemStart>
<Typography type="small">{title}</Typography>
</List.Item>
))}
</>
);
}

function ProfileMenu() {
return (
<Menu>
<Menu.Trigger
as={Avatar}
src="https://dub.sh/iu8bOfU"
alt="profile-picture"
size="sm"
className="border border-primary p-0.5 lg:ml-auto"
/>
<Menu.Content>
<Menu.Item>
<UserCircle className="mr-2 h-[18px] w-[18px]" /> My Profile
</Menu.Item>
<Menu.Item>
<Settings className="mr-2 h-[18px] w-[18px]" /> Edit Profile
</Menu.Item>
<Menu.Item>
<HeadsetHelp className="mr-2 h-[18px] w-[18px]" /> Support
</Menu.Item>
<hr className="!my-1 -mx-1 border-secondary-dark" />
<Menu.Item className="text-error hover:bg-error/10 hover:text-error focus:bg-error/10 focus:text-error dark:hover:text-error dark:focus:text-error">
<LogOut className="mr-2 h-[18px] w-[18px]" />
Logout
</Menu.Item>
</Menu.Content>
</Menu>
);
}

const MenuItem = React.forwardRef<
typeof Menu.Item,
{
title: string;
description: string;
icon?: React.ElementType;
}
>(({ title, description, icon: Icon, ...rest }, ref) => {
return (
<List.Item ref={ref} as="a" href="#" className="p-1.5" {...rest}>
{Icon && (
<List.ItemStart>
<div className="flex items-center justify-center rounded-[5px] bg-surface-light p-2">
<Icon className="h-6 w-6 text-black dark:text-white" />
</div>
</List.ItemStart>
)}
<div className="leading-none">
<Typography color="default" className="mb-0.5 text-sm font-semibold">
{title}
</Typography>
<Typography type="small" className="text-xs text-foreground">
{description}
</Typography>
</div>
</List.Item>
);
});

export function NavbarWithMegaMenu() {
const [openNav, setOpenNav] = React.useState(false);

const renderItems = navListMenuItems.map(
({ icon, title, description }, key) => (
<MenuItem key={key} title={title} description={description} icon={icon} />
),
);

React.useEffect(() => {
window.addEventListener(
"resize",
() => window.innerWidth >= 960 && setOpenNav(false),
);
}, []);

return (
<Navbar className="mx-auto w-full max-w-screen-xl">
<div className="flex items-center">
<Typography
as="a"
href="#"
type="small"
className="ml-2 mr-2 block py-1 font-semibold"
>
Material Tailwind
</Typography>
<hr className="mx-1 hidden h-5 w-px border-l border-t-0 border-secondary-dark lg:block" />
<div className="hidden lg:block">
<List className="mt-4 flex flex-col gap-1 lg:mt-0 lg:flex-row lg:items-center">
<Tooltip placement="bottom" interactive>
<Tooltip.Trigger>
<List.Item>
<List.ItemStart className="me-1.5">
<MultiplePages className="h-4 w-4" />
</List.ItemStart>
<Typography type="small">Pages</Typography>
<List.ItemEnd className="ps-1">
<NavArrowDown className="h-3.5 w-3.5 group-data-[open=true]:rotate-180" />
</List.ItemEnd>
</List.Item>
</Tooltip.Trigger>
<Tooltip.Content className="z-[100000] grid max-w-screen-xl rounded-lg border border-surface bg-background p-2 shadow-xl shadow-surface/10 dark:border-surface dark:bg-background">
<ul className="grid grid-cols-3 gap-y-2">{renderItems}</ul>
<Tooltip.Arrow />
</Tooltip.Content>
</Tooltip>
<NavList />
</List>
</div>
<IconButton
size="sm"
variant="ghost"
color="secondary"
onClick={() => setOpenNav(!openNav)}
className="ml-auto mr-2 grid lg:hidden"
>
{openNav ? (
<Xmark className="h-4 w-4" />
) : (
<MenuIcon className="h-4 w-4" />
)}
</IconButton>
<ProfileMenu />
</div>
<Collapse open={openNav}>
<ul className="grid grid-cols-1 gap-y-2 md:grid-cols-2">
{renderItems}
</ul>
<NavList />
</Collapse>
</Navbar>
);
}
import * as React from "react";
import {
IconButton,
Typography,
Collapse,
Card,
Navbar,
List,
Avatar,
Menu,
Tooltip,
} from "@material-tailwind/react";
import {
Archive,
Community,
Globe,
GridPlus,
Hashtag,
HeadsetHelp,
JournalPage,
LogOut,
Menu as MenuIcon,
MultiplePages,
NavArrowDown,
Phone,
Post,
ProfileCircle,
SelectFace3d,
Settings,
SunLight,
UserCircle,
Xmark,
} from "iconoir-react";

const LINKS = [
{
icon: ProfileCircle,
title: "Account",
href: "#",
},
{
icon: SelectFace3d,
title: "Blocks",
href: "#",
},
{
icon: Archive,
title: "Docs",
href: "#",
},
];

const navListMenuItems = [
{
title: "Products",
description: "Find the perfect solution for your needs.",
icon: GridPlus,
},
{
title: "About Us",
description: "Meet and learn about our dedication",
icon: Community,
},
{
title: "Blog",
description: "Find the perfect solution for your needs.",
icon: Post,
},
{
title: "Services",
description: "Learn how we can help you achieve your goals.",
icon: SunLight,
},
{
title: "Support",
description: "Reach out to us for assistance or inquiries",
icon: Globe,
},
{
title: "Contact",
description: "Find the perfect solution for your needs.",
icon: Phone,
},
{
title: "News",
description: "Read insightful articles, tips, and expert opinions.",
icon: JournalPage,
},
{
title: "Products",
description: "Find the perfect solution for your needs.",
icon: SelectFace3d,
},
{
title: "Special Offers",
description: "Explore limited-time deals and bundles",
icon: Hashtag,
},
];

function NavList() {
return (
<>
{LINKS.map(({ icon: Icon, title, href }) => (
<List.Item key={title} as="a" href={href}>
<List.ItemStart className="mr-1.5">
<Icon className="h-4 w-4" />
</List.ItemStart>
<Typography type="small">{title}</Typography>
</List.Item>
))}
</>
);
}

function ProfileMenu() {
return (
<Menu>
<Menu.Trigger
as={Avatar}
src="https://dub.sh/iu8bOfU"
alt="profile-picture"
size="sm"
className="border border-primary p-0.5 lg:ml-auto"
/>
<Menu.Content>
<Menu.Item>
<UserCircle className="mr-2 h-[18px] w-[18px]" /> My Profile
</Menu.Item>
<Menu.Item>
<Settings className="mr-2 h-[18px] w-[18px]" /> Edit Profile
</Menu.Item>
<Menu.Item>
<HeadsetHelp className="mr-2 h-[18px] w-[18px]" /> Support
</Menu.Item>
<hr className="!my-1 -mx-1 border-secondary-dark" />
<Menu.Item className="text-error hover:bg-error/10 hover:text-error focus:bg-error/10 focus:text-error dark:hover:text-error dark:focus:text-error">
<LogOut className="mr-2 h-[18px] w-[18px]" />
Logout
</Menu.Item>
</Menu.Content>
</Menu>
);
}

const MenuItem = React.forwardRef<
typeof Menu.Item,
{
title: string;
description: string;
icon?: React.ElementType;
}
>(({ title, description, icon: Icon, ...rest }, ref) => {
return (
<List.Item ref={ref} as="a" href="#" className="p-1.5" {...rest}>
{Icon && (
<List.ItemStart>
<div className="flex items-center justify-center rounded-[5px] bg-surface-light p-2">
<Icon className="h-6 w-6 text-black dark:text-white" />
</div>
</List.ItemStart>
)}
<div className="leading-none">
<Typography color="default" className="mb-0.5 text-sm font-semibold">
{title}
</Typography>
<Typography type="small" className="text-xs text-foreground">
{description}
</Typography>
</div>
</List.Item>
);
});

export function NavbarWithMegaMenu() {
const [openNav, setOpenNav] = React.useState(false);

const renderItems = navListMenuItems.map(
({ icon, title, description }, key) => (
<MenuItem key={key} title={title} description={description} icon={icon} />
),
);

React.useEffect(() => {
window.addEventListener(
"resize",
() => window.innerWidth >= 960 && setOpenNav(false),
);
}, []);

return (
<Navbar className="mx-auto w-full max-w-screen-xl">
<div className="flex items-center">
<Typography
as="a"
href="#"
type="small"
className="ml-2 mr-2 block py-1 font-semibold"
>
Material Tailwind
</Typography>
<hr className="mx-1 hidden h-5 w-px border-l border-t-0 border-secondary-dark lg:block" />
<div className="hidden lg:block">
<List className="mt-4 flex flex-col gap-1 lg:mt-0 lg:flex-row lg:items-center">
<Tooltip placement="bottom" interactive>
<Tooltip.Trigger>
<List.Item>
<List.ItemStart className="me-1.5">
<MultiplePages className="h-4 w-4" />
</List.ItemStart>
<Typography type="small">Pages</Typography>
<List.ItemEnd className="ps-1">
<NavArrowDown className="h-3.5 w-3.5 group-data-[open=true]:rotate-180" />
</List.ItemEnd>
</List.Item>
</Tooltip.Trigger>
<Tooltip.Content className="z-[100000] grid max-w-screen-xl rounded-lg border border-surface bg-background p-2 shadow-xl shadow-surface/10 dark:border-surface dark:bg-background">
<ul className="grid grid-cols-3 gap-y-2">{renderItems}</ul>
<Tooltip.Arrow />
</Tooltip.Content>
</Tooltip>
<NavList />
</List>
</div>
<IconButton
size="sm"
variant="ghost"
color="secondary"
onClick={() => setOpenNav(!openNav)}
className="ml-auto mr-2 grid lg:hidden"
>
{openNav ? (
<Xmark className="h-4 w-4" />
) : (
<MenuIcon className="h-4 w-4" />
)}
</IconButton>
<ProfileMenu />
</div>
<Collapse open={openNav}>
<ul className="grid grid-cols-1 gap-y-2 md:grid-cols-2">
{renderItems}
</ul>
<NavList />
</Collapse>
</Navbar>
);
}