{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "menu",
  "title": "Menu",
  "description": "A key that opens a menu of actions, with checkable items, groups and a submenu.",
  "dependencies": [
    "@ui-sdk/core@0.1.0-beta.5",
    "@ui-sdk/react@0.1.0-beta.5",
    "lucide-react@1.73.0"
  ],
  "registryDependencies": [
    "https://www.cyberspec.dev/r/cyber.json",
    "https://www.cyberspec.dev/r/button.json"
  ],
  "files": [
    {
      "path": "registry/cyber/ui/menu.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { ariaKeyshortcuts, formatShortcut } from \"@ui-sdk/core\"\nimport {\n  Menu as SdkMenu,\n  MenuCheckboxItem,\n  MenuContent,\n  MenuGroup,\n  MenuGroupLabel,\n  MenuItem,\n  MenuItemIcon,\n  MenuItemIndicator,\n  MenuRadioGroup,\n  MenuRadioItem,\n  MenuSeparator,\n  MenuShortcut,\n  MenuSub,\n  MenuSubContent,\n  MenuSubTrigger,\n  MenuTrigger,\n} from \"@ui-sdk/react/menu\"\nimport { ChevronDown, ChevronRight } from \"lucide-react\"\nimport type { ButtonSize, ButtonTone } from \"@/registry/cyber/ui/button\"\nimport \"@/registry/cyber/ui/cyber/button.css\"\nimport \"@/registry/cyber/ui/cyber/menu.css\"\n\n// A menu, as data. The shape follows ui-sdk's own MenuData, with an icon on\n// actions and submenus, and `confirm` on anything a person should approve:\n//\n// - an action:       { value, label, icon?, shortcut?, disabled?, destructive?, confirm? }\n// - a rule:          { type: \"separator\" }\n// - a headed group:  { type: \"group\", label?, items }\n// - a checkbox:      { type: \"checkbox\", value, label, defaultChecked? }\n// - one of several:  { type: \"radio-group\", name, label?, defaultValue?, items }\n// - another level:   { type: \"submenu\", label, icon?, items }\ntype MenuEntry =\n  | {\n      type?: \"item\"\n      value: string\n      label: string\n      icon?: React.ReactNode\n      /** A hint like \"mod+c\": shown as ⌘C or Ctrl+C. The app owns the key handler. */\n      shortcut?: string\n      disabled?: boolean\n      /** Something that can't be taken back. Flagged in yellow, with a mark. */\n      destructive?: boolean\n      /** A sentence saying what it does. An agent has to ask a person before running it. */\n      confirm?: string\n      closeOnSelect?: boolean\n    }\n  | { type: \"separator\" }\n  | { type: \"group\"; label?: string; items: MenuEntry[] }\n  | { type: \"checkbox\"; value: string; label: string; checked?: boolean; defaultChecked?: boolean; disabled?: boolean }\n  | {\n      type: \"radio-group\"\n      name: string\n      label?: string\n      value?: string | null\n      defaultValue?: string | null\n      items: { value: string; label: string; disabled?: boolean }[]\n    }\n  | { type: \"submenu\"; label: string; icon?: React.ReactNode; disabled?: boolean; items: MenuEntry[] }\n\n// Whether any row at this level carries an icon or a check. If one does,\n// every row gets the same leading column, so their labels line up.\nconst hasGutter = (items: MenuEntry[]): boolean =>\n  items.some((entry) => {\n    if (entry.type === \"checkbox\" || entry.type === \"radio-group\") return true\n    if (entry.type === \"group\") return hasGutter(entry.items)\n    return entry.type !== \"separator\" && entry.icon != null\n  })\n\nfunction Lead({ icon, gutter }: { icon?: React.ReactNode; gutter: boolean }) {\n  if (icon != null) return <MenuItemIcon data-kit=\"menu-icon\">{icon}</MenuItemIcon>\n  return gutter ? <span data-kit=\"menu-icon\" aria-hidden /> : null\n}\n\n// The mark in a checkable row: a block that's hollow while off and solid\n// while on, like the switch's. A box for a checkbox, a diamond for a radio.\nfunction Mark({ shape }: { shape: \"box\" | \"diamond\" }) {\n  return (\n    <MenuItemIndicator data-kit=\"popup-indicator\" keepMounted>\n      <span data-kit=\"menu-mark\" data-shape={shape} aria-hidden />\n    </MenuItemIndicator>\n  )\n}\n\n// The rows of one level of a menu. Submenus render themselves the same way.\nfunction MenuEntries({ items, gutter = hasGutter(items) }: { items: MenuEntry[]; gutter?: boolean }) {\n  return items.map((entry, index) => {\n    switch (entry.type) {\n      case \"separator\":\n        return <MenuSeparator key={index} data-kit=\"popup-separator\" />\n      case \"group\":\n        return (\n          <MenuGroup key={index} data-kit=\"menu-group\">\n            {entry.label && <MenuGroupLabel data-kit=\"popup-label\">{entry.label}</MenuGroupLabel>}\n            <MenuEntries items={entry.items} gutter={gutter} />\n          </MenuGroup>\n        )\n      case \"checkbox\":\n        return (\n          <MenuCheckboxItem\n            key={index}\n            data-kit=\"popup-item\"\n            value={entry.value}\n            checked={entry.checked}\n            defaultChecked={entry.defaultChecked}\n            disabled={entry.disabled}\n          >\n            <Mark shape=\"box\" />\n            {entry.label}\n          </MenuCheckboxItem>\n        )\n      case \"radio-group\":\n        return (\n          <MenuRadioGroup key={index} data-kit=\"menu-group\" name={entry.name} value={entry.value} defaultValue={entry.defaultValue}>\n            {entry.label && <MenuGroupLabel data-kit=\"popup-label\">{entry.label}</MenuGroupLabel>}\n            {entry.items.map((option) => (\n              <MenuRadioItem key={option.value} data-kit=\"popup-item\" value={option.value} disabled={option.disabled}>\n                <Mark shape=\"diamond\" />\n                {option.label}\n              </MenuRadioItem>\n            ))}\n          </MenuRadioGroup>\n        )\n      case \"submenu\":\n        return (\n          <MenuSub key={index}>\n            <MenuSubTrigger data-kit=\"popup-item\" data-menu-row=\"sub\" disabled={entry.disabled}>\n              <Lead icon={entry.icon} gutter={gutter} />\n              {entry.label}\n              <ChevronRight data-kit=\"menu-more\" aria-hidden />\n            </MenuSubTrigger>\n            <MenuSubContent data-kit=\"popup\" data-frame=\"tr bl\" sideOffset={10}>\n              <MenuEntries items={entry.items} />\n            </MenuSubContent>\n          </MenuSub>\n        )\n      default:\n        // The SDK would print the shortcut itself; it's printed here so it\n        // can carry the shared popup-shortcut look. The hint is still\n        // announced, through aria-keyshortcuts.\n        return (\n          <MenuItem\n            key={index}\n            data-kit=\"popup-item\"\n            data-menu-row={entry.destructive ? \"destructive\" : undefined}\n            data-agent-confirm={entry.confirm}\n            value={entry.value}\n            disabled={entry.disabled}\n            destructive={entry.destructive}\n            closeOnSelect={entry.closeOnSelect}\n            aria-keyshortcuts={entry.shortcut ? ariaKeyshortcuts(entry.shortcut) : undefined}\n          >\n            <Lead icon={entry.icon} gutter={gutter} />\n            {entry.label}\n            {entry.shortcut && <MenuShortcut data-kit=\"popup-shortcut\">{formatShortcut(entry.shortcut)}</MenuShortcut>}\n          </MenuItem>\n        )\n    }\n  })\n}\n\n// The floating frame and its rows: what a Menu, a ContextMenu and each menu\n// of a Menubar open. It goes inside an SDK Menu, beside its trigger.\nfunction MenuPopup({\n  items,\n  ...props\n}: Omit<React.ComponentProps<typeof MenuContent>, \"children\"> & { items: MenuEntry[] }) {\n  return (\n    <MenuContent data-kit=\"popup\" data-frame=\"tr bl\" align=\"start\" sideOffset={6} {...props}>\n      <MenuEntries items={items} />\n    </MenuContent>\n  )\n}\n\n// A key that opens a list of actions and settings.\n//\n// - `label` is the key's text and its name. With `compact` the key shows\n//   only `icon`, and the label becomes its aria-label.\n// - `items` is the menu, as data (see MenuEntry).\n// - `onAction` runs for every action, with its value; `onCheckedChange` and\n//   `onValueChange` report checkboxes and radio groups, as on the SDK's Menu.\n//\n// Checkboxes and radios keep the menu open, so several can be set in one\n// visit. Shortcuts are hints: the app owns the keys.\nfunction Menu({\n  label,\n  items,\n  icon,\n  compact,\n  tone = \"secondary\",\n  size = \"md\",\n  disabled,\n  side,\n  align,\n  ...props\n}: Omit<React.ComponentProps<typeof SdkMenu>, \"children\" | \"items\"> & {\n  label: string\n  items: MenuEntry[]\n  icon?: React.ReactNode\n  compact?: boolean\n  tone?: ButtonTone\n  size?: ButtonSize\n  disabled?: boolean\n  side?: React.ComponentProps<typeof MenuContent>[\"side\"]\n  align?: React.ComponentProps<typeof MenuContent>[\"align\"]\n}) {\n  return (\n    <SdkMenu {...props}>\n      <MenuTrigger\n        data-kit=\"button\"\n        data-frame={tone === \"ghost\" ? \"br\" : \"notch br\"}\n        data-press-flash=\"\"\n        data-tone={tone}\n        data-size={size}\n        data-icon={compact ? \"\" : undefined}\n        aria-label={compact ? label : undefined}\n        disabled={disabled}\n      >\n        {icon}\n        {!compact && label}\n        {!compact && <ChevronDown data-kit=\"menu-caret\" aria-hidden />}\n      </MenuTrigger>\n      <MenuPopup items={items} side={side} align={align} />\n    </SdkMenu>\n  )\n}\n\nexport { Menu, MenuEntries, MenuPopup }\nexport type { MenuEntry }\n",
      "type": "registry:ui",
      "target": "@ui/menu.tsx"
    },
    {
      "path": "registry/cyber/ui/cyber/menu.css",
      "content": "@layer ui-sdk, cyber.tokens, cyber.base, cyber.ui, cyber.blocks, cyber.fx, cyber.a11y;\n\n/* A menu is the shared popup look (popup.css) plus the few things only a\n   menu has: the caret on its key, the leading column of icons and checks,\n   the mark in a checkable row, the arrow on a row that opens another level,\n   and a row that can't be taken back. */\n@layer cyber.ui {\n  /* The caret on the key turns over while its menu is open. */\n  [data-skin=\"cyber\"] [data-kit=\"menu-caret\"] {\n    margin-inline-end: -4px;\n    transition: rotate var(--cy-t) var(--cy-ease-snap);\n\n    [data-open] > & {\n      rotate: 180deg;\n    }\n  }\n\n  /* The leading column: an icon, or the space one would take, so every\n     label in the level starts on the same line. */\n  [data-skin=\"cyber\"] [data-kit=\"menu-icon\"] {\n    flex: none;\n    display: grid;\n    place-items: center;\n    width: 14px;\n    height: 14px;\n  }\n\n  /* The mark: hollow while off, a lit block while on. Shape says which kind\n     of choice it is, so neither state rests on color: a box toggles on its\n     own, a diamond is one of several. */\n  [data-skin=\"cyber\"] [data-kit=\"menu-mark\"] {\n    width: 10px;\n    height: 10px;\n    border: 1px solid var(--cy-line-ctl);\n    transition:\n      background-color var(--cy-t-fast) linear,\n      border-color var(--cy-t-fast) linear;\n\n    &[data-shape=\"box\"] {\n      clip-path: polygon(0 0, 100% 0, 100% calc(100% - 3px), calc(100% - 3px) 100%, 0 100%);\n    }\n\n    &[data-shape=\"diamond\"] {\n      width: 8px;\n      height: 8px;\n      rotate: 45deg;\n    }\n\n    [data-checked] > & {\n      border-color: var(--cy-signal);\n      background: var(--cy-signal);\n      box-shadow: 0 0 calc(6px * var(--cy-fx)) var(--cy-signal);\n    }\n\n    [data-highlighted] > [data-unchecked] > & {\n      border-color: var(--cy-ink-hi);\n    }\n\n    [data-disabled] > & {\n      border-color: var(--cy-line-deco);\n      box-shadow: none;\n    }\n\n    /* Fills don't survive forced colors; a thick border does. */\n    @media (forced-colors: active) {\n      [data-checked] > & {\n        border-width: 5px;\n      }\n    }\n  }\n\n  /* The arrow on a row that opens another level. It leans toward the\n     submenu while the row is lit. */\n  [data-skin=\"cyber\"] [data-kit=\"menu-more\"] {\n    margin-inline-start: auto;\n    transition: translate var(--cy-t-fast) var(--cy-ease-snap);\n\n    :is([data-highlighted], [data-open]) > & {\n      translate: 2px 0;\n    }\n\n    :dir(rtl) & {\n      scale: -1 1;\n    }\n    :dir(rtl) :is([data-highlighted], [data-open]) > & {\n      translate: -2px 0;\n    }\n  }\n\n  /* A row whose submenu is open stays lit while focus is inside the\n     submenu, so the path back is visible. */\n  [data-skin=\"cyber\"] [data-menu-row=\"sub\"][data-open]:not([data-highlighted]) {\n    background: var(--cy-fill-hover);\n    color: var(--cy-ink-hi);\n    box-shadow: inset 3px 0 0 var(--cy-line-hot);\n  }\n\n  /* Something that can't be taken back. Red is the resting color here, so\n     it's flagged in yellow, with a mark that doesn't depend on the color. */\n  [data-skin=\"cyber\"] [data-menu-row=\"destructive\"]:not([data-disabled]) {\n    color: var(--cy-flag);\n\n    &::after {\n      content: \"▲\";\n      margin-inline-start: auto;\n      padding-inline-start: 12px;\n      font-size: 8px;\n      line-height: 1;\n    }\n\n    /* The shortcut already sits at the end; the mark follows it. */\n    &:has([data-kit=\"popup-shortcut\"])::after {\n      margin-inline-start: 0;\n      padding-inline-start: 4px;\n    }\n\n    &[data-highlighted] {\n      box-shadow: inset 3px 0 0 var(--cy-flag);\n    }\n  }\n}\n",
      "type": "registry:file",
      "target": "@ui/cyber/menu.css"
    }
  ],
  "type": "registry:ui"
}
