Skip to content

Commit 346c278

Browse files
committed
feat: navigation menu
- create better, more consistent border behavior - fix broken links in demo
1 parent d319ab5 commit 346c278

File tree

5 files changed

+64
-23
lines changed

5 files changed

+64
-23
lines changed

app/docs/components/navigation-menu/demo.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,22 +67,22 @@ export default function NavigationMenuDemo() {
6767
href="/"
6868
>
6969
<div className="mt-4 mb-2 text-lg font-medium">
70-
shadcn/ui
70+
8bitcn/ui
7171
</div>
7272
<p className="text-muted-foreground text-sm leading-tight">
7373
Beautifully designed components built with Tailwind CSS.
7474
</p>
7575
</Link>
7676
</NavigationMenuLink>
7777
</li>
78-
<ListItem href="/docs" title="Introduction">
79-
Re-usable components built using Radix UI and Tailwind CSS.
80-
</ListItem>
81-
<ListItem href="/docs/installation" title="Installation">
78+
<ListItem href="/docs" title="Installation">
8279
How to install dependencies and structure your app.
8380
</ListItem>
84-
<ListItem href="/docs/components/typography" title="Typography">
85-
Styles for headings, paragraphs, lists...etc
81+
<ListItem href="/docs/components/accordion" title="Components">
82+
Re-usable components built using Radix UI and Tailwind CSS.
83+
</ListItem>
84+
<ListItem href="/blocks" title="Typography">
85+
Building Retro Blocks for the Web
8686
</ListItem>
8787
</ul>
8888
</NavigationMenuContent>

app/docs/components/navigation-menu/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export default function NavigationMenuPage() {
6868
NavigationMenuList,
6969
NavigationMenuTrigger,
7070
NavigationMenuViewport,
71-
from "@/components/ui/8bit/navigation-menu"
71+
} from "@/components/ui/8bit/navigation-menu"
7272
`}</CodeSnippet>
7373

7474
<CodeSnippet>{`<NavigationMenu>

app/globals.css

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
--sidebar-accent-foreground: oklch(0.21 0.006 285.885);
7777
--sidebar-border: oklch(0.92 0.004 286.32);
7878
--sidebar-ring: oklch(0.795 0.184 86.047);
79+
--shadow-border: var(--foreground);
7980
}
8081

8182
.dark {
@@ -110,6 +111,7 @@
110111
--sidebar-accent-foreground: oklch(0.985 0 0);
111112
--sidebar-border: oklch(1 0 0 / 10%);
112113
--sidebar-ring: oklch(0.554 0.135 66.442);
114+
--shadow-border: var(--ring);
113115
}
114116

115117
@layer base {
@@ -120,3 +122,11 @@
120122
@apply bg-background text-foreground;
121123
}
122124
}
125+
126+
.shadow-border {
127+
box-shadow:
128+
6px 0px var(--shadow-border),
129+
-6px 0px var(--shadow-border),
130+
0px 6px var(--shadow-border),
131+
0px -6px var(--shadow-border);
132+
}

components/ui/8bit/navigation-menu.tsx

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as React from "react"
22
import { Press_Start_2P } from "next/font/google"
3+
import { Indicator, Root, Viewport } from "@radix-ui/react-navigation-menu"
34
import { cva, VariantProps } from "class-variance-authority"
45

56
import { cn } from "@/lib/utils"
@@ -11,7 +12,6 @@ import {
1112
NavigationMenuLink as ShadcnNavigationMenuLink,
1213
NavigationMenuList as ShadcnNavigationMenuList,
1314
NavigationMenuTrigger as ShadcnNavigationMenuTrigger,
14-
NavigationMenuViewport as ShadcnNavigationMenuViewport,
1515
} from "@/components/ui/navigation-menu"
1616

1717
export { navigationMenuTriggerStyle } from "@/components/ui/navigation-menu"
@@ -44,13 +44,26 @@ export interface BitNavigationMenuProps
4444
function NavigationMenu({
4545
className,
4646
font,
47+
children,
48+
viewport = true,
4749
...props
48-
}: React.ComponentProps<typeof ShadcnNavigationMenu> & FontVariantProps) {
50+
}: React.ComponentProps<typeof Root> & {
51+
viewport?: boolean
52+
} & FontVariantProps) {
4953
return (
50-
<ShadcnNavigationMenu
51-
className={cn(font !== "normal" && pressStart.className, className)}
54+
<Root
55+
data-slot="navigation-menu"
56+
data-viewport={viewport}
57+
className={cn(
58+
"group/navigation-menu relative flex max-w-max flex-1 items-center justify-center",
59+
font !== "normal" && pressStart.className,
60+
className
61+
)}
5262
{...props}
53-
/>
63+
>
64+
{children}
65+
{viewport && <NavigationMenuViewport />}
66+
</Root>
5467
)
5568
}
5669

@@ -120,13 +133,24 @@ function NavigationMenuViewport({
120133
className,
121134
font,
122135
...props
123-
}: React.ComponentProps<typeof ShadcnNavigationMenuViewport> &
124-
FontVariantProps) {
136+
}: React.ComponentProps<typeof Viewport> & FontVariantProps) {
125137
return (
126-
<ShadcnNavigationMenuViewport
127-
className={cn(font !== "normal" && pressStart.className, className)}
128-
{...props}
129-
/>
138+
<div
139+
className={cn(
140+
"absolute top-full left-0 isolate z-50 flex justify-center"
141+
)}
142+
>
143+
<Viewport
144+
data-slot="navigation-menu-viewport"
145+
className={cn(
146+
"origin-top-center bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-90 relative mt-3 h-[var(--radix-navigation-menu-viewport-height)] w-full overflow-hidden rounded-md border shadow md:w-[var(--radix-navigation-menu-viewport-width)]",
147+
font !== "normal" && pressStart.className,
148+
"shadow-border",
149+
className
150+
)}
151+
{...props}
152+
/>
153+
</div>
130154
)
131155
}
132156

@@ -150,10 +174,17 @@ function NavigationMenuIndicator({
150174
}: React.ComponentProps<typeof ShadcnNavigationMenuIndicator> &
151175
FontVariantProps) {
152176
return (
153-
<ShadcnNavigationMenuIndicator
154-
className={cn(font !== "normal" && pressStart.className, className)}
177+
<Indicator
178+
data-slot="navigation-menu-indicator"
179+
className={cn(
180+
"data-[state=visible]:animate-in data-[state=hidden]:fade-out data-[state=visible]:fade-in top-full z-[1] flex h-1.5 items-end justify-center overflow-hidden",
181+
font !== "normal" && pressStart.className,
182+
className
183+
)}
155184
{...props}
156-
/>
185+
>
186+
<div className="bg-foreground dark:bg-ring relative top-[60%] h-2 w-2 rotate-45 rounded-tl-sm shadow-md" />
187+
</Indicator>
157188
)
158189
}
159190

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"@radix-ui/react-hover-card": "^1.1.14",
2323
"@radix-ui/react-label": "^2.1.7",
2424
"@radix-ui/react-menubar": "^1.1.15",
25-
"@radix-ui/react-navigation-menu": "^1.2.12",
25+
"@radix-ui/react-navigation-menu": "^1.2.13",
2626
"@radix-ui/react-popover": "^1.1.14",
2727
"@radix-ui/react-progress": "^1.1.7",
2828
"@radix-ui/react-radio-group": "^1.3.7",

0 commit comments

Comments
 (0)