# Nav

> The main site navigation bar with responsive mobile menu, search, and active link highlighting.

The Nav component provides the primary site navigation. It displays your site's
brand (a text wordmark by default, or a logo if you pass one), a list of
navigation links, and optional search. On viewports narrower than 640px, the
links collapse behind a hamburger menu button. The colour-scheme control lives
in the footer.

```astro
---
import Nav from "astro-theme-university/components/Nav.astro";
---
```

## Props

<PropsTable component="components/Nav" />

The `NavLink` type has the following shape:

```ts
interface NavLink {
  text: string;
  href: string;
}
```

## Usage

Nav is typically used via `BaseLayout` rather than directly, but it can be used
standalone if you need a custom layout.

```astro
---
import Nav from "astro-theme-university/components/Nav.astro";
---

<Nav
  name="My Site"
  links={[
    { text: "Home", href: "/" },
    { text: "About", href: "/about/" },
    { text: "Blog", href: "/blog/" },
  ]}
/>
```

## Behaviour

The component handles several concerns automatically:

- **Active link detection** --- the current page's link receives
  `aria-current="page"` based on URL path matching.
- **Mobile menu** --- below 640px, links move behind a hamburger toggle button
  that updates `aria-expanded`.
- **Search** --- the optional search button opens a native dialog backed by the
  site's Pagefind index; <kbd>Cmd/Ctrl+K</kbd> works globally.
- **Brand mark** --- with no `logo` prop, the site `name` renders as a text
  wordmark (`.at-nav-wordmark`). When you pass a `logo` (an imported
  `ImageMetadata`), it replaces the wordmark; pass `logoDark` as well and the
  nav switches between the two based on the active theme (`logoDark` is only
  used when `logo` is also given).
- **Compact mark** --- a wide horizontal lockup can wrap the nav bar on narrow
  screens. Pass `logoCompact` (a crest or monogram) and the nav swaps to it
  below the 640px breakpoint, restoring the full `logo` above it;
  `logoCompactDark` supplies a dark-mode variant. Both are only used when `logo`
  is given.

## Notes

A live example is not shown here as it would conflict with this page's own
navigation. See the nav bar at the top of this site for a working instance.
