Skip to content

Commit 642c944

Browse files
authored
Merge pull request #13503 from ethereum/shadcn-desktop-menu
Shadcn migration - desktop menu
2 parents c7b18ff + f10af22 commit 642c944

File tree

2 files changed

+42
-61
lines changed

2 files changed

+42
-61
lines changed

src/components/Nav/Menu/index.tsx

Lines changed: 41 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import { BaseHTMLAttributes } from "react"
12
import { motion } from "framer-motion"
23
import dynamic from "next/dynamic"
3-
import { Box, type BoxProps, Text, UnorderedList } from "@chakra-ui/react"
44
import {
55
Item,
66
List,
@@ -9,15 +9,16 @@ import {
99
Viewport,
1010
} from "@radix-ui/react-navigation-menu"
1111

12-
import { Button } from "@/components/Buttons"
12+
import { cn } from "@/lib/utils/cn"
1313

14-
import { MAIN_NAV_ID, NAV_PY, SECTION_LABELS } from "@/lib/constants"
14+
import { MAIN_NAV_ID, SECTION_LABELS } from "@/lib/constants"
1515

16+
import { Button } from "../../../../tailwind/ui/buttons/Button"
1617
import type { NavSections } from "../types"
1718

1819
import { useNavMenu } from "./useNavMenu"
1920

20-
type NavMenuProps = BoxProps & {
21+
type NavMenuProps = BaseHTMLAttributes<HTMLDivElement> & {
2122
sections: NavSections
2223
}
2324

@@ -28,73 +29,53 @@ const Menu = ({ sections, ...props }: NavMenuProps) => {
2829
const MenuContent = dynamic(() => import("./MenuContent"))
2930

3031
return (
31-
<Box {...props}>
32+
<div {...props}>
3233
<Root
3334
dir={direction}
3435
orientation="horizontal"
3536
onValueChange={handleSectionChange}
3637
delayDuration={0}
3738
>
38-
<List asChild>
39-
<UnorderedList
40-
id={MAIN_NAV_ID}
41-
display="flex"
42-
listStyleType="none"
43-
m="0"
44-
>
45-
{SECTION_LABELS.map((sectionKey) => {
46-
const { label, items } = sections[sectionKey]
47-
const isActive = activeSection === sectionKey
39+
<List id={MAIN_NAV_ID} className="m-0 flex list-none">
40+
{SECTION_LABELS.map((sectionKey) => {
41+
const { label, items } = sections[sectionKey]
42+
const isActive = activeSection === sectionKey
4843

49-
return (
50-
<Item key={sectionKey} value={label}>
51-
<Trigger asChild>
52-
<Button
53-
py="2"
54-
px={{ base: "3", lg: "4" }}
55-
variant="ghost"
56-
whiteSpace="nowrap"
57-
color={isActive ? "primary.base" : "body.base"}
58-
_after={{
59-
content: '""',
60-
position: "absolute",
61-
insetInline: 0,
62-
top: "100%",
63-
height: NAV_PY,
64-
}}
65-
>
66-
{/* Animated highlight for active section */}
67-
{isActive && (
68-
<Box
69-
as={motion.div}
70-
layoutId="active-section-highlight"
71-
position="absolute"
72-
inset="0"
73-
bg="primary.lowContrast"
74-
rounded="base"
75-
zIndex={0}
76-
/>
77-
)}
78-
<Text as="span" position="relative" zIndex={1}>
79-
{label}
80-
</Text>
81-
</Button>
82-
</Trigger>
83-
{/* Desktop Menu content */}
84-
<MenuContent
85-
items={items}
86-
isOpen={isOpen}
87-
sections={sections}
88-
/>
89-
</Item>
90-
)
91-
})}
92-
</UnorderedList>
44+
return (
45+
<Item key={sectionKey} value={label}>
46+
<Trigger asChild>
47+
<Button
48+
className={cn(
49+
"relative whitespace-nowrap px-3 py-2 lg:px-4",
50+
isActive ? "text-primary" : "text-body",
51+
"after:absolute after:inset-x-0 after:top-full after:h-4 after:content-['']"
52+
)}
53+
variant="ghost"
54+
>
55+
{/* Animated highlight for active section */}
56+
{isActive && (
57+
<motion.div
58+
layoutId="active-section-highlight"
59+
className="absolute inset-0 z-0 rounded bg-primary-low-contrast"
60+
/>
61+
)}
62+
<span className="relative z-10">{label}</span>
63+
</Button>
64+
</Trigger>
65+
{/* Desktop Menu content */}
66+
<MenuContent
67+
items={items}
68+
isOpen={isOpen}
69+
sections={sections}
70+
/>
71+
</Item>
72+
)
73+
})}
9374
</List>
9475

9576
<Viewport />
9677
</Root>
97-
</Box>
78+
</div>
9879
)
9980
}
10081

src/components/Nav/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ const Nav = () => {
6565
{/* avoid rendering desktop Menu version on mobile */}
6666

6767
{isClient && isDesktopFlag ? (
68-
<Menu hideBelow="md" sections={linkSections} />
68+
<Menu className="hidden md:block" sections={linkSections} />
6969
) : (
7070
<Box />
7171
)}

0 commit comments

Comments
 (0)