{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "navbar-menu",
  "type": "registry:block",
  "title": "Navbar, menu panels",
  "description": "Brand, up to four link groups that open a panel of described links, and one call to action. Panels become sections of the mobile menu.",
  "categories": [
    "navbar"
  ],
  "dependencies": [
    "lucide-react@^1.49.0",
    "zod@^4.6.5"
  ],
  "registryDependencies": [
    "https://ui.klarhimmel.com/r/block-kit.json",
    "https://ui.klarhimmel.com/r/button.json",
    "https://ui.klarhimmel.com/r/editing.json",
    "https://ui.klarhimmel.com/r/kit-d-chrome.json",
    "https://ui.klarhimmel.com/r/utils.json"
  ],
  "files": [
    {
      "path": "src/blocks/navbar-menu/spec.ts",
      "type": "registry:file",
      "target": "components/klarhimmel/blocks/navbar-menu/spec.ts",
      "content": "import { z } from 'zod';\nimport { defineSpec, link, t, req, wordmark } from '../_shared/schema';\n\nconst item = z.object({ label: t(40), description: t(100), href: t(300) });\nconst group = z.object({ label: t(24), links: z.array(item).min(1).max(6) });\n\nconst schema = z.object({\n  brand: req(40),\n  /** Their logo in place of the brand name; the name stays for screen readers. Not drawn without a src. */\n  wordmark,\n  /** Brand link target; default \"/\". */\n  brandHref: t(300).optional(),\n  groups: z.array(group).min(1).max(4),\n  cta: link,\n});\n\nexport const spec = defineSpec({\n  type: 'navbar-menu',\n  aliases: ['navigation/menu', 'header/menu'],\n  name: 'Navbar, menu panels',\n  category: 'navbar',\n  role: 'nav',\n  description: 'Brand, up to four link groups that open a panel of described links, and one call to action. Panels become sections of the mobile menu.',\n  schema,\n  defaults: {\n    brand: 'Brand name',\n    groups: [\n      {\n        label: 'First group',\n        links: [\n          { label: 'First page', description: 'Say what the first page is for.', href: '#planning' },\n          { label: 'Second page', description: 'Say what the second page is for.', href: '#reviews' },\n          { label: 'Third page', description: 'Say what the third page is for.', href: '#workload' },\n          { label: 'Fourth page', description: 'Say what the fourth page is for.', href: '#integrations' },\n        ],\n      },\n      {\n        label: 'Second group',\n        links: [\n          { label: 'First page', description: 'Say what the first page is for.', href: '#guides' },\n          { label: 'Second page', description: 'Say what the second page is for.', href: '#docs' },\n          { label: 'Third page', description: 'Say what the page holds.', href: '#changelog' },\n        ],\n      },\n      {\n        label: 'Third group',\n        links: [\n          { label: 'First page', description: 'Say what the first page is for.', href: '#about' },\n          { label: 'Second page', description: 'Say what the second page is for.', href: '#careers' },\n        ],\n      },\n    ],\n    cta: { label: 'Main action', href: '#start' },\n  },\n});\n"
    },
    {
      "path": "src/blocks/navbar-menu/index.tsx",
      "type": "registry:file",
      "target": "components/klarhimmel/blocks/navbar-menu/index.tsx",
      "content": "import { useEffect, useId, useRef, useState } from 'react';\nimport { ChevronDown } from 'lucide-react';\nimport { Text, withHeadingLevel } from '../../editing';\nimport { safeHref } from '../../ui/button';\nimport { ActionLink, brandName, Container, useEditing, Gate, Named } from '../_shared/kit';\nimport { FOCUS, MenuDetails, useMenu } from '../_shared/d-chrome-kit';\nimport { cn } from '../../lib/utils';\nimport { spec } from './spec';\nimport type { BlockProps } from '../types';\nimport type { z } from 'zod';\n\nexport { spec };\ntype Props = z.infer<typeof spec.schema>;\n\nfunction NavbarMenu({ props }: BlockProps<Props>) {\n  const { shown, setOpen, menuId, summaryRef, detailsRef, rootRef, rootProps } = useMenu();\n  const editing = useEditing();\n  const [group, setGroup] = useState<number | null>(null);\n  const base = useId();\n  const triggers = useRef<(HTMLElement | null)[]>([]);\n\n  useEffect(() => {\n    if (group === null) return;\n    const away = (e: PointerEvent) => {\n      if (rootRef.current && !rootRef.current.contains(e.target as Node)) setGroup(null);\n    };\n    const esc = (e: KeyboardEvent) => {\n      if (e.key !== 'Escape') return;\n      const t = triggers.current[group];\n      setGroup(null);\n      if (t && t.offsetParent !== null) t.focus();\n    };\n    document.addEventListener('pointerdown', away);\n    document.addEventListener('keydown', esc);\n    return () => {\n      document.removeEventListener('pointerdown', away);\n      document.removeEventListener('keydown', esc);\n    };\n  }, [group, rootRef]);\n\n  const onBlur = (e: React.FocusEvent) => {\n    rootProps.onBlur(e);\n    const next = e.relatedTarget as Node | null;\n    if (group !== null && next && rootRef.current && !rootRef.current.contains(next)) setGroup(null);\n  };\n\n  return (\n    <header ref={rootRef} onBlur={onBlur} className=\"relative border-b border-kh-line bg-kh-canvas\">\n      <Container className=\"flex min-h-16 flex-wrap items-center gap-2 py-2 @4xl:flex-nowrap\">\n        <Named as=\"a\" href={safeHref(props.brandHref ?? '/')} className={cn('mr-auto max-w-full shrink-0 [overflow-wrap:anywhere] rounded-kh-sm text-kh-heading font-semibold tracking-tight text-kh-ink @4xl:mr-4', FOCUS)}>\n          {brandName({ brand: props.brand, wordmark: props.wordmark })}\n        </Named>\n        <ActionLink path={['cta']} value={props.cta} size=\"md\" className=\"@4xl:order-2\" />\n        <MenuDetails shown={shown} onToggle={setOpen} summaryRef={summaryRef} detailsRef={detailsRef} className=\"@4xl:hidden\" detailsClass={cn('@4xl:order-1 @4xl:flex @4xl:flex-1 @4xl:details-content:contents @4xl:details-content:content-visible', editing && 'order-last basis-full')}>\n        <nav\n          id={menuId}\n          aria-label=\"Main\"\n          className={cn(\n            'flex flex-col border-b border-kh-line bg-kh-canvas pb-4 pt-1',\n            editing ? 'order-last basis-full' : 'absolute inset-x-0 top-full z-10 max-h-[calc(100dvh-4rem)] overflow-y-auto px-kh-gutter',\n            '@4xl:static @4xl:order-1 @4xl:flex @4xl:max-h-none @4xl:flex-1 @4xl:flex-row @4xl:overflow-visible @4xl:border-0 @4xl:bg-transparent @4xl:p-0',\n          )}\n        >\n          <ul className=\"flex flex-col @4xl:flex-row @4xl:gap-1\">\n            {props.groups.map((g, i) => {\n              const isOpen = editing || group === i;\n              const panelId = `${base}-${i}`;\n              return (\n                <li key={i} className=\"border-b border-kh-line last:border-0 @4xl:border-0\">\n                  <details open={isOpen} name={editing ? undefined : base} onToggle={(e) => { const o = e.currentTarget.open; setGroup((g) => (o ? i : g === i ? null : g)); }} className=\"group/sub\">\n                  <summary\n                    ref={(el) => { triggers.current[i] = el; }}\n                    className={cn(\n                      'cursor-pointer list-none [&::-webkit-details-marker]:hidden',\n                      'inline-flex min-h-11 w-full items-center justify-between gap-1.5 rounded-kh px-0 text-kh-body font-medium text-kh-ink-2 transition-colors hover:text-kh-ink @4xl:w-auto @4xl:justify-start @4xl:px-3 @4xl:text-kh-small @4xl:hover:bg-kh-surface-2',\n                      isOpen && 'text-kh-ink',\n                      FOCUS,\n                    )}\n                  >\n                    <Text path={['groups', i, 'label']} value={g.label} as=\"span\" />\n                    <ChevronDown aria-hidden strokeWidth={1.75} className=\"size-4 text-kh-muted transition-transform group-open/sub:rotate-180\" />\n                  </summary>\n                  <div\n                    id={panelId}\n                    className={cn('pb-3 @4xl:pb-0', !editing && '@4xl:absolute @4xl:inset-x-0 @4xl:top-full @4xl:z-10 @4xl:border-b @4xl:border-kh-line @4xl:bg-kh-canvas @4xl:shadow-kh-2')}\n                  >\n                    <div className={cn(!editing && '@4xl:mx-auto @4xl:w-full @4xl:max-w-kh-page @4xl:px-kh-gutter @4xl:py-6')}>\n                      <ul className={cn('grid gap-1', !editing && '@4xl:grid-cols-2 @5xl:grid-cols-3')}>\n                        {g.links.map((l, j) => (\n                          <Gate key={j} label={l.label}>\n                          <li>\n                            <a\n                              href={safeHref(l.href)}\n                              onClick={() => { setGroup(null); setOpen(false); }}\n                              className={cn('block rounded-kh px-3 py-2.5 transition-colors hover:bg-kh-surface-2 @4xl:p-3', 'focus-visible:outline-2 focus-visible:outline-(--kh-focus)')}\n                            >\n                              <Text path={['groups', i, 'links', j, 'label']} value={l.label} as=\"span\" className=\"block text-kh-small font-medium text-kh-ink\" />\n                              <Text path={['groups', i, 'links', j, 'description']} value={l.description} as=\"span\" className=\"mt-0.5 block text-kh-small text-kh-muted\" />\n                            </a>\n                          </li>\n                          </Gate>\n                        ))}\n                      </ul>\n                    </div>\n                  </div>\n                  </details>\n                </li>\n              );\n            })}\n          </ul>\n        </nav>\n        </MenuDetails>\n      </Container>\n    </header>\n  );\n}\n\nexport default withHeadingLevel(NavbarMenu);\n"
    }
  ]
}
