{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "menubar",
  "title": "Menubar",
  "description": "A frame row of words on a hairline; opening a word folds the line down into a pocket that holds its menu.",
  "dependencies": [
    "@radix-ui/react-menubar"
  ],
  "registryDependencies": [
    "https://thedirectors.agency/ui/r/0nlytype.json",
    "https://thedirectors.agency/ui/r/dropdown-menu.json",
    "https://thedirectors.agency/ui/r/popover.json"
  ],
  "files": [
    {
      "path": "registry/0nlytype/ui/menubar.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport * as MenuPrimitive from \"@radix-ui/react-menubar\"\n\nimport { useComposedRefs } from \"@/lib/0nlytype/refs\"\nimport { cn } from \"@/lib/utils\"\nimport { DropdownMenuShortcut, MenuLook, useSubmenuPlace } from \"@/components/ui/dropdown-menu\"\n\ntype MenubarVariant = \"pocket\" | \"leaders\" | \"caption\"\nconst Look = React.createContext<MenubarVariant>(\"pocket\")\n\n/** An item's own words, without its shortcut keys or a submenu's arrow. */\nconst words = (el: HTMLElement) =>\n  [...el.childNodes].filter((n) => n.nodeType === Node.TEXT_NODE).map((n) => n.textContent).join(\"\").trim() || (el.textContent ?? \"\").trim()\n\n/** Where focus is, as the words that lead there: the bar's word, any submenus, then the item. */\nfunction pathTo(el: HTMLElement) {\n  const path: string[] = []\n  for (let at: HTMLElement | null = el; at; ) {\n    path.unshift(words(at))\n    if (at.dataset.slot === \"menubar-trigger\") break\n    at = document.getElementById(at.closest(\"[role='menu']\")?.getAttribute(\"aria-labelledby\") ?? \"\")\n  }\n  return path\n}\n\n/**\n * A row of words on a hairline. Opening a word opens the hairline under it into a pocket:\n * the line folds down around the menu and back up. Down opens, Left and Right move between menus.\n *\n * `variant`: `pocket` (the default), `leaders` (every menu is a contents page, the dropdown\n * menu's leaders) or `caption`, after the SHAPES / GRADIENTS rule that carries a name at its\n * far end and the old status line: the rule's far end carries the bar's name at rest, and the\n * path to what focus is on as you move (\"File / Export / As PDF\"). The caption is aria-hidden;\n * the menus already say where you are.\n */\nfunction Menubar({ className, dir, ref, variant = \"pocket\", children, onFocus, onBlur, ...props }: React.ComponentProps<typeof MenuPrimitive.Root> & { variant?: MenubarVariant }) {\n  // Radix reads direction from its own provider, not the page, so a right-to-left page would get\n  // left-to-right menus and arrow keys the wrong way round. Without a dir, the bar takes the\n  // direction of the page around it, read as it mounts (as the toggle group does).\n  const [around, setAround] = React.useState<\"rtl\">()\n  const [path, setPath] = React.useState<string[] | null>(null)\n  const caption = variant === \"caption\"\n  const rest = props[\"aria-label\"]\n  const composedRef = useComposedRefs(React.useCallback((node: HTMLDivElement | null) => {\n    const up = node?.parentElement\n    if (!dir && up && getComputedStyle(up).direction === \"rtl\") setAround(\"rtl\")\n  }, [dir]), ref)\n  return (\n    <MenuPrimitive.Root\n      ref={composedRef}\n      data-slot=\"menubar\"\n      data-variant={variant}\n      dir={dir ?? around}\n      className={cn(\"ot-menubar\", className)}\n      // Focus in the menus bubbles here through React, from their portals too.\n      onFocus={(event) => {\n        onFocus?.(event)\n        const at = (event.target as HTMLElement).closest<HTMLElement>(\"[role^='menuitem']\") // not a menu's own box\n        if (caption && at) setPath(pathTo(at))\n      }}\n      onBlur={(event) => {\n        onBlur?.(event)\n        const to = event.relatedTarget as HTMLElement | null\n        if (caption && !to?.closest(\"[data-slot='menubar'], [role='menu']\")) setPath(null)\n      }}\n      {...props}\n    >\n      <Look.Provider value={variant}>{children}</Look.Provider>\n      {caption ? (\n        <span className=\"ot-menubar-caption\" aria-hidden data-rest={path ? undefined : \"\"}>\n          {(path ?? (rest ? [rest] : [])).map((w, i) => (\n            <span key={`${i}-${w}`}>{w}</span>\n          ))}\n        </span>\n      ) : null}\n    </MenuPrimitive.Root>\n  )\n}\n\nfunction MenubarMenu(props: React.ComponentProps<typeof MenuPrimitive.Menu>) {\n  return <MenuPrimitive.Menu {...props} />\n}\n\nfunction MenubarTrigger({ className, ...props }: React.ComponentProps<typeof MenuPrimitive.Trigger>) {\n  return <MenuPrimitive.Trigger data-slot=\"menubar-trigger\" className={cn(\"ot-menubar-trigger\", className)} {...props} />\n}\n\nfunction MenubarGroup(props: React.ComponentProps<typeof MenuPrimitive.Group>) {\n  return <MenuPrimitive.Group data-slot=\"menubar-group\" {...props} />\n}\n\nfunction MenubarRadioGroup(props: React.ComponentProps<typeof MenuPrimitive.RadioGroup>) {\n  return <MenuPrimitive.RadioGroup data-slot=\"menubar-radio-group\" {...props} />\n}\n\nfunction MenubarSub(props: React.ComponentProps<typeof MenuPrimitive.Sub>) {\n  return <MenuPrimitive.Sub data-slot=\"menubar-sub\" {...props} />\n}\n\n/**\n * The dropdown menu's list of words, hung in the bar's own hairline: the panel rises just\n * over the rule (a sideOffset of minus one and a half pixels, since the word reaches down to\n * the rule), its paper hides the rule there, and its sides and foot carry the line on. So\n * the menu needs no leader. Its words start under the word that opened it; the bar sits its\n * words in from the rule's ends by the same inset, so even the first menu folds from the rule.\n */\nfunction MenubarContent({\n  className,\n  align = \"start\",\n  sideOffset = -1.5, /* over the rule by more than its width, whatever pixel it rounds to */\n  alignOffset = -27, /* --ot-space-5, the items' inset: their words line up under the word */\n  collisionPadding = 20,\n  ref,\n  onFocusOutside,\n  children,\n  ...props\n}: React.ComponentProps<typeof MenuPrimitive.Content>) {\n  const look = React.useContext(Look) === \"leaders\" ? \"leaders\" : \"list\"\n  const node = React.useRef<HTMLDivElement>(null)\n  const composedRef = useComposedRefs(node, ref)\n  return (\n    <MenuPrimitive.Portal>\n      <MenuPrimitive.Content\n        ref={composedRef}\n        data-slot=\"menubar-content\"\n        data-variant={look}\n        align={align}\n        sideOffset={sideOffset}\n        alignOffset={alignOffset}\n        collisionPadding={collisionPadding}\n        className={cn(\"ot-pop ot-menu\", className)}\n        onFocusOutside={(event) => {\n          onFocusOutside?.(event)\n          // A menu still rolling up must not dismiss the next one: moving between menus\n          // focuses the new one while the old one's exit animation runs.\n          if (node.current?.dataset.state === \"closed\") event.preventDefault()\n        }}\n        {...props}\n      >\n        <MenuLook.Provider value={look}>{children}</MenuLook.Provider>\n      </MenuPrimitive.Content>\n    </MenuPrimitive.Portal>\n  )\n}\n\n/** A destructive item says so in its words (\"Delete Halden for good\"); it is never red. */\nfunction MenubarItem({\n  className,\n  variant = \"default\",\n  ...props\n}: React.ComponentProps<typeof MenuPrimitive.Item> & { variant?: \"default\" | \"destructive\" }) {\n  return <MenuPrimitive.Item data-slot=\"menubar-item\" data-variant={variant} className={cn(\"ot-menu-item\", className)} {...props} />\n}\n\n/** Checked, the sentence turns to the expression italic. Screen readers get aria-checked. */\nfunction MenubarCheckboxItem({ className, ...props }: React.ComponentProps<typeof MenuPrimitive.CheckboxItem>) {\n  return <MenuPrimitive.CheckboxItem data-slot=\"menubar-checkbox-item\" className={cn(\"ot-menu-item\", className)} {...props} />\n}\n\nfunction MenubarRadioItem({ className, ...props }: React.ComponentProps<typeof MenuPrimitive.RadioItem>) {\n  return <MenuPrimitive.RadioItem data-slot=\"menubar-radio-item\" className={cn(\"ot-menu-item\", className)} {...props} />\n}\n\nfunction MenubarLabel({ className, ...props }: React.ComponentProps<typeof MenuPrimitive.Label>) {\n  return <MenuPrimitive.Label data-slot=\"menubar-label\" className={cn(\"ot-menu-label\", className)} {...props} />\n}\n\nfunction MenubarSeparator({ className, ...props }: React.ComponentProps<typeof MenuPrimitive.Separator>) {\n  return <MenuPrimitive.Separator data-slot=\"menubar-separator\" className={cn(\"ot-menu-sep\", className)} {...props} />\n}\n\n/** Shortcut keys, each a base `ot-kbd` cap; it is the dropdown menu's, under this slot. */\nfunction MenubarShortcut(props: React.ComponentProps<typeof DropdownMenuShortcut>) {\n  return <DropdownMenuShortcut data-slot=\"menubar-shortcut\" {...props} />\n}\n\n/** Opens something, so it carries the one → glyph. */\nfunction MenubarSubTrigger({ className, ...props }: React.ComponentProps<typeof MenuPrimitive.SubTrigger>) {\n  return <MenuPrimitive.SubTrigger data-slot=\"menubar-sub-trigger\" className={cn(\"ot-menu-item ot-menu-sub\", className)} {...props} />\n}\n\n/** Beside its item, or on a narrow screen dropped open under it (the dropdown menu's useSubmenuPlace). */\nfunction MenubarSubContent({ className, ref, sideOffset, alignOffset, collisionPadding, style, ...props }: React.ComponentProps<typeof MenuPrimitive.SubContent>) {\n  const place = useSubmenuPlace({ ref, sideOffset, alignOffset, collisionPadding, style })\n  return (\n    <MenuPrimitive.Portal>\n      <MenuPrimitive.SubContent data-slot=\"menubar-sub-content\" className={cn(\"ot-pop ot-menu\", className)} {...props} {...place} />\n    </MenuPrimitive.Portal>\n  )\n}\n\nexport {\n  Menubar,\n  MenubarMenu,\n  MenubarTrigger,\n  MenubarContent,\n  MenubarGroup,\n  MenubarLabel,\n  MenubarItem,\n  MenubarCheckboxItem,\n  MenubarRadioGroup,\n  MenubarRadioItem,\n  MenubarSeparator,\n  MenubarShortcut,\n  MenubarSub,\n  MenubarSubTrigger,\n  MenubarSubContent,\n}\n",
      "type": "registry:ui"
    },
    {
      "path": "registry/0nlytype/styles/menubar.css",
      "content": "@layer components {\n  /* ── ot-menubar ── a frame row of words on a hairline; each opens a menu (ot-menu,\n     dropdown-menu.css, on the popover panel). Opening a word opens the hairline under it into\n     a pocket: the line folds down around the menu and back up. One line, no leader, no stroke.\n     The words sit in from the rule's ends by a menu's own inset, so every menu, the first one\n     too, folds from the rule with its words under the word. Radix moves between menus with\n     Left and Right. */\n  .ot-menubar { --ot-menubar-line: var(--ot-rule-strong); position: relative; display: flex; flex-wrap: wrap; column-gap: var(--ot-space-5); padding-inline: var(--ot-space-5); box-shadow: inset 0 calc(-1 * var(--ot-hairline)) 0 var(--ot-menubar-line); }\n  /* The word reaches down to the rule, so its menu can hang from the word's own edge. */\n  .ot-menubar-trigger {\n    appearance: none; border: 0; margin: 0; padding: 0 0 var(--ot-space-2); font: inherit; color: var(--ot-graphite); cursor: pointer; outline: 0;\n    background: linear-gradient(var(--ot-accent), var(--ot-accent)) no-repeat 0 calc(100% - var(--ot-hairline)) / 0% var(--ot-stroke);\n    transition: color var(--ot-allegro);\n  }\n  .ot-menubar-trigger:is(:hover, [data-state=\"open\"], [data-force~=\"hover\"]) { color: var(--ot-ink); }\n  /* Focus is the one accent: a stroke laid on the rule under the word. */\n  .ot-menubar-trigger:is(:focus-visible, [data-force~=\"focus\"]) { color: var(--ot-ink); background-size: 100% var(--ot-stroke); }\n  .ot-menubar-trigger:disabled { color: var(--ot-pencil); opacity: 0.55; cursor: not-allowed; }\n\n  /* The menu: its paper covers the rule where it hangs, and its sides and foot are the same\n     line, so the hairline runs in, down, along and back up. No dot, no leader. It unrolls down\n     out of the line and rolls back up into it; the words arrive in turn (dropdown-menu.css). */\n  .ot-pop.ot-menu[data-slot=\"menubar-content\"] {\n    --ot-menubar-line: var(--ot-rule-strong);\n    box-shadow: inset var(--ot-hairline) 0 0 var(--ot-menubar-line), inset calc(-1 * var(--ot-hairline)) 0 0 var(--ot-menubar-line), inset 0 calc(-1 * var(--ot-hairline)) 0 var(--ot-menubar-line);\n    animation: ot-menubar-unroll var(--ot-moderato) var(--ot-exhale);\n  }\n  .ot-pop.ot-menu[data-slot=\"menubar-content\"]::before, .ot-pop.ot-menu[data-slot=\"menubar-content\"]::after { display: none; }\n  .ot-pop.ot-menu[data-slot=\"menubar-content\"][data-state=\"closed\"] { animation: ot-menubar-roll-up var(--ot-allegro) var(--ot-breath) forwards; }\n  /* Without room below, Radix turns it above the words, where there's no line to hang in:\n     it stands clear of them in a whole frame and unrolls upward. */\n  .ot-pop.ot-menu[data-slot=\"menubar-content\"][data-side=\"top\"] { translate: 0 calc(-1 * var(--ot-space-2)); box-shadow: inset 0 0 0 var(--ot-hairline) var(--ot-menubar-line); animation-name: ot-menubar-unroll-up; }\n  .ot-pop.ot-menu[data-slot=\"menubar-content\"][data-side=\"top\"][data-state=\"closed\"] { animation-name: ot-menubar-roll-down; }\n  @keyframes ot-menubar-unroll { from { clip-path: inset(0 0 100% 0); } to { clip-path: inset(0); } }\n  @keyframes ot-menubar-roll-up { from { clip-path: inset(0); } to { clip-path: inset(0 0 100% 0); } }\n  @keyframes ot-menubar-unroll-up { from { clip-path: inset(100% 0 0 0); } to { clip-path: inset(0); } }\n  @keyframes ot-menubar-roll-down { from { clip-path: inset(0); } to { clip-path: inset(100% 0 0 0); } }\n\n  /* ── caption ── after the SHAPES / GRADIENTS rule that carries a name at its far end, and\n     the old status line: the bar's rule runs on to a small caption on its far end, on the\n     words' baseline. At rest it is the bar's own name, in pencil; as focus moves it is the path\n     to where you are (\"File / Export / As PDF\"), the last step inked and arriving. On a narrow\n     bar only the last step stands. */\n  .ot-menubar[data-variant=\"caption\"] { align-items: baseline; }\n  .ot-menubar-caption { display: flex; gap: 0.5em; min-width: 0; margin-inline-start: auto; overflow: hidden; white-space: nowrap; font-size: var(--ot-pp); line-height: var(--ot-pp-lh); color: var(--ot-pencil); }\n  .ot-menubar-caption > span + span::before { content: \"/\" / \"\"; margin-inline-end: 0.5em; color: var(--ot-rule-strong); }\n  .ot-menubar-caption:not([data-rest]) > span:last-child { color: var(--ot-ink); animation: ot-arrive var(--ot-moderato) var(--ot-exhale); }\n  @media (max-width: 40rem) {\n    .ot-menubar-caption > span:not(:last-child) { display: none; }\n    .ot-menubar-caption > span:last-child::before { display: none; }\n  }\n\n  @media (forced-colors: active) {\n    .ot-menubar { border-bottom: 1px solid CanvasText; }\n    .ot-menubar-trigger:focus-visible { outline: 2px solid Highlight; outline-offset: 2px; }\n    .ot-pop.ot-menu[data-slot=\"menubar-content\"] { border: 1px solid CanvasText; border-top: 0; }\n  }\n}\n",
      "type": "registry:file",
      "target": "styles/0nlytype/menubar.css"
    }
  ],
  "css": {
    "@import \"../styles/0nlytype/menubar.css\"": {}
  },
  "meta": {
    "movement": "IX",
    "underneath": "radix",
    "contract": "ot-menubar"
  },
  "type": "registry:ui"
}
