Skip to main content
astrocraft-ui/ components · 101

Nav

Free · MIT

Headless, accessible, and styled entirely through the attribute surface below — bring your own CSS system, or start from the reference theme.

Install

Without a flag you get no styling at all — plain HTML carrying the attribute surface below. --theme copies the same theme in two dialects;--bridge lumos re-points either one onto Lumos for Astro's tokens (it needs a theme to re-point, and Lumos itself, already in your project).

Unstyled — behavior only, you write the CSS

Install command
npx astrocraft-ui add navigation/nav

Plain-CSS theme — no build step

Install command
npx astrocraft-ui add navigation/nav --theme css

Tailwind theme — needs Tailwind v4

Install command
npx astrocraft-ui add navigation/nav --theme tailwind

Plain-CSS theme, re-pointed onto Lumos tokens

Install command
npx astrocraft-ui add navigation/nav --theme css --bridge lumos

Tailwind theme, re-pointed onto Lumos tokens

Install command
npx astrocraft-ui add navigation/nav --theme tailwind --bridge lumos

Live demo

Nav

The primitive is a plain route-driven list of links; this dev page wires clicks below so you can preview the active state moving between variants.

Attribute surface

With no class-merging machinery, these attributes are the whole extension point. State is a data-attribute or a native attribute; visibility is the hiddenattribute. Generated from source by pnpm slots.

ComponentSlotsVariantsRuntime stateNative state
`Nav.astro``nav` `nav-list``data-orientation`: `horizontal` · `vertical`——
`NavItem.astro``nav-item`———
`NavLink.astro``nav-link``data-variant`: `underline` · `pills` · `segment`——

Source

What the command copies — 4 files, alias-free so the copy lands standing alone. This is the whole component; there is nothing else.

src/components/ui/navigation/nav/Nav.astro
---
// src/components/ui/navigation/nav/Nav.astro — headless primitive (see ../../README.md).
// Static navigation list (<nav> + <ul>). Compose NavItem / NavLink. Active state is the caller's
// job via `aria-current="page"` on the link (route-driven, zero-JS — the platform models it).
import type { HTMLAttributes } from "astro/types";

type Props = HTMLAttributes<"nav"> & { orientation?: "horizontal" | "vertical" };

const { orientation = "horizontal", class: className, ...rest } = Astro.props;
---

<nav data-slot="nav" {...rest}>
  <ul class={className} data-slot="nav-list" data-orientation={orientation}>
    <slot />
  </ul>
</nav>
src/components/ui/navigation/nav/NavItem.astro
---
// src/components/ui/navigation/nav/NavItem.astro — Nav compound part (see ../../README.md).
import type { HTMLAttributes } from "astro/types";

type Props = HTMLAttributes<"li">;

const { class: className, ...rest } = Astro.props;
---

<li class={className} data-slot="nav-item" {...rest}>
  <slot />
</li>
src/components/ui/navigation/nav/NavLink.astro
---
// src/components/ui/navigation/nav/NavLink.astro — Nav compound part (see ../../README.md).
// Active state = `aria-current="page"` set by the caller — the platform already models it, so no
// "active" prop and no data attribute duplicating it. A theme styles hover on non-active links with
// `[data-slot="nav-link"]:not([aria-current="page"]):hover`, which is what the old
// `not-aria-[current=page]:hover:` utility compiled to.
import type { HTMLAttributes } from "astro/types";

type Props = HTMLAttributes<"a"> & {
  href: string;
  variant?: "underline" | "pills" | "segment";
};

const { variant = "underline", href, class: className, ...rest } = Astro.props;
---

<a href={href} class={className} data-slot="nav-link" data-variant={variant} {...rest}>
  <slot />
</a>
src/components/ui/navigation/nav/index.ts
import Nav from "./Nav.astro";
import NavItem from "./NavItem.astro";
import NavLink from "./NavLink.astro";

export { Nav, NavItem, NavLink };
export default Nav;

What you get

The component source, copied into your project by npx astrocraft-ui add navigation/nav — no package dependency, no CSS to fight. Whatever the paid blocks compose, this is it.