{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"index-step-nav","type":"registry:component","title":"Index Step Nav","description":"A numbered nav whose third item hangs one gutter below the bar on a contrasting plate by the rule, the bar's hairline dipping under it, and a tag that steps to the current item, or the one you point at, in four ticks.","dependencies":[],"registryDependencies":[],"files":[{"path":"components/viberdy/index-step-nav.tsx","content":"\"use client\";\n\nimport { useEffect, useRef, useState, useSyncExternalStore } from \"react\";\nimport type { CSSProperties, KeyboardEvent as ReactKeyboardEvent } from \"react\";\n\n/**\n * IndexStepNav — a numbered nav whose third item hangs below the bar, and a tag that steps.\n *\n * The items are a run: by the rule the third hangs one gutter below the bar\n * on a contrasting plate with the bracket, and the bar's hairline dips to\n * pass under it. A tag steps to the current item (or the one you point at)\n * in four ticks over 320ms, never a glide. An email item copies the address\n * and says so. Field (acid marks) or paper (ink marks).\n *\n * Part of the Broken Grid kit: a Klein-blue field #2416f0, paper plates\n * #f1f0e8, ink #0a0a1f, and acid #e2ff3a only where a rule fires. One rule,\n * \"The Third\": every third module in a run overshoots its leading edge by two\n * gutters (overlapping its neighbour by one) and wears the acid bracket; the\n * ends never break. Radius 0, no shadows; reflows in 380ms, no bounce. Big\n * Shoulders through var(--font-big-shoulders) for display over Geist.\n * Respects prefers-reduced-motion. No dependencies beyond React. Paste it as\n * its own file: it repeats the kit's small helpers, which would clash in one\n * module. Load Big Shoulders with next/font (variable:\n * \"--font-big-shoulders\") on a parent, or from Google Fonts or @fontsource.\n * Needs Tailwind v4 (on v3.4, add the @tailwindcss/container-queries plugin).\n */\n\nconst SANS = 'var(--font-sans, \"Geist\", \"Inter\", ui-sans-serif, system-ui, sans-serif)';\n\nconst MONO = 'var(--font-mono, \"Geist Mono\", ui-monospace, \"SFMono-Regular\", Menlo, Consolas, monospace)';\n\nconst DISPLAY = 'var(--font-big-shoulders, \"Big Shoulders\", \"Big Shoulders Display\", \"Arial Narrow\", \"Roboto Condensed\", sans-serif)';\n\n/**\n * A Klein-blue field, paper plates, blue-black ink, and acid for a rule firing.\n * Secondary and tertiary text clear 4.5:1 on their grounds (ink2 7.4, ink3 5.0\n * on paper; onField2 5.9, onField3 4.8 on the field); `edgeOnPaper` is the 3:1\n * boundary for inputs.\n */\nconst FIELD = {\n  field: \"#2416f0\",\n  raised: \"#3a2ff5\",\n  pressed: \"#1a0ec4\",\n  paper: \"#f1f0e8\",\n  ink: \"#0a0a1f\",\n  ink2: \"rgba(10,10,31,0.72)\",\n  ink3: \"rgba(10,10,31,0.6)\",\n  onField2: \"rgba(241,240,232,0.86)\",\n  onField3: \"rgba(241,240,232,0.76)\",\n  lineOnField: \"rgba(241,240,232,0.22)\",\n  lineOnPaper: \"rgba(10,10,31,0.14)\",\n  edgeOnPaper: \"rgba(10,10,31,0.5)\",\n  edgeOnField: \"rgba(241,240,232,0.6)\",\n  acid: \"#e2ff3a\",\n} as const;\n\n/** The mark (bracket, tag, focus ring) for a ground: acid on the field, ink on paper. */\nfunction bgMark(ground: \"field\" | \"paper\"): CSSProperties {\n  const c = ground === \"field\" ? FIELD.acid : FIELD.ink;\n  return { [\"--bg-mark\" as string]: c, [\"--bg-ring\" as string]: c } as CSSProperties;\n}\n\n/** Layout changes: 380ms, no stagger, no bounce. Role hand-offs take 240ms. */\nconst BG_EASE = \"cubic-bezier(.2,.8,.2,1)\";\n\nconst BG_HANDOFF_MS = 240;\n\nfunction clamp(v: number, lo: number, hi: number): number {\n  return v < lo ? lo : v > hi ? hi : v;\n}\n\n/** Links: strip tabs and newlines, refuse backslashes, allow http(s), mailto, tel and same-site paths. */\nfunction safeHref(raw: string): string {\n  const v = raw.replace(/[\\t\\n\\r]/g, \"\").trim();\n  if (!v || v.includes(\"\\\\\")) return \"#\";\n  if (/^(https?:|mailto:|tel:)/i.test(v)) return v;\n  if (/^[/#?]/.test(v) && !/^\\/\\//.test(v)) return v;\n  return \"#\";\n}\n\nfunction subscribeMotion(cb: () => void) {\n  const m = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n  m.addEventListener(\"change\", cb);\n  return () => m.removeEventListener(\"change\", cb);\n}\n\n/** True when the visitor asked for reduced motion. False on the server. */\nfunction useReducedMotion(): boolean {\n  return useSyncExternalStore(\n    subscribeMotion,\n    () => window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches,\n    () => false,\n  );\n}\n\n/**\n * The rule, \"The Third\": in a run of `count` modules, module `index` (from 0)\n * breaks when it is every `every`th (3, 6, 9...) and is neither end of the run.\n * Use it for your own runs, so the break is computed and never placed by hand.\n */\nexport function bgBreaks(index: number, count: number, every = 3): boolean {\n  if (every < 2 || index <= 0 || index >= count - 1) return false;\n  return (index + 1) % every === 0;\n}\n\n/**\n * The CSS half of the lattice: `.bg-grid` lays children on the same columns\n * as bgGrid (4 on a phone, 12 from 48rem, the same step as Tailwind's @3xl),\n * and sets --bg-g (the gutter) for the overshoots.\n */\nconst GRID_CSS =\n  \".bg-grid{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));column-gap:8px;padding-inline:24px;--bg-g:8px}\" +\n  \"@container (min-width:48rem){.bg-grid{grid-template-columns:repeat(12,minmax(0,1fr));column-gap:1.875cqw;padding-inline:calc(3.75cqw + 8px);--bg-g:1.875cqw}}\";\n\n// Each part carries only the CSS it needs, so any one of them works on its own.\n// revert-layer keeps an element's own corners when a host page's focus rule rounds or flattens them.\nconst FOCUS_CSS = \".bg-scope :focus-visible,.bg-scope:focus-visible{outline:2px solid var(--bg-ring,#e2ff3a)!important;outline-offset:3px;border-radius:revert-layer}\";\n\n/**\n * The bracket a module wears when the rule breaks it: an L of 2px, one gutter\n * long, 6px outside its leading corner, so it reads against the ground. Its\n * colour is --bg-mark (acid on the field, ink on paper; see bgMark).\n */\nfunction BgBracket({ on, size = 24, className = \"\" }: { on: boolean; size?: number; className?: string }) {\n  const reduced = useReducedMotion();\n  return (\n    <span\n      aria-hidden\n      className={\"pointer-events-none absolute left-0 top-0 block \" + className}\n      style={{\n        width: size,\n        height: size,\n        borderTop: `2px solid var(--bg-mark, ${FIELD.acid})`,\n        borderLeft: `2px solid var(--bg-mark, ${FIELD.acid})`,\n        transform: \"translate(-6px, -6px)\",\n        opacity: on ? 1 : 0,\n        transition: reduced ? \"none\" : `opacity ${BG_HANDOFF_MS}ms ${BG_EASE}`,\n      }}\n    />\n  );\n}\n\nexport type BgLink = { label: string; href: string };\n\n/**\n * IndexStepNav — a numbered nav whose third item hangs below the bar, and an\n * active tag that steps rather than glides.\n *\n * Every item carries its number. The items are a run, so by the rule the\n * third (and sixth, and so on, never the last) hangs one gutter below the bar\n * on a contrasting plate with the bracket, and the bar's hairline dips to\n * pass under it and comes back up. The current item is marked by a small tag\n * that steps to it in four ticks over 320ms, like a counter turning, never a\n * glide; point at (or focus) another item and the tag steps over to it, and\n * back when you leave. From 48rem an email item copies the address and says\n * so. Arrow keys, Home and End move between items; the current one is marked\n * for screen readers. Field blue (acid marks) or paper (ink marks). Pass\n * active={-1} while no section is current.\n */\nexport function IndexStepNav({\n  brand = \"Overshoot\",\n  brandHref = \"#\",\n  items = [\n    { label: \"Work\", href: \"#work\" },\n    { label: \"Studio\", href: \"#studio\" },\n    { label: \"The rule\", href: \"#rule\" },\n    { label: \"Journal\", href: \"#journal\" },\n  ],\n  defaultActive = 0,\n  active: activeProp,\n  onChange,\n  email = \"\",\n  tone = \"field\",\n  every = 3,\n  className = \"\",\n  style,\n}: {\n  brand?: string;\n  brandHref?: string;\n  items?: BgLink[];\n  defaultActive?: number;\n  /** Controlled: which item is current, or -1 for none. */\n  active?: number;\n  onChange?: (index: number) => void;\n  /** An address to copy; empty for none. */\n  email?: string;\n  tone?: \"field\" | \"paper\";\n  every?: number;\n  className?: string;\n  style?: CSSProperties;\n}) {\n  const [own, setOwn] = useState(defaultActive);\n  const active = clamp(activeProp ?? own, -1, items.length - 1);\n  const [point, setPoint] = useState(-1);\n  const barRef = useRef<HTMLDivElement>(null);\n  const refs = useRef<(HTMLAnchorElement | null)[]>([]);\n  // Each item's left, right and top in the bar (a hanging item's top includes its hang); the bar's size.\n  const [geo, setGeo] = useState<{ w: number; h: number; at: [number, number, number][] }>({ w: 0, h: 64, at: [] });\n  const [copied, setCopied] = useState<\"\" | \"ok\" | \"no\">(\"\");\n  const reduced = useReducedMotion();\n  const onField = tone === \"field\";\n  const ink = onField ? FIELD.paper : FIELD.ink;\n  const dim = onField ? FIELD.onField3 : FIELD.ink3;\n  const line = onField ? \"rgba(241,240,232,0.34)\" : \"rgba(10,10,31,0.22)\";\n  // The hanging plate contrasts with the bar: paper on the field, field blue on paper.\n  const plate = onField ? { bg: FIELD.paper, fg: FIELD.ink, num: FIELD.ink3 } : { bg: FIELD.field, fg: FIELD.paper, num: FIELD.onField3 };\n  const hangs = items.map((_, i) => bgBreaks(i, items.length, every));\n  const hangKey = hangs.map((b) => (b ? 1 : 0)).join(\"\");\n\n  // Measure every item (the tag goes to whichever is current or pointed at; the hairline dips under each hanging one).\n  useEffect(() => {\n    const bar = barRef.current;\n    if (!bar) return;\n    let alive = true;\n    const measure = () => {\n      const br = bar.getBoundingClientRect();\n      const k = bar.offsetWidth ? br.width / bar.offsetWidth : 1;\n      const at = refs.current.slice(0, items.length).map((el): [number, number, number] => {\n        if (!el) return [0, 0, 0];\n        const r = el.getBoundingClientRect();\n        return [(r.left - br.left) / k, (r.right - br.left) / k, (r.top - br.top) / k];\n      });\n      setGeo((g) => (g.w === bar.clientWidth && g.h === bar.clientHeight && JSON.stringify(g.at) === JSON.stringify(at) ? g : { w: bar.clientWidth, h: bar.clientHeight, at }));\n    };\n    measure();\n    const ro = new ResizeObserver(measure);\n    ro.observe(bar);\n    refs.current.forEach((el) => el && ro.observe(el));\n    // A web font arriving changes the items' widths without changing the bar's.\n    document.fonts?.ready.then(() => alive && measure());\n    return () => {\n      alive = false;\n      ro.disconnect();\n    };\n  }, [items.length, hangKey]);\n  useEffect(() => {\n    if (!copied) return;\n    const id = window.setTimeout(() => setCopied(\"\"), 1600);\n    return () => window.clearTimeout(id);\n  }, [copied]);\n\n  const choose = (i: number) => {\n    if (activeProp === undefined) setOwn(i);\n    onChange?.(i);\n  };\n  const onKey = (e: ReactKeyboardEvent<HTMLAnchorElement>, i: number) => {\n    const n = items.length;\n    const next = e.key === \"ArrowRight\" ? (i + 1) % n : e.key === \"ArrowLeft\" ? (i - 1 + n) % n : e.key === \"Home\" ? 0 : e.key === \"End\" ? n - 1 : -1;\n    if (next < 0) return;\n    e.preventDefault();\n    refs.current[next]?.focus();\n  };\n  const copy = async () => {\n    try {\n      await navigator.clipboard.writeText(email);\n      setCopied(\"ok\");\n    } catch {\n      setCopied(\"no\");\n    }\n  };\n  // The hairline: straight, dipping 8px under each hanging item (which covers it) and back.\n  const { w, h } = geo;\n  let d = `M0 ${h - 0.5}`;\n  geo.at.forEach(([l, r], i) => {\n    if (!hangs[i]) return;\n    d += ` L${l - 24} ${h - 0.5} C${l - 12} ${h - 0.5} ${l - 12} ${h + 7.5} ${l} ${h + 7.5} L${r} ${h + 7.5} C${r + 12} ${h + 7.5} ${r + 12} ${h - 0.5} ${r + 24} ${h - 0.5}`;\n  });\n  d += ` L${w} ${h - 0.5}`;\n  // The tag: on the item pointed at, else the current one; hidden when neither.\n  const shown = point >= 0 ? point : active;\n  const spot = shown >= 0 ? geo.at[shown] : undefined;\n  const tagY = spot ? spot[2] + 4 : 0;\n\n  return (\n    <nav aria-label=\"Main\" className={\"bg-scope relative w-full @container \" + className} style={{ background: onField ? FIELD.field : FIELD.paper, color: ink, fontFamily: SANS, ...bgMark(tone), ...style }}>\n      <style>{FOCUS_CSS + GRID_CSS}</style>\n      <div ref={barRef} className=\"bg-grid relative min-h-16 items-center gap-y-1 py-2 @3xl:py-0\">\n        <a href={safeHref(brandHref)} className=\"col-span-2 text-[22px] leading-none no-underline @3xl:col-span-3\" style={{ fontFamily: DISPLAY, fontWeight: 800, textTransform: \"uppercase\", letterSpacing: \"0.01em\", color: ink }}>\n          {brand}\n        </a>\n        <div className=\"relative order-last col-span-full flex min-h-12 flex-wrap items-center gap-x-5 gap-y-1 @3xl:order-none @3xl:col-span-6 @3xl:h-16 @3xl:flex-nowrap @3xl:gap-7\" onPointerLeave={() => setPoint(-1)}>\n          {items.map((it, i) => {\n            const hang = hangs[i];\n            return (\n              <a\n                key={it.label}\n                ref={(el) => void (refs.current[i] = el)}\n                href={safeHref(it.href)}\n                aria-current={i === active ? (it.href.startsWith(\"#\") ? \"location\" : \"page\") : undefined}\n                onClick={() => choose(i)}\n                onKeyDown={(e) => onKey(e, i)}\n                onPointerEnter={() => setPoint(i)}\n                onFocus={() => setPoint(i)}\n                onBlur={() => setPoint(-1)}\n                className=\"relative flex shrink-0 items-baseline gap-1.5 whitespace-nowrap no-underline\"\n                style={{ color: hang ? plate.fg : ink, padding: hang ? \"10px 12px\" : \"10px 0\", transform: hang ? \"translateY(var(--bg-g, 24px))\" : undefined, background: hang ? plate.bg : \"transparent\", zIndex: hang ? 2 : 1 }}\n              >\n                {hang ? <BgBracket on size={14} /> : null}\n                <span className=\"text-[11px]\" style={{ fontFamily: MONO, letterSpacing: \"0.08em\", color: hang ? plate.num : dim }}>\n                  {String(i + 1).padStart(2, \"0\")}\n                </span>\n                <span className=\"text-[19px] leading-none\" style={{ fontFamily: DISPLAY, fontWeight: 800, textTransform: \"uppercase\", letterSpacing: \"0.02em\" }}>\n                  {it.label}\n                </span>\n              </a>\n            );\n          })}\n        </div>\n        {email ? (\n          <div className=\"col-span-full hidden justify-end @3xl:col-span-3 @3xl:flex\">\n            <button type=\"button\" onClick={copy} className=\"text-[11px] uppercase\" style={{ fontFamily: MONO, letterSpacing: \"0.08em\", color: copied === \"ok\" ? (onField ? FIELD.ink : FIELD.paper) : ink, background: copied === \"ok\" ? (onField ? FIELD.acid : FIELD.ink) : \"transparent\", padding: \"6px 8px\", boxShadow: `inset 0 0 0 1px ${copied === \"ok\" ? \"transparent\" : line}` }}>\n              {copied === \"ok\" ? \"Copied\" : copied === \"no\" ? \"Copy failed\" : email}\n            </button>\n          </div>\n        ) : null}\n        {/* The tag: a 10px square in the mark colour that steps to the item in four ticks (no transition until first measured). */}\n        <span\n          aria-hidden\n          className=\"pointer-events-none absolute left-0 top-0 block h-2.5 w-2.5\"\n          style={{\n            background: `var(--bg-mark, ${FIELD.acid})`,\n            opacity: spot ? 1 : 0,\n            transform: `translate(${Math.round((spot?.[0] ?? 0) - 16)}px, ${Math.round(tagY + 8)}px)`,\n            transition: reduced || !geo.w ? \"none\" : `transform 320ms steps(4, end), opacity ${BG_HANDOFF_MS}ms`,\n          }}\n        />\n        <svg aria-hidden className=\"pointer-events-none absolute left-0 top-0 overflow-visible\" width={w || 1} height={h + 12}>\n          <path d={d} fill=\"none\" stroke={line} strokeWidth={1} />\n        </svg>\n        <p aria-live=\"polite\" className=\"sr-only\">\n          {copied === \"ok\" ? `Copied ${email}` : copied === \"no\" ? \"Couldn't copy the address\" : \"\"}\n        </p>\n      </div>\n    </nav>\n  );\n}\n","type":"registry:component","target":"components/viberdy/index-step-nav.tsx"}],"meta":{"tier":"free","tags":["navigation","navbar","numbered","broken grid","copy email","steps"],"href":"https://viberdy.dev/library/index-step-nav","aiPrompt":"Build a React + Tailwind nav, `IndexStepNav({ brand, brandHref, items, defaultActive, active, onChange, email, tone, every, className, style })`.\n\nBroken Grid grammar: a visible grid that holds, and one rule that breaks it the same way everywhere. A Klein-blue field #2416f0 as the ground (raised #3a2ff5, pressed #1a0ec4), paper plates #f1f0e8, blue-black ink #0a0a1f; secondary and tertiary text at 72/60% ink on paper and 86/76% paper on the field (all 4.5:1 or better), input boundaries at 50% ink (3:1). The mark means one thing, a rule firing or the current state (the bracket on a breaking module, an index tag, a selected chip): acid #e2ff3a on the field, ink on paper, where acid would vanish; never a wash, a gradient or text on paper. The lattice: twelve columns from a 48rem container (gutter 1.875%, 24px at 1280), four on a phone (8px gutters); the margin is two gutters and 8px (56px at 1280, 24px on a phone), so a breaker in the first column runs into the margin with its bracket still on the page; rows square with the columns; hairlines through the gutter centres (paper at 22% on the field), small crosses where they meet; drawn in full only at the anchors (hero, footer), elsewhere as column ticks. THE RULE, \"The Third\": in every run of modules, module 3, 6, 9... (never the first or the last) overshoots its leading edge by two gutters, one closing the gap and one overlapping its neighbour, rides one layer above it, wears the bracket (a 2px L one gutter long, 6px outside its leading corner, read against the ground) and gets a firmer leading edge (half-strength text colour) so the overlap reads as two plates; its padding grows by the same so its content never moves, and the module it overlaps keeps a gutter of trailing padding clear. Type follows the same law with one column pitch as the unit. The break belongs to the position: reorder a run and the break passes to whichever module is now third; compute it, never place it. Radius 0, no shadows, no grain; depth is overlap and a 1px hairline (inset box-shadow, never a border). Type: Big Shoulders at 800 in capitals through var(--font-big-shoulders, \"Big Shoulders\", ...) for display (up to 164px, leading 0.84-0.86), Geist Mono 11px uppercase +0.08em for labels (never smaller), Geist 16-17px/1.5 for reading. Motion: layouts change in 380ms on cubic-bezier(.2,.8,.2,1), all at once, no stagger, no spring, no overshoot (the layout overshoots, the motion never does); a role hand-off (breaking or letting go) takes 240ms; a drag follows 1:1 and snaps in 320ms; controls press in 120ms, release in 200ms, labels step in 160ms; tags step (steps(4)), never glide; scroll only ever changes a layout at checkpoints (never a continuous scrub); no ambient loops; reduced motion makes every change instant.\n\nA 12-column bar (min-height 64px): the brand in Big Shoulders 800 caps (columns 1-3), the items (columns 4-9) as links with a mono number and a caps label, and, if `email` is set, an email button (columns 10-12, from 48rem) that writes the address to the clipboard and shows Copied or Copy failed for 1.6s. Items at the rule's positions (bgBreaks over the items) hang by translateY(var(--bg-g)) on a contrasting plate (paper on the field, field blue on paper) with the bracket. An SVG path draws the bar's bottom hairline, dipping 8px on short curves just before and after each hanging item (which covers it). The tag is a 10px square in the mark colour at the left of the item pointed at (or else the current one), moved with transition: transform 320ms steps(4, end), hidden when none is current; every item is measured (a ResizeObserver on the bar and each item, and again when the fonts are ready). On a phone the items wrap below the brand (no horizontal scroller, which would clip the hanging plate).","license":"https://viberdy.dev/license"}}