|
1
|
"use client" |
|
2
|
|
|
3
|
import { BarsThree, Book, SidebarLeft, TimelineVertical } from "@medusajs/icons" |
|
4
|
import React, { useMemo, useRef, useState } from "react" |
|
5
|
import { Button } from "@/components/Button" |
|
6
|
import { Menu } from "@/components/Menu" |
|
7
|
import { useSidebar } from "@/providers/Sidebar" |
|
8
|
import { useClickOutside } from "@/hooks/use-click-outside" |
|
9
|
import { getOsShortcut } from "@/utils/os-browser-utils" |
|
10
|
import clsx from "clsx" |
|
11
|
import { HouseIcon } from "../../Icons/House" |
|
12
|
import { MainNavThemeMenu } from "./ThemeMenu" |
|
13
|
import { MenuItem } from "types" |
|
14
|
import { useMainNav } from "../../../providers/MainNav" |
|
15
|
|
|
16
|
export const MainNavDesktopMenu = () => { |
|
17
|
const [isOpen, setIsOpen] = useState(false) |
|
18
|
const { setDesktopSidebarOpen, isSidebarShown, desktopSidebarOpen } = |
|
19
|
useSidebar() |
|
20
|
const { additionalMenuItems } = useMainNav() |
|
21
|
const ref = useRef<HTMLDivElement>(null) |
|
22
|
|
|
23
|
useClickOutside({ |
|
24
|
elmRef: ref, |
|
25
|
onClickOutside: () => setIsOpen(false), |
|
26
|
}) |
|
27
|
|
|
28
|
const items: MenuItem[] = useMemo(() => { |
|
29
|
const items: MenuItem[] = additionalMenuItems |
|
30
|
? [...additionalMenuItems] |
|
31
|
: [ |
|
32
|
{ |
|
33
|
type: "link", |
|
34
|
icon: <HouseIcon />, |
|
35
|
title: "Homepage", |
|
36
|
link: "https://medusajs.com", |
|
37
|
}, |
|
38
|
{ |
|
39
|
type: "link", |
|
40
|
icon: <Book />, |
|
41
|
title: "Medusa v1", |
|
42
|
link: "https://docs.medusajs.com/v1", |
|
43
|
}, |
|
44
|
{ |
|
45
|
type: "link", |
|
46
|
icon: <TimelineVertical />, |
|
47
|
title: "Changelog", |
|
48
|
link: "https://medusajs.com/changelog", |
|
49
|
}, |
|
50
|
] |
|
51
|
|
|
52
|
if (isSidebarShown) { |
|
53
|
items.push( |
|
54
|
{ |
|
55
|
type: "divider", |
|
56
|
}, |
|
57
|
{ |
|
58
|
type: "action", |
|
59
|
title: desktopSidebarOpen ? "Hide Sidebar" : "Show Sidebar", |
|
60
|
icon: <SidebarLeft />, |
|
61
|
shortcut: `${getOsShortcut()}\\`, |
|
62
|
action: () => { |
|
63
|
setDesktopSidebarOpen((prev) => !prev) |
|
64
|
setIsOpen(false) |
|
65
|
}, |
|
66
|
} |
|
67
|
) |
|
68
|
} |
|
69
|
|
|
70
|
items.push( |
|
71
|
{ |
|
72
|
type: "divider", |
|
73
|
}, |
|
74
|
{ |
|
75
|
type: "custom", |
|
76
|
content: <MainNavThemeMenu />, |
|
77
|
} |
|
78
|
) |
|
79
|
|
|
80
|
return items |
|
81
|
}, [isSidebarShown, desktopSidebarOpen, additionalMenuItems]) |
|
82
|
|
|
83
|
return ( |
|
84
|
<div |
|
85
|
className="relative hidden lg:flex justify-center items-center" |
|
86
|
ref={ref} |
|
87
|
> |
|
88
|
<Button |
|
89
|
variant="transparent" |
|
90
|
onClick={() => setIsOpen((prev) => !prev)} |
|
91
|
className="!p-[6.5px]" |
|
92
|
data-testid="menu-button" |
|
93
|
> |
|
94
|
<BarsThree className="text-medusa-fg-subtle" /> |
|
95
|
</Button> |
|
96
|
<Menu |
|
97
|
className={clsx( |
|
98
|
"absolute top-[calc(100%+8px)] right-0 min-w-[200px]", |
|
99
|
!isOpen && "hidden" |
|
100
|
)} |
|
101
|
items={items} |
|
102
|
/> |
|
103
|
</div> |
|
104
|
) |
|
105
|
} |