# Navigation Menu

shadcn navigation-menu reskinned for UI95.

Source: https://www.ui95.dev/ui/navigation-menu

## Examples

```tsx
"use client"

import {
  NavigationMenu,
  NavigationMenuContent,
  NavigationMenuItem,
  NavigationMenuLink,
  NavigationMenuList,
  NavigationMenuTrigger,
  navigationMenuTriggerStyle,
} from "@/components/ui/navigation-menu"

import type { ShowcaseDemo } from "../types"

type Entry = { title: string; description: string }

const DRIVERS: readonly Entry[] = [
  { title: "Disk", description: "Mount a 3.5 inch floppy at A:." },
  { title: "Modem", description: "Dial up at 2400 baud." },
  { title: "Memory", description: "Check the 640K conventional pool." },
  { title: "Sound", description: "Tune the PC speaker beeps." },
]

const FILES: readonly string[] = ["AUTOEXEC.BAT", "CONFIG.SYS", "README.TXT"]

function MenuBar({ viewport }: { viewport: boolean }) {
  return (
    <NavigationMenu viewport={viewport} className="justify-start">
      <NavigationMenuList>
        <NavigationMenuItem>
          <NavigationMenuTrigger>Drivers</NavigationMenuTrigger>
          <NavigationMenuContent>
            <ul className="grid w-64 grid-cols-1 gap-0">
              {DRIVERS.map((driver) => (
                <li key={driver.title}>
                  <NavigationMenuLink
                    href="#"
                    className="flex-col items-start gap-1"
                  >
                    <span className="font-pixel text-[16px] leading-none uppercase">
                      {driver.title}
                    </span>
                    <span className="text-xl leading-tight">
                      {driver.description}
                    </span>
                  </NavigationMenuLink>
                </li>
              ))}
            </ul>
          </NavigationMenuContent>
        </NavigationMenuItem>
        <NavigationMenuItem>
          <NavigationMenuTrigger>Files</NavigationMenuTrigger>
          <NavigationMenuContent>
            <ul className="w-40">
              {FILES.map((file) => (
                <li key={file}>
                  <NavigationMenuLink href="#">{file}</NavigationMenuLink>
                </li>
              ))}
            </ul>
          </NavigationMenuContent>
        </NavigationMenuItem>
        <NavigationMenuItem>
          <NavigationMenuLink href="#" className={navigationMenuTriggerStyle()}>
            Help
          </NavigationMenuLink>
        </NavigationMenuItem>
      </NavigationMenuList>
    </NavigationMenu>
  )
}

export const demo: ShowcaseDemo = {
  span: "wide",
  variants: [
    {
      label: "with viewport",
      render: () => (
        <div className="h-88">
          <MenuBar viewport />
        </div>
      ),
    },
    {
      label: "without viewport",
      render: () => (
        <div className="h-88">
          <MenuBar viewport={false} />
        </div>
      ),
    },
  ],
}
```

## Installation

```bash
npx shadcn@latest add https://www.ui95.dev/r/navigation-menu.json
```

Run it in a Radix shadcn project that already has the UI95 theme.

Dependencies:

```bash
npm install class-variance-authority cn radix-ui
```

Add these items first:

- [pixel-glyphs](https://www.ui95.dev/ui/pixel-glyphs)

`components/ui/navigation-menu.tsx`

```tsx
import { cva } from "class-variance-authority"
import { cn } from "cn"
import { NavigationMenu as NavigationMenuPrimitive } from "radix-ui"
import * as React from "react"

import { ChevronGlyph } from "@/components/ui/pixel-glyphs"

function NavigationMenu({
  className,
  children,
  viewport = true,
  ...props
}: React.ComponentProps<typeof NavigationMenuPrimitive.Root> & {
  viewport?: boolean
}) {
  return (
    <NavigationMenuPrimitive.Root
      data-slot="navigation-menu"
      data-viewport={viewport}
      className={cn(
        "group/navigation-menu relative flex max-w-max flex-1 items-center justify-center",
        className
      )}
      {...props}
    >
      {children}
      {viewport && <NavigationMenuViewport />}
    </NavigationMenuPrimitive.Root>
  )
}

function NavigationMenuList({
  className,
  ...props
}: React.ComponentProps<typeof NavigationMenuPrimitive.List>) {
  return (
    <NavigationMenuPrimitive.List
      data-slot="navigation-menu-list"
      className={cn(
        "group flex flex-1 list-none items-center justify-center gap-0",
        className
      )}
      {...props}
    />
  )
}

function NavigationMenuItem({
  className,
  ...props
}: React.ComponentProps<typeof NavigationMenuPrimitive.Item>) {
  return (
    <NavigationMenuPrimitive.Item
      data-slot="navigation-menu-item"
      className={cn("relative", className)}
      {...props}
    />
  )
}

const navigationMenuTriggerStyle = cva(
  "group/navigation-menu-trigger inline-flex h-8 w-max items-center justify-center px-3 font-pixel text-[16px] leading-none uppercase outline-none select-none hover:bg-foreground hover:text-popover focus:bg-foreground focus:text-popover focus-visible:bg-foreground focus-visible:text-popover disabled:pointer-events-none disabled:text-muted-foreground data-[state=open]:bevel-sunken data-[state=open]:hover:bg-card data-[state=open]:hover:text-card-foreground data-[state=open]:focus:bg-card data-[state=open]:focus:text-card-foreground"
)

function NavigationMenuTrigger({
  className,
  children,
  ...props
}: React.ComponentProps<typeof NavigationMenuPrimitive.Trigger>) {
  return (
    <NavigationMenuPrimitive.Trigger
      data-slot="navigation-menu-trigger"
      className={cn(navigationMenuTriggerStyle(), "group", className)}
      {...props}
    >
      {children}
      <ChevronGlyph className="ml-2 size-3 group-data-[state=open]/navigation-menu-trigger:hidden" />
      <ChevronGlyph
        direction="up"
        className="ml-2 hidden size-3 group-data-[state=open]/navigation-menu-trigger:block"
      />
    </NavigationMenuPrimitive.Trigger>
  )
}

function NavigationMenuContent({
  className,
  ...props
}: React.ComponentProps<typeof NavigationMenuPrimitive.Content>) {
  return (
    <NavigationMenuPrimitive.Content
      data-slot="navigation-menu-content"
      className={cn(
        "top-0 left-0 w-full p-(--pixel) group-data-[viewport=false]/navigation-menu:top-full group-data-[viewport=false]/navigation-menu:mt-1 group-data-[viewport=false]/navigation-menu:overflow-hidden group-data-[viewport=false]/navigation-menu:pixel-border group-data-[viewport=false]/navigation-menu:border-border group-data-[viewport=false]/navigation-menu:bg-popover group-data-[viewport=false]/navigation-menu:text-popover-foreground group-data-[viewport=false]/navigation-menu:offset-shadow-2 **:data-[slot=navigation-menu-link]:focus:outline-none md:absolute md:w-auto",
        className
      )}
      {...props}
    />
  )
}

function NavigationMenuViewport({
  className,
  ...props
}: React.ComponentProps<typeof NavigationMenuPrimitive.Viewport>) {
  return (
    <div className="absolute top-full left-0 isolate z-50 flex justify-center">
      <NavigationMenuPrimitive.Viewport
        data-slot="navigation-menu-viewport"
        className={cn(
          "relative mt-1 h-(--radix-navigation-menu-viewport-height) w-full overflow-hidden pixel-border border-border bg-popover text-popover-foreground offset-shadow-2 md:w-(--radix-navigation-menu-viewport-width)",
          className
        )}
        {...props}
      />
    </div>
  )
}

function NavigationMenuLink({
  className,
  ...props
}: React.ComponentProps<typeof NavigationMenuPrimitive.Link>) {
  return (
    <NavigationMenuPrimitive.Link
      data-slot="navigation-menu-link"
      className={cn(
        "flex items-center gap-2 p-2 text-xl leading-tight outline-none select-none hover:bg-foreground hover:text-popover focus:bg-foreground focus:text-popover data-active:bg-secondary data-active:text-secondary-foreground data-active:hover:bg-foreground data-active:hover:text-popover data-active:focus:bg-foreground data-active:focus:text-popover [&_svg:not([class*='size-'])]:size-3.5",
        className
      )}
      {...props}
    />
  )
}

function NavigationMenuIndicator({
  className,
  ...props
}: React.ComponentProps<typeof NavigationMenuPrimitive.Indicator>) {
  return (
    <NavigationMenuPrimitive.Indicator
      data-slot="navigation-menu-indicator"
      className={cn(
        "top-full z-1 flex h-1.5 items-end justify-center overflow-hidden",
        className
      )}
      {...props}
    >
      <div className="relative top-[60%] h-2 w-2 bg-border" />
    </NavigationMenuPrimitive.Indicator>
  )
}

export {
  NavigationMenu,
  NavigationMenuContent,
  NavigationMenuIndicator,
  NavigationMenuItem,
  NavigationMenuLink,
  NavigationMenuList,
  NavigationMenuTrigger,
  navigationMenuTriggerStyle,
  NavigationMenuViewport,
}
```

## API reference

### NavigationMenu

| Prop | Type | Default |
| --- | --- | --- |
| `viewport` | `boolean` | `true` |

### NavigationMenuContent

No props of its own. It forwards the props of the element or primitive it wraps.

### NavigationMenuIndicator

No props of its own. It forwards the props of the element or primitive it wraps.

### NavigationMenuItem

No props of its own. It forwards the props of the element or primitive it wraps.

### NavigationMenuLink

No props of its own. It forwards the props of the element or primitive it wraps.

### NavigationMenuList

No props of its own. It forwards the props of the element or primitive it wraps.

### NavigationMenuTrigger

No props of its own. It forwards the props of the element or primitive it wraps.

### NavigationMenuViewport

No props of its own. It forwards the props of the element or primitive it wraps.

## Sounds

- `button.press`
- `button.release`
