Raw
1 "use client"
2
3 import clsx from "clsx"
4 import React, { useMemo } from "react"
5 import { Button } from "@/components/Button"
6 import { GITHUB_ISSUES_LINK } from "@/constants"
7 import { SearchModalOpener } from "@/components/Search/ModalOpener"
8 import { useLayout } from "@/providers/Layout"
9 import { useSidebar } from "@/providers/Sidebar"
10 import { useSiteConfig } from "@/providers/SiteConfig"
11 import { MainNavItems } from "./Items"
12 import { MainNavDesktopMenu } from "./DesktopMenu"
13 import { SidebarLeftIcon } from "../Icons/SidebarLeft"
14 import { MainNavMobileMenu } from "./MobileMenu"
15 import Link from "next/link"
16 import { MainNavVersion } from "./Version"
17 import { AiAssistantTriggerButton } from "../AiAssistant/TriggerButton"
18 import { MainNavItemDropdown } from "./Items/Dropdown"
19 import { ColoredMedusaIcon } from "../Icons"
20 import { useMainNav } from "../../providers/MainNav"
21
22 type MainNavProps = {
23 className?: string
24 itemsClassName?: string
25 }
26
27 export const MainNav = ({ className, itemsClassName }: MainNavProps) => {
28 const { logo, logoUrl, helpNavItem } = useMainNav()
29 const { setMobileSidebarOpen, isSidebarShown } = useSidebar()
30 const { config, isInProduct } = useSiteConfig()
31 const { showCollapsedNavbar } = useLayout()
32
33 const collapseNavbar = useMemo(() => {
34 return showCollapsedNavbar && !isInProduct
35 }, [showCollapsedNavbar, isInProduct])
36
37 return (
38 <div
39 className={clsx("w-full z-20 sticky top-0 bg-medusa-bg-base", className)}
40 data-testid="main-nav"
41 >
42 <div
43 className={clsx(
44 "flex justify-between items-center px-docs_1 w-full gap-docs_0.5",
45 "border-b border-medusa-border-base relative z-50"
46 )}
47 data-testid="main-nav-content"
48 >
49 <div className="flex items-center gap-[10px]">
50 {isSidebarShown && (
51 <Button
52 className="lg:hidden my-docs_0.75 !p-[6.5px]"
53 variant="transparent-clear"
54 onClick={() => setMobileSidebarOpen(true)}
55 data-testid="mobile-sidebar-button"
56 >
57 <SidebarLeftIcon />
58 </Button>
59 )}
60 <Link href={`${logoUrl || config.baseUrl}`} data-testid="logo-link">
61 {logo || <ColoredMedusaIcon variant="subtle" />}
62 </Link>
63 </div>
64 {!collapseNavbar && (
65 <MainNavItems className={clsx("flex-grow", itemsClassName)} />
66 )}
67 {!isInProduct && (
68 <div
69 className={clsx(
70 "flex items-center my-docs_0.75",
71 collapseNavbar && "flex-grow justify-between"
72 )}
73 data-testid="main-nav-actions"
74 >
75 <div className="lg:flex items-center gap-docs_0.25 text-medusa-fg-subtle hidden">
76 <MainNavVersion />
77 <MainNavItemDropdown
78 item={
79 helpNavItem || {
80 type: "dropdown",
81 title: "Help",
82 children: [
83 {
84 type: "link",
85 title: "Troubleshooting",
86 link: "https://docs.medusajs.com/resources/troubleshooting",
87 },
88 {
89 type: "link",
90 title: "Report Issue",
91 link: GITHUB_ISSUES_LINK,
92 },
93 {
94 type: "link",
95 title: "Discord Community",
96 link: "https://discord.gg/medusajs",
97 },
98 {
99 type: "divider",
100 },
101 {
102 type: "link",
103 title: "Contact Sales",
104 link: "https://medusajs.com/contact/",
105 },
106 ],
107 }
108 }
109 isActive={false}
110 />
111 </div>
112 <div className="flex items-center">
113 {config.features?.aiAssistant && <AiAssistantTriggerButton />}
114 <SearchModalOpener />
115 <MainNavDesktopMenu />
116 <MainNavMobileMenu />
117 </div>
118 </div>
119 )}
120 </div>
121 {collapseNavbar && (
122 <div
123 className={clsx(
124 "border-b border-medusa-border-base px-docs_1 relative z-10"
125 )}
126 data-testid="collapsed-nav-items"
127 >
128 <MainNavItems className={clsx("flex-wrap", itemsClassName)} />
129 </div>
130 )}
131 </div>
132 )
133 }