{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "menu",
  "title": "Menu",
  "description": "A menu of actions and settings, opened from a button or by a right click: it grows out of what opened it, with one highlight that glides from item to item and into submenus. Checkbox and radio items, shortcuts, and submenus that grow out of their item.",
  "dependencies": [
    "@ui-sdk/react"
  ],
  "registryDependencies": [
    "https://kinoui.com/r/kbd.json",
    "https://kinoui.com/r/keys.json",
    "https://kinoui.com/r/list-rows.json",
    "https://kinoui.com/r/panel.json",
    "https://kinoui.com/r/popup.json",
    "https://kinoui.com/r/refs.json",
    "https://kinoui.com/r/scroll.json",
    "https://kinoui.com/r/highlight.json",
    "https://kinoui.com/r/theme.json"
  ],
  "files": [
    {
      "path": "registry/components/kino/menu.tsx",
      "content": "'use client'\n\nimport { KbdGroup } from '@/registry/components/kino/kbd'\nimport { IconPlaceholder } from '@/registry/icons/icon-placeholder'\nimport { followRows, tintedRowTextClassName } from '@/registry/lib/highlight'\nimport { useAriaKeyshortcuts } from '@/registry/lib/keys'\nimport {\n  listIndicatorClassName,\n  menuGutterClassName,\n  MenuHighlight,\n  menuIndicatorSlot,\n  menuInset,\n  menuLabelClassName,\n  menuPickedRowClassName,\n  menuRowVariants,\n  menuSeparatorClassName,\n  menuShortcutClassName,\n  MenuTick,\n} from '@/registry/lib/list-rows'\nimport {\n  PanelHandle,\n  panelSheetBackdropClassName,\n  popupSheetClassName,\n  popupSheetPanelClassName,\n} from '@/registry/lib/panel'\nimport {\n  POPUP_COLLISION_PADDING,\n  popupGrowBoxClassName,\n  popupGrowContentClassName,\n  popupPlacedClassName,\n  popupSurfaceClassName,\n  usePopupPresentation,\n} from '@/registry/lib/popup'\nimport { mergeRefs } from '@/registry/lib/refs'\nimport { edgeFadeClassName, followEdges } from '@/registry/lib/scroll'\nimport {\n  Menu as MenuPrimitive,\n  MenuCheckboxItem as MenuCheckboxItemPrimitive,\n  MenuContent as MenuContentPrimitive,\n  MenuContextTrigger as MenuContextTriggerPrimitive,\n  MenuGroup as MenuGroupPrimitive,\n  MenuGroupLabel as MenuGroupLabelPrimitive,\n  MenuItem as MenuItemPrimitive,\n  MenuItemIcon as MenuItemIconPrimitive,\n  MenuItemIndicator as MenuItemIndicatorPrimitive,\n  MenuRadioGroup as MenuRadioGroupPrimitive,\n  MenuRadioItem as MenuRadioItemPrimitive,\n  MenuSeparator as MenuSeparatorPrimitive,\n  MenuShortcut as MenuShortcutPrimitive,\n  MenuSub as MenuSubPrimitive,\n  MenuSubContent as MenuSubContentPrimitive,\n  MenuSubTrigger as MenuSubTriggerPrimitive,\n  MenuTrigger as MenuTriggerPrimitive,\n} from '@ui-sdk/react/menu'\nimport {\n  type ComponentProps,\n  createContext,\n  type ReactNode,\n  type Ref,\n  type RefCallback,\n  use,\n  useMemo,\n} from 'react'\n\nimport { cn } from '@/lib/utils'\n\n/*\n * A menu of actions and settings, opened from a button or by a right click.\n * It grows out of what opened it and folds back into it, and one highlight\n * glides between its rows, across separators and into its submenus.\n */\n\n/** Tells the presentation where the trigger is, to read the motion preference there. */\nconst TriggerContext = createContext<((element: HTMLElement | null) => void) | null>(null)\n\n/**\n * With `presentation='auto'`, a small touch screen opens it as a sheet,\n * unless motion is reduced around its trigger (`popupPresentation`). A\n * context menu and a Menubar's menus are always popovers.\n */\nfunction Menu({\n  presentation = 'popover',\n  ...props\n}: ComponentProps<typeof MenuPrimitive>) {\n  const [shown, setTrigger] = usePopupPresentation(presentation)\n  return (\n    <TriggerContext value={setTrigger}>\n      <MenuPrimitive presentation={shown} {...props} />\n    </TriggerContext>\n  )\n}\n\n/** What opens it, such as a Button, through `render`. */\nfunction MenuTrigger({ ref, ...props }: ComponentProps<typeof MenuTriggerPrimitive>) {\n  const setTrigger = use(TriggerContext)\n  const refs = useMemo(() => mergeRefs(setTrigger, ref), [setTrigger, ref])\n  return <MenuTriggerPrimitive ref={refs} {...props} />\n}\n\n/**\n * The area that opens it on a right click, a long press or Shift F10. Give\n * it `tabIndex={0}` where nothing inside it takes focus, so the keyboard\n * reaches it too.\n */\nfunction MenuContextTrigger({\n  className,\n  ...props\n}: Omit<ComponentProps<typeof MenuContextTriggerPrimitive>, 'className'> & {\n  className?: string\n}) {\n  return (\n    <MenuContextTriggerPrimitive className={cn('select-none', className)} {...props} />\n  )\n}\n\n/** A ref for the rows: the highlight that glides between them, and the list's fading edges. */\nconst followMenu: RefCallback<HTMLDivElement> = (rows) => {\n  const list = rows?.parentElement\n  const content = rows?.closest<HTMLElement>('[data-menu-content]')\n  const layer = rows?.querySelector<HTMLElement>(':scope > [data-slot=menu-highlight]')\n  if (!rows || !list || !content || !layer) return\n  const stops = [\n    followRows(rows, layer, { popup: content, bounds: list }),\n    followEdges(list, '--scroll-fade'),\n  ]\n  return () => {\n    for (const stop of stops) stop()\n  }\n}\n\n/** What the box takes: ui-sdk's content props, with `className` for the list of rows. */\ntype MenuContentProps = Omit<\n  ComponentProps<typeof MenuContentPrimitive>,\n  'className' | 'children'\n> & {\n  className?: string\n  children?: ReactNode\n}\n\n/**\n * The box: it grows out of what opened it and folds back into it, or as a\n * sheet, it has a handle. A list taller than the screen, or than\n * `--menu-max-height` (24rem unless a menu that holds more sets it), scrolls.\n */\nfunction MenuBox({\n  Content,\n  className,\n  children,\n  ...props\n}: MenuContentProps & { Content: typeof MenuContentPrimitive }) {\n  return (\n    <Content\n      data-menu-content=''\n      collisionPadding={POPUP_COLLISION_PADDING}\n      arrowPadding={0}\n      className={cn(\n        popupPlacedClassName,\n        panelSheetBackdropClassName,\n        'flex max-h-[min(var(--available-height),var(--menu-max-height,24rem))] max-w-[max(12rem,min(20rem,var(--available-width)))] flex-col text-sm',\n        popupSheetClassName,\n      )}\n      {...props}\n    >\n      {({ presentation }) => (\n        <div\n          className={cn(\n            'flex min-h-0 flex-1 flex-col',\n            // A sheet opens on a touch screen, where there are no keys to show.\n            presentation === 'sheet'\n              ? cn(popupSheetPanelClassName, '**:data-menu-shortcut:hidden')\n              : cn(\n                  'relative rounded-(--list-radius)',\n                  popupSurfaceClassName,\n                  popupGrowBoxClassName,\n                ),\n          )}\n        >\n          {presentation === 'sheet' ? <PanelHandle /> : null}\n          {/* The rows scroll inside the surface, so their fading edges leave its shadow, ring and outline whole. Never sideways: at some zooms a scrollbar takes a fraction of a pixel more than the box made room for. */}\n          <div\n            className={cn(\n              'scrollbar-thin relative min-h-0 flex-1 overflow-x-hidden overflow-y-auto overscroll-contain rounded-[inherit]',\n              edgeFadeClassName,\n            )}\n          >\n            <div\n              ref={followMenu}\n              className={cn(\n                // The 4px around the rows is the highlight's margin, not a\n                // surface's padding, so it stays the same at every density. The\n                // width follows the longest row, from 12rem.\n                'group/menu relative flex min-w-48 flex-col p-1',\n                menuGutterClassName,\n                // A sheet spans the screen: its rows take a control's height for a finger, and they and their lines sit inside its edges.\n                presentation === 'sheet'\n                  ? 'px-2 pt-1 pb-3 **:data-menu-row:min-h-(--control-height) **:[[role=separator]]:mx-0'\n                  : popupGrowContentClassName,\n                className,\n              )}\n            >\n              <MenuHighlight />\n              {children}\n            </div>\n          </div>\n        </div>\n      )}\n    </Content>\n  )\n}\n\n/**\n * The menu: under its trigger, or at the pointer for a context menu.\n * `className` goes to the list of rows; every other prop goes to ui-sdk's\n * content.\n */\nfunction MenuContent({\n  side = 'bottom',\n  align = 'start',\n  sideOffset = 6,\n  ...props\n}: MenuContentProps) {\n  return (\n    <MenuBox\n      Content={MenuContentPrimitive}\n      side={side}\n      align={align}\n      sideOffset={sideOffset}\n      {...props}\n    />\n  )\n}\n\n/**\n * A row that acts. `onSelect` runs it, or the menu's `onAction` with its\n * `value`; render it as a link with `render={<a href='…' />}`.\n */\nfunction MenuItem({\n  className,\n  ref,\n  destructive = false,\n  shortcut,\n  children,\n  ...props\n}: Omit<ComponentProps<typeof MenuItemPrimitive>, 'className' | 'children' | 'shortcut'> &\n  ShortcutProps & {\n    className?: string\n    children?: ReactNode\n  }) {\n  return (\n    <MenuItemPrimitive\n      data-menu-row=''\n      data-variant={destructive ? 'destructive' : 'default'}\n      destructive={destructive}\n      ref={useShortcutRef(shortcut, ref)}\n      className={cn(\n        menuRowVariants({ variant: destructive ? 'destructive' : 'default' }),\n        menuInset,\n        className,\n      )}\n      {...props}\n    >\n      {children}\n      {shortcut ? <MenuShortcut shortcut={shortcut} /> : null}\n    </MenuItemPrimitive>\n  )\n}\n\n/** A row that turns a setting on and off, with a tick in the gutter. */\nfunction MenuCheckboxItem({\n  className,\n  ref,\n  shortcut,\n  children,\n  ...props\n}: Omit<ComponentProps<typeof MenuCheckboxItemPrimitive>, 'className' | 'children'> &\n  ShortcutProps & {\n    className?: string\n    children?: ReactNode\n  }) {\n  return (\n    <MenuCheckboxItemPrimitive\n      data-menu-row=''\n      ref={useShortcutRef(shortcut, ref)}\n      className={cn(menuRowVariants(), 'group/menu-row', className)}\n      {...props}\n    >\n      <span data-menu-indicator='' className={menuIndicatorSlot}>\n        <MenuItemIndicatorPrimitive keepMounted className={listIndicatorClassName}>\n          <MenuTick />\n        </MenuItemIndicatorPrimitive>\n      </span>\n      {children}\n      {shortcut ? <MenuShortcut shortcut={shortcut} /> : null}\n    </MenuCheckboxItemPrimitive>\n  )\n}\n\n/**\n * A row's icon, before its text: screen readers and typing to a row skip it,\n * and `mirror` flips one that points a way in right to left.\n */\nfunction MenuItemIcon({\n  className,\n  ...props\n}: Omit<ComponentProps<typeof MenuItemIconPrimitive>, 'className'> & {\n  className?: string\n}) {\n  return (\n    <MenuItemIconPrimitive\n      data-menu-icon=''\n      className={cn('flex shrink-0 items-center', className)}\n      {...props}\n    />\n  )\n}\n\nfunction MenuRadioGroup<T extends string = string>(\n  props: ComponentProps<typeof MenuRadioGroupPrimitive<T>>,\n) {\n  return <MenuRadioGroupPrimitive<T> {...props} />\n}\n\n/** One choice of a radio group: the picked one is tinted, with a medium label. */\nfunction MenuRadioItem({\n  className,\n  ref,\n  shortcut,\n  children,\n  ...props\n}: Omit<ComponentProps<typeof MenuRadioItemPrimitive>, 'className' | 'children'> &\n  ShortcutProps & {\n    className?: string\n    children?: ReactNode\n  }) {\n  return (\n    <MenuRadioItemPrimitive\n      data-menu-row=''\n      ref={useShortcutRef(shortcut, ref)}\n      className={cn(\n        menuRowVariants(),\n        'group/menu-row',\n        menuInset,\n        menuPickedRowClassName,\n        className,\n      )}\n      {...props}\n    >\n      {children}\n      {shortcut ? <MenuShortcut shortcut={shortcut} /> : null}\n    </MenuRadioItemPrimitive>\n  )\n}\n\nfunction MenuGroup(props: ComponentProps<typeof MenuGroupPrimitive>) {\n  return <MenuGroupPrimitive {...props} />\n}\n\n/** A group's heading, which names it, lined up with the rows' text past any tick's gutter. */\nfunction MenuGroupLabel({\n  className,\n  ...props\n}: Omit<ComponentProps<typeof MenuGroupLabelPrimitive>, 'className'> & {\n  className?: string\n}) {\n  return (\n    <MenuGroupLabelPrimitive className={cn(menuLabelClassName, className)} {...props} />\n  )\n}\n\n/** The Separator's line between groups of rows, across the list's 4px margin. */\nfunction MenuSeparator({\n  className,\n  ...props\n}: Omit<ComponentProps<typeof MenuSeparatorPrimitive>, 'className'> & {\n  className?: string\n}) {\n  return (\n    <MenuSeparatorPrimitive\n      className={cn(menuSeparatorClassName, className)}\n      {...props}\n    />\n  )\n}\n\ninterface ShortcutProps {\n  /**\n   * The keys that do the same as the row, as ui-sdk writes them, such as\n   * `'mod+shift+d'`: shown as `Kbd`s at the row's end and given to it as\n   * `aria-keyshortcuts`. A hint only: the app runs the shortcut.\n   */\n  shortcut?: string\n}\n\n/** A row's ref, which also says its `shortcut` as `aria-keyshortcuts`. */\nfunction useShortcutRef<T extends Element>(shortcut: string | undefined, ref?: Ref<T>) {\n  const ariaKeys = useAriaKeyshortcuts(shortcut)\n  return useMemo(() => mergeRefs<T>(ariaKeys, ref), [ariaKeys, ref])\n}\n\n/**\n * A row's keys at its end, hidden from screen readers, which hear the row's\n * `aria-keyshortcuts`. A row's `shortcut` draws it; use it yourself for a\n * hint of your own, such as a key you hold.\n */\nfunction MenuShortcut({\n  shortcut,\n  className,\n  children,\n  ...props\n}: Omit<ComponentProps<typeof MenuShortcutPrimitive>, 'className'> & {\n  /** The keys, as a row's `shortcut` takes them: `'mod+shift+d'`. */\n  shortcut?: string\n  className?: string\n}) {\n  return (\n    <MenuShortcutPrimitive\n      data-menu-shortcut=''\n      className={cn(menuShortcutClassName, className)}\n      {...props}\n    >\n      {children ?? <KbdGroup keys={shortcut} />}\n    </MenuShortcutPrimitive>\n  )\n}\n\nfunction MenuSub(props: ComponentProps<typeof MenuSubPrimitive>) {\n  return <MenuSubPrimitive {...props} />\n}\n\n/** The row that opens a submenu beside it, with a chevron at its end. */\nfunction MenuSubTrigger({\n  className,\n  children,\n  ...props\n}: Omit<ComponentProps<typeof MenuSubTriggerPrimitive>, 'className' | 'children'> & {\n  className?: string\n  children?: ReactNode\n}) {\n  return (\n    <MenuSubTriggerPrimitive\n      data-menu-row=''\n      data-variant='default'\n      className={cn(menuRowVariants(), menuInset, tintedRowTextClassName, className)}\n      {...props}\n    >\n      {children}\n      <MenuItemIconPrimitive\n        mirror\n        data-menu-chevron=''\n        className='text-muted-foreground ms-auto flex shrink-0 items-center'\n      >\n        <IconPlaceholder\n          aria-hidden\n          lucide='ChevronRightIcon'\n          tabler='IconChevronRight'\n          hugeicons='ArrowRight01Icon'\n          phosphor='CaretRightIcon'\n          remixicon='RiArrowRightSLine'\n        />\n      </MenuItemIconPrimitive>\n    </MenuSubTriggerPrimitive>\n  )\n}\n\n/** A submenu's box: beside its row, with its first row level with it. */\nfunction MenuSubContent({\n  sideOffset = 2,\n  alignOffset = -5,\n  ...props\n}: MenuContentProps) {\n  return (\n    <MenuBox\n      Content={MenuSubContentPrimitive}\n      sideOffset={sideOffset}\n      // Up by the list's 4px margin and the surface's 1px ring, so its first row meets its trigger.\n      alignOffset={alignOffset}\n      {...props}\n    />\n  )\n}\n\nexport {\n  Menu,\n  MenuCheckboxItem,\n  MenuContent,\n  MenuContextTrigger,\n  MenuGroup,\n  MenuGroupLabel,\n  MenuItem,\n  MenuItemIcon,\n  MenuRadioGroup,\n  MenuRadioItem,\n  MenuSeparator,\n  MenuShortcut,\n  MenuSub,\n  MenuSubContent,\n  MenuSubTrigger,\n  MenuTrigger,\n}\n",
      "type": "registry:component",
      "target": "@components/kino/menu.tsx"
    }
  ],
  "type": "registry:component"
}