Installation

Once the project is set up (see Installation), add the component and every Component file it builds on:

pnpm dlx shadcn@4.23.1 add @effectcn/navigation-links

Then import it:

import { NavigationLinksRoot, NavigationLinksList, NavigationLinksItem, NavigationLinksLink, NavigationLinksTitle, NavigationLinksBadge } from "#ui/navigation-links"

Usage

Basic.ts
import { UiSchema } from "@effect/ui"
import { Html } from "@effect/ui/html"
import { NavigationLinks } from "@effect/ui-kit"
import { Schema } from "effect"
import { NavigationLinksItem, NavigationLinksLink, NavigationLinksList, NavigationLinksRoot } from "#ui/navigation-links"

const NavigationLinksBasicMessage = UiSchema.TaggedEnum({
  ClickedLink: { path: Schema.String }
})

const pages = [
  { path: "#overview", label: "Overview" },
  { path: "#customers", label: "Customers" },
  { path: "#products", label: "Products" },
  { path: "#settings", label: "Settings" }
]

export const NavigationLinksBasic = Html.component({
  name: "NavigationLinksBasic",
  model: Schema.Struct({ path: Schema.String }),
  message: NavigationLinksBasicMessage
}).make({
  init: () => ({ path: "#overview" }),
  update: {
    ClickedLink: ($, { path }) => $.evolve({ path })
  },
  view: (h, model) =>
    NavigationLinks(h, {
      view: (navigationLinks) =>
        NavigationLinksRoot(h, navigationLinks, { label: "Main" }).children(
          NavigationLinksList(h, navigationLinks).children(
            pages.map((page) =>
              NavigationLinksItem(h, navigationLinks, { key: page.path }).children(
                NavigationLinksLink(h, navigationLinks, { href: page.path, active: page.path === model.path })
                  .on("click", NavigationLinksBasicMessage.ClickedLink({ path: page.path }), { preventDefault: "always" })
                  .children(page.label)
              )
            )
          )
        )
    })
})

Examples

Vertical, with sections

A sidebar: one list with titles between the links, moved through with ArrowDown and ArrowUp.

Icons and counts

Links with an icon in front and a badge at the end.

Segmented, with a disabled link

The segmented variant puts the links on a muted track. The arrow keys skip a link with aria-disabled.

Two lists under one parent each take a key and their own aria-label, and keep their arrow keys to themselves.

Anatomy

The parts the view closure receives. Apply each one to an element of your own.

PartDescription
rootThe <nav> landmark. Give it an aria-label when the page has more than one.
listThe <ul> inside the root. It carries the arrow keys.
itemAn <li> inside the list, around one link.
linkAn <a>, { element, active }. The href and the click are the consumer's.

API reference

Props

PropTypeDescription
orientation"horizontal" | "vertical"Right and Left move focus between the links by default; "vertical" uses Down and Up.

Data attributes

AttributeDescription
data-activeOn the active link, which also gets aria-current="page".

effectcn is built with Effect UI and @effect/ui-kit. Not affiliated with Effectful Technologies.