{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "dropdown-stagger",
  "title": "Stagger dropdown",
  "description": "A dropdown menu springs open while its items stagger in, with a highlight that glides between items, submenus, checkbox and radio items, and full keyboard navigation.",
  "dependencies": [
    "lucide-react",
    "motion"
  ],
  "registryDependencies": [
    "https://goodui.dev/r/goodui-motion.json"
  ],
  "files": [
    {
      "path": "registry/components/overlays/dropdown-stagger.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { AnimatePresence, motion, useReducedMotion, type Variants } from \"motion/react\"\nimport { ChevronRight } from \"lucide-react\"\nimport { cn } from \"@/lib/utils\"\nimport { GooduiTokens, ease, spring } from \"@/lib/goodui-motion\"\n\nfunction useControllable<T>(value: T | undefined, defaultValue: T, onChange?: (v: T) => void) {\n  const [inner, setInner] = React.useState(defaultValue)\n  const controlled = value !== undefined\n  const current = controlled ? value : inner\n  const set = React.useCallback(\n    (v: T) => {\n      if (!controlled) setInner(v)\n      onChange?.(v)\n    },\n    [controlled, onChange],\n  )\n  return [current, set] as const\n}\n\ntype RootContextValue = { close: (returnFocus?: boolean) => void; reduce: boolean; rtl: boolean; stagger: boolean; instant: boolean }\ntype MenuContextValue = {\n  menuId: string\n  highlighted: string | null\n  setHighlighted: (id: string | null) => void\n  openSub: string | null\n  subFocusFirst: boolean\n  openSubMenu: (id: string, focusFirst: boolean) => void\n  closeSub: (id?: string) => void\n  scheduleCloseSub: () => void\n  cancelCloseSub: () => void\n}\ntype RadioContextValue = {\n  /** Value of the selected radio item. */\n  value: string\n  /** Called with the chosen item's value. */\n  onValueChange: (value: string) => void\n}\n\nconst RootContext = React.createContext<RootContextValue | null>(null)\nconst MenuContext = React.createContext<MenuContextValue | null>(null)\nconst RadioContext = React.createContext<RadioContextValue | null>(null)\n\nfunction useRoot() {\n  const ctx = React.useContext(RootContext)\n  if (!ctx) throw new Error(\"DropdownStagger parts must be used inside <DropdownStagger>\")\n  return ctx\n}\nfunction useMenu() {\n  return React.useContext(MenuContext)!\n}\n\nconst panelVariants = (reduce: boolean, sub: boolean, rtl = false, stagger = false): Variants =>\n  reduce\n    ? { closed: { opacity: 0 }, open: { opacity: 1, transition: { duration: 0 } }, exit: { opacity: 0, transition: { duration: 0 } } }\n    : {\n        closed: { opacity: 0, scale: 0.96, y: sub ? 0 : -4, x: sub ? (rtl ? 4 : -4) : 0 },\n        open: {\n          opacity: 1,\n          scale: 1,\n          y: 0,\n          x: 0,\n          transition: { duration: 0.15, ease: ease.out, ...(stagger ? { staggerChildren: 0.028, delayChildren: 0.03 } : {}) },\n        },\n        exit: { opacity: 0, scale: 0.98, transition: { duration: 0.1, ease: ease.out } },\n      }\n\nconst itemVariants = (reduce: boolean, rtl = false): Variants =>\n  reduce\n    ? { closed: { opacity: 0 }, open: { opacity: 1, transition: { duration: 0 } } }\n    : { closed: { opacity: 0, x: rtl ? 8 : -8 }, open: { opacity: 1, x: 0, transition: spring.ui } }\n\nconst ITEM =\n  \"relative flex w-full cursor-default items-center gap-2 rounded-md px-2 py-1.5 text-start text-sm outline-none select-none aria-disabled:pointer-events-none aria-disabled:opacity-50 [&_svg]:size-4 [&_svg]:shrink-0\"\n\ntype MenuPanelProps = {\n  id?: string\n  menuId: string\n  labelledBy: string\n  sub?: boolean\n  focusOnMount: \"first\" | \"last\" | \"panel\" | null\n  onEscape: () => void\n  className?: string\n  children: React.ReactNode\n}\n\nfunction MenuPanel({ id, menuId, labelledBy, sub = false, focusOnMount, onEscape, className, children }: MenuPanelProps) {\n  const { close, reduce, rtl, stagger, instant } = useRoot()\n  const ref = React.useRef<HTMLDivElement>(null)\n  const [highlighted, setHighlighted] = React.useState<string | null>(null)\n  const [openSub, setOpenSub] = React.useState<string | null>(null)\n  const [subFocusFirst, setSubFocusFirst] = React.useState(false)\n  const subTimer = React.useRef<ReturnType<typeof setTimeout> | null>(null)\n  const typeahead = React.useRef({ text: \"\", at: 0 })\n\n  const items = React.useCallback(\n    () =>\n      Array.from(ref.current?.querySelectorAll<HTMLElement>(`[data-pc-item=\"${menuId}\"]`) ?? []).filter(\n        (el) => el.getAttribute(\"aria-disabled\") !== \"true\",\n      ),\n    [menuId],\n  )\n\n  React.useLayoutEffect(() => {\n    if (focusOnMount === \"panel\") ref.current?.focus({ preventScroll: true })\n    else if (focusOnMount) {\n      const list = items()\n      ;(focusOnMount === \"first\" ? list[0] : list[list.length - 1])?.focus({ preventScroll: true })\n    }\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, [])\n\n  React.useEffect(() => () => void (subTimer.current && clearTimeout(subTimer.current)), [])\n\n  const menu = React.useMemo<MenuContextValue>(\n    () => ({\n      menuId,\n      highlighted,\n      setHighlighted,\n      openSub,\n      subFocusFirst,\n      openSubMenu: (id, focusFirst) => {\n        if (subTimer.current) clearTimeout(subTimer.current)\n        setSubFocusFirst(focusFirst)\n        setOpenSub(id)\n      },\n      closeSub: (id) => setOpenSub((cur) => (id === undefined || cur === id ? null : cur)),\n      scheduleCloseSub: () => {\n        if (subTimer.current) clearTimeout(subTimer.current)\n        subTimer.current = setTimeout(() => setOpenSub(null), 160)\n      },\n      cancelCloseSub: () => {\n        if (subTimer.current) clearTimeout(subTimer.current)\n      },\n    }),\n    [menuId, highlighted, openSub, subFocusFirst],\n  )\n\n  const onKeyDown = (e: React.KeyboardEvent<HTMLDivElement>) => {\n    if ((e.target as HTMLElement).closest('[role=\"menu\"]') !== ref.current) return\n    const list = items()\n    const idx = list.indexOf(document.activeElement as HTMLElement)\n    const focus = (i: number) => list[(i + list.length) % list.length]?.focus({ preventScroll: true })\n    switch (e.key) {\n      case \"ArrowDown\":\n        e.preventDefault()\n        return focus(idx + 1)\n      case \"ArrowUp\":\n        e.preventDefault()\n        return focus(idx < 0 ? -1 : idx - 1)\n      case \"Home\":\n        e.preventDefault()\n        return focus(0)\n      case \"End\":\n        e.preventDefault()\n        return focus(-1)\n      case \"Escape\":\n        e.preventDefault()\n        e.stopPropagation()\n        return onEscape()\n      case rtl ? \"ArrowRight\" : \"ArrowLeft\":\n        if (sub) {\n          e.preventDefault()\n          onEscape()\n        }\n        return\n      case \"Tab\":\n        e.preventDefault()\n        return close(true)\n    }\n    if (e.key.length === 1 && /\\S/.test(e.key) && !e.ctrlKey && !e.metaKey && !e.altKey) {\n      const t = typeahead.current\n      t.text = e.timeStamp - t.at > 600 ? e.key.toLowerCase() : t.text + e.key.toLowerCase()\n      t.at = e.timeStamp\n      const ordered = [...list.slice(idx + 1), ...list.slice(0, idx + 1)]\n      ordered.find((el) => el.textContent?.trim().toLowerCase().startsWith(t.text))?.focus({ preventScroll: true })\n    }\n  }\n\n  return (\n    <MenuContext.Provider value={menu}>\n      <motion.div\n        ref={ref}\n        id={id}\n        role=\"menu\"\n        aria-labelledby={labelledBy}\n        aria-orientation=\"vertical\"\n        tabIndex={-1}\n        variants={panelVariants(reduce || instant, sub, rtl, stagger)}\n        initial=\"closed\"\n        animate=\"open\"\n        exit=\"exit\"\n        onKeyDown={onKeyDown}\n        onPointerLeave={() => {\n          if (!openSub) setHighlighted(null)\n        }}\n        className={cn(\n          \"absolute z-50 flex min-w-52 flex-col rounded-xl bg-popover p-1 text-popover-foreground shadow-[var(--pc-e2)] outline-none\",\n          className,\n        )}\n      >\n        {children}\n      </motion.div>\n    </MenuContext.Provider>\n  )\n}\n\nfunction Highlight({ active, destructive }: { active: boolean; destructive?: boolean }) {\n  const { reduce } = useRoot()\n  const { menuId } = useMenu()\n  if (!active) return null\n  return (\n    <motion.span\n      aria-hidden=\"true\"\n      layoutId={`${menuId}-highlight`}\n      className={cn(\"absolute inset-0 rounded-md\", destructive ? \"bg-destructive/10 dark:bg-destructive/20\" : \"bg-muted\")}\n      style={{ borderRadius: 6 }}\n      transition={reduce ? { duration: 0 } : spring.snap}\n    />\n  )\n}\n\nexport type DropdownStaggerProps = Omit<React.ComponentProps<\"div\">, \"children\"> & {\n  /** Content of the trigger button. */\n  trigger: React.ReactNode\n  /** Accessible name when the trigger is icon-only. Rendered as sr-only text after the trigger content, so any visible text stays the start of the name. */\n  triggerLabel?: string\n  /** Classes for the trigger button. */\n  triggerClassName?: string\n  /** Classes for the menu panel. */\n  contentClassName?: string\n  /** Which edge of the trigger the menu lines up with (logical: start is the left edge in LTR, the right edge in RTL). It does not flip near the viewport edge. */\n  align?: \"start\" | \"end\"\n  /** Controlled open state. Pair with onOpenChange. */\n  open?: boolean\n  /** Initial open state when uncontrolled. */\n  defaultOpen?: boolean\n  /** Called with the next state on trigger use, item selection, Esc, Tab or an outside click. */\n  onOpenChange?: (open: boolean) => void\n  /** Cascade the items in. Off by default: menus are frequent, so they stay quiet. Keep it for rare, showcase menus. */\n  stagger?: boolean\n  /** Items, labels, separators, radio groups and submenus. */\n  children: React.ReactNode\n}\n\n/**\n * Dropdown menu whose panel springs open while its items stagger in. Arrow keys, Home/End, typeahead,\n * submenus (hover or ArrowRight), checkbox and radio items, and a highlight that glides between items.\n */\nexport function DropdownStagger({\n  trigger,\n  triggerLabel,\n  triggerClassName,\n  contentClassName,\n  align = \"start\",\n  open: openProp,\n  defaultOpen = false,\n  onOpenChange,\n  stagger = false,\n  className,\n  children,\n  ...props\n}: DropdownStaggerProps) {\n  const reduce = useReducedMotion() ?? false\n  const [open, setOpen] = useControllable(openProp, defaultOpen, onOpenChange)\n  const uid = React.useId()\n  const rootRef = React.useRef<HTMLDivElement>(null)\n  const triggerRef = React.useRef<HTMLButtonElement>(null)\n  const [focusMode, setFocusMode] = React.useState<\"first\" | \"last\" | \"panel\">(\"panel\")\n  // Right-to-left mirrors submenu keys, placement and the slide-in direction; read after mount so SSR output is unchanged.\n  const [rtl, setRtl] = React.useState(false)\n  React.useEffect(() => {\n    if (triggerRef.current) setRtl(getComputedStyle(triggerRef.current).direction === \"rtl\")\n  }, [])\n\n  const close = React.useCallback(\n    (returnFocus = true) => {\n      setOpen(false)\n      if (returnFocus) triggerRef.current?.focus({ preventScroll: true })\n    },\n    [setOpen],\n  )\n\n  React.useEffect(() => {\n    if (!open) return\n    const onDown = (e: PointerEvent) => {\n      if (!rootRef.current?.contains(e.target as Node)) close(false)\n    }\n    document.addEventListener(\"pointerdown\", onDown)\n    return () => document.removeEventListener(\"pointerdown\", onDown)\n  }, [open, close])\n\n  const instant = focusMode !== \"panel\"\n  const root = React.useMemo(() => ({ close, reduce, rtl, stagger, instant }), [close, reduce, rtl, stagger, instant])\n\n  return (\n    <RootContext.Provider value={root}>\n      <GooduiTokens />\n      <div ref={rootRef} className={cn(\"relative inline-block\", className)} {...props}>\n        <button\n          ref={triggerRef}\n          id={`${uid}-trigger`}\n          type=\"button\"\n          aria-haspopup=\"menu\"\n          aria-expanded={open}\n          aria-controls={open ? `${uid}-menu` : undefined}\n          onClick={() => {\n            setFocusMode(\"panel\")\n            setOpen(!open)\n          }}\n          onKeyDown={(e) => {\n            if ([\"ArrowDown\", \"ArrowUp\", \"Enter\", \" \"].includes(e.key)) {\n              e.preventDefault()\n              setFocusMode(e.key === \"ArrowUp\" ? \"last\" : \"first\")\n              setOpen(true)\n            }\n          }}\n          className={cn(\n            \"pc-press inline-flex h-9 items-center justify-center gap-2 rounded-lg bg-background px-3 text-sm font-medium shadow-[var(--pc-e1)] transition-colors outline-none hover:bg-muted focus-visible:ring-3 focus-visible:ring-ring/50 aria-expanded:bg-muted [&_svg]:size-4 [&_svg]:shrink-0\",\n            triggerClassName,\n          )}\n        >\n          {trigger}\n          {triggerLabel && <span className=\"sr-only\">{triggerLabel}</span>}\n        </button>\n        <AnimatePresence>\n          {open && (\n            <MenuPanel\n              key=\"menu\"\n              id={`${uid}-menu`}\n              menuId={`${uid}-root`}\n              labelledBy={`${uid}-trigger`}\n              focusOnMount={focusMode}\n              onEscape={() => close(true)}\n              className={cn(\"top-full mt-1.5\", align === \"start\" ? \"start-0 origin-top-left rtl:origin-top-right\" : \"end-0 origin-top-right rtl:origin-top-left\", contentClassName)}\n            >\n              {children}\n            </MenuPanel>\n          )}\n        </AnimatePresence>\n      </div>\n    </RootContext.Provider>\n  )\n}\n\nexport type DropdownStaggerItemProps = {\n  /** Leading icon, tinted muted unless the item is destructive. */\n  icon?: React.ReactNode\n  /** Hint shown on the right, e.g. \"⌘E\". It is display text only; it does not bind the shortcut. */\n  shortcut?: string\n  /** \"destructive\" colors the text and highlight with the destructive token. */\n  variant?: \"default\" | \"destructive\"\n  /** Grays the item out; arrow keys and typeahead skip it and clicks do nothing. */\n  disabled?: boolean\n  /** Call event.preventDefault() to keep the menu open. */\n  onSelect?: (event: React.MouseEvent<HTMLButtonElement>) => void\n  /** Close the menu and return focus to the trigger after selecting. Defaults to true for items, false for checkbox and radio items. */\n  closeOnSelect?: boolean\n  className?: string\n  children: React.ReactNode\n}\n\nexport function DropdownStaggerItem({\n  icon,\n  shortcut,\n  variant = \"default\",\n  disabled,\n  onSelect,\n  closeOnSelect = true,\n  className,\n  children,\n}: DropdownStaggerItemProps) {\n  const id = React.useId()\n  const root = useRoot()\n  const menu = useMenu()\n  const destructive = variant === \"destructive\"\n  return (\n    <motion.button\n      type=\"button\"\n      role=\"menuitem\"\n      tabIndex={-1}\n      data-pc-item={menu.menuId}\n      aria-disabled={disabled || undefined}\n      variants={itemVariants(root.reduce || !root.stagger, root.rtl)}\n      onFocus={() => menu.setHighlighted(id)}\n      onPointerEnter={menu.scheduleCloseSub}\n      onPointerMove={(e) => {\n        if (!disabled && document.activeElement !== e.currentTarget) e.currentTarget.focus({ preventScroll: true })\n      }}\n      onClick={(e) => {\n        if (disabled) return\n        onSelect?.(e)\n        if (closeOnSelect && !e.defaultPrevented) root.close(true)\n      }}\n      // Destructive text is darkened in light mode so it keeps 4.5:1 on the red highlight.\n      className={cn(\"pc-press\", ITEM, destructive && \"text-[color-mix(in_oklab,var(--destructive),black_18%)] dark:text-destructive\", className)}\n    >\n      <Highlight active={menu.highlighted === id} destructive={destructive} />\n      <span className={cn(\"relative flex min-w-0 flex-1 items-center gap-2\", !destructive && \"[&_svg]:text-muted-foreground\")}>\n        {icon}\n        <span className=\"truncate\">{children}</span>\n      </span>\n      {shortcut && <span className=\"relative ms-auto ps-4 text-xs tracking-widest text-foreground/60\">{shortcut}</span>}\n    </motion.button>\n  )\n}\n\nexport type DropdownStaggerCheckboxItemProps = Omit<DropdownStaggerItemProps, \"variant\" | \"icon\"> & {\n  /** Whether the check is drawn. The item is always controlled. */\n  checked: boolean\n  /** Called with the toggled value on click, Enter or Space. */\n  onCheckedChange: (checked: boolean) => void\n}\n\n/** Toggle item with a check that draws itself. Stays open by default so several can be toggled. */\nexport function DropdownStaggerCheckboxItem({\n  checked,\n  onCheckedChange,\n  shortcut,\n  disabled,\n  onSelect,\n  closeOnSelect = false,\n  className,\n  children,\n}: DropdownStaggerCheckboxItemProps) {\n  const id = React.useId()\n  const root = useRoot()\n  const menu = useMenu()\n  return (\n    <motion.button\n      type=\"button\"\n      role=\"menuitemcheckbox\"\n      aria-checked={checked}\n      tabIndex={-1}\n      data-pc-item={menu.menuId}\n      aria-disabled={disabled || undefined}\n      variants={itemVariants(root.reduce || !root.stagger, root.rtl)}\n      onFocus={() => menu.setHighlighted(id)}\n      onPointerEnter={menu.scheduleCloseSub}\n      onPointerMove={(e) => {\n        if (!disabled && document.activeElement !== e.currentTarget) e.currentTarget.focus({ preventScroll: true })\n      }}\n      onClick={(e) => {\n        if (disabled) return\n        onSelect?.(e)\n        onCheckedChange(!checked)\n        if (closeOnSelect && !e.defaultPrevented) root.close(true)\n      }}\n      className={cn(\"pc-press\", ITEM, className)}\n    >\n      <Highlight active={menu.highlighted === id} />\n      <span className=\"relative grid size-4 place-items-center\">\n        <svg viewBox=\"0 0 16 16\" fill=\"none\" className=\"size-4\" aria-hidden=\"true\">\n          <motion.path\n            d=\"M3.5 8.5l3 3 6-7\"\n            stroke=\"currentColor\"\n            strokeWidth={2}\n            strokeLinecap=\"round\"\n            strokeLinejoin=\"round\"\n            initial={false}\n            animate={{ pathLength: checked ? 1 : 0, opacity: checked ? 1 : 0 }}\n            transition={root.reduce ? { duration: 0 } : { pathLength: spring.ui, opacity: { duration: 0.1 } }}\n          />\n        </svg>\n      </span>\n      <span className=\"relative min-w-0 flex-1 truncate\">{children}</span>\n      {shortcut && <span className=\"relative ms-auto ps-4 text-xs tracking-widest text-foreground/60\">{shortcut}</span>}\n    </motion.button>\n  )\n}\n\nexport type DropdownStaggerRadioGroupProps = RadioContextValue & {\n  /** Accessible name of the group. Without it, a DropdownStaggerLabel right before (or inside) the group names it. */\n  label?: string\n  /** Id of an element that names the group; overrides the automatic DropdownStaggerLabel link. */\n  \"aria-labelledby\"?: string\n  children: React.ReactNode\n}\n\nexport function DropdownStaggerRadioGroup({ value, onValueChange, label, \"aria-labelledby\": labelledByProp, children }: DropdownStaggerRadioGroupProps) {\n  const ctx = React.useMemo(() => ({ value, onValueChange }), [value, onValueChange])\n  const ref = React.useRef<HTMLDivElement>(null)\n  const [labelId, setLabelId] = React.useState<string | undefined>(undefined)\n  // Find the DropdownStaggerLabel that heads this group: the first one inside it, else the element right before it.\n  React.useLayoutEffect(() => {\n    const el = ref.current\n    if (!el || label || labelledByProp) return\n    const inner = el.querySelector<HTMLElement>(\":scope > [data-pc-menu-label]\")\n    const prev = el.previousElementSibling\n    const found = inner ?? (prev instanceof HTMLElement && prev.hasAttribute(\"data-pc-menu-label\") ? prev : null)\n    setLabelId(found?.id || undefined)\n  }, [label, labelledByProp])\n  return (\n    <RadioContext.Provider value={ctx}>\n      <div ref={ref} role=\"group\" aria-label={label} aria-labelledby={label ? undefined : (labelledByProp ?? labelId)} className=\"contents\">\n        {children}\n      </div>\n    </RadioContext.Provider>\n  )\n}\n\nexport type DropdownStaggerRadioItemProps = Omit<DropdownStaggerItemProps, \"variant\" | \"icon\"> & {\n  /** Value reported to the surrounding DropdownStaggerRadioGroup; checked when it equals the group's value. */\n  value: string\n}\n\nexport function DropdownStaggerRadioItem({\n  value,\n  shortcut,\n  disabled,\n  onSelect,\n  closeOnSelect = false,\n  className,\n  children,\n}: DropdownStaggerRadioItemProps) {\n  const id = React.useId()\n  const root = useRoot()\n  const menu = useMenu()\n  const group = React.useContext(RadioContext)\n  const checked = group?.value === value\n  return (\n    <motion.button\n      type=\"button\"\n      role=\"menuitemradio\"\n      aria-checked={checked}\n      tabIndex={-1}\n      data-pc-item={menu.menuId}\n      aria-disabled={disabled || undefined}\n      variants={itemVariants(root.reduce || !root.stagger, root.rtl)}\n      onFocus={() => menu.setHighlighted(id)}\n      onPointerEnter={menu.scheduleCloseSub}\n      onPointerMove={(e) => {\n        if (!disabled && document.activeElement !== e.currentTarget) e.currentTarget.focus({ preventScroll: true })\n      }}\n      onClick={(e) => {\n        if (disabled) return\n        onSelect?.(e)\n        group?.onValueChange(value)\n        if (closeOnSelect && !e.defaultPrevented) root.close(true)\n      }}\n      className={cn(\"pc-press\", ITEM, className)}\n    >\n      <Highlight active={menu.highlighted === id} />\n      <span className=\"relative grid size-4 place-items-center\">\n        <motion.span\n          className=\"size-2 rounded-full bg-current\"\n          initial={false}\n          animate={{ scale: checked ? 1 : 0, opacity: checked ? 1 : 0 }}\n          transition={root.reduce ? { duration: 0 } : spring.play}\n        />\n      </span>\n      <span className=\"relative min-w-0 flex-1 truncate\">{children}</span>\n      {shortcut && <span className=\"relative ms-auto ps-4 text-xs tracking-widest text-foreground/60\">{shortcut}</span>}\n    </motion.button>\n  )\n}\n\nexport type DropdownStaggerSubProps = {\n  /** Text of the item that opens the submenu; it also names the submenu. */\n  label: React.ReactNode\n  /** Leading icon for the submenu item. */\n  icon?: React.ReactNode\n  /** Grays the item out; the submenu cannot open. */\n  disabled?: boolean\n  className?: string\n  children: React.ReactNode\n}\n\n/** Item that opens a nested menu on hover, click, Enter or ArrowRight. It flips left or below near the edge. */\nexport function DropdownStaggerSub({ label, icon, disabled, className, children }: DropdownStaggerSubProps) {\n  const id = React.useId()\n  const subId = React.useId()\n  const root = useRoot()\n  const menu = useMenu()\n  const triggerRef = React.useRef<HTMLButtonElement>(null)\n  const hoverTimer = React.useRef<ReturnType<typeof setTimeout> | null>(null)\n  const [placement, setPlacement] = React.useState<\"right\" | \"left\" | \"below\">(root.rtl ? \"left\" : \"right\")\n  const open = menu.openSub === id\n\n  React.useEffect(() => () => void (hoverTimer.current && clearTimeout(hoverTimer.current)), [])\n\n  const show = (focusFirst: boolean) => {\n    if (disabled) return\n    const r = triggerRef.current?.getBoundingClientRect()\n    if (r) {\n      const w = 208\n      const vw = window.innerWidth\n      const fitsRight = r.right + w + 8 <= vw - 4\n      const fitsLeft = r.left - w - 8 >= 4\n      // Open toward the inline end first: right in LTR, left in RTL.\n      if (root.rtl) setPlacement(fitsLeft ? \"left\" : fitsRight ? \"right\" : \"below\")\n      else setPlacement(fitsRight ? \"right\" : fitsLeft ? \"left\" : \"below\")\n    }\n    menu.openSubMenu(id, focusFirst)\n  }\n\n  return (\n    <div\n      className=\"relative\"\n      onPointerEnter={menu.cancelCloseSub}\n      onPointerLeave={() => {\n        if (hoverTimer.current) clearTimeout(hoverTimer.current)\n        if (open) menu.scheduleCloseSub()\n      }}\n    >\n      <motion.button\n        ref={triggerRef}\n        id={`${subId}-trigger`}\n        type=\"button\"\n        role=\"menuitem\"\n        tabIndex={-1}\n        aria-haspopup=\"menu\"\n        aria-expanded={open}\n        aria-disabled={disabled || undefined}\n        data-pc-item={menu.menuId}\n        variants={itemVariants(root.reduce || !root.stagger, root.rtl)}\n        onFocus={() => menu.setHighlighted(id)}\n        onPointerEnter={() => {\n          menu.cancelCloseSub()\n          if (hoverTimer.current) clearTimeout(hoverTimer.current)\n          hoverTimer.current = setTimeout(() => show(false), 90)\n        }}\n        onPointerMove={(e) => {\n          if (!disabled && document.activeElement !== e.currentTarget) e.currentTarget.focus({ preventScroll: true })\n        }}\n        onClick={() => show(true)}\n        onKeyDown={(e) => {\n          if (e.key === (root.rtl ? \"ArrowLeft\" : \"ArrowRight\") || e.key === \"Enter\" || e.key === \" \") {\n            e.preventDefault()\n            e.stopPropagation()\n            show(true)\n          }\n        }}\n        className={cn(\"pc-press\", ITEM, open && menu.highlighted !== id && \"bg-muted/60\", className)}\n      >\n        <Highlight active={menu.highlighted === id} />\n        <span className=\"relative flex min-w-0 flex-1 items-center gap-2 [&_svg]:text-muted-foreground\">\n          {icon}\n          <span className=\"truncate\">{label}</span>\n        </span>\n        <ChevronRight className=\"relative ms-auto text-muted-foreground rtl:rotate-180\" />\n      </motion.button>\n      <AnimatePresence>\n        {open && (\n          <MenuPanel\n            key=\"sub\"\n            sub\n            menuId={subId}\n            labelledBy={`${subId}-trigger`}\n            focusOnMount={menu.subFocusFirst ? \"first\" : null}\n            onEscape={() => {\n              menu.closeSub(id)\n              triggerRef.current?.focus({ preventScroll: true })\n            }}\n            className={cn(\n              \"w-52 min-w-0\",\n              placement === \"right\" && \"top-[-5px] left-full ml-1.5 origin-top-left\",\n              placement === \"left\" && \"top-[-5px] right-full mr-1.5 origin-top-right\",\n              placement === \"below\" && \"top-full start-6 mt-1 origin-top-left rtl:origin-top-right\",\n            )}\n          >\n            {children}\n          </MenuPanel>\n        )}\n      </AnimatePresence>\n    </div>\n  )\n}\n\nexport function DropdownStaggerLabel({ id, className, children }: { id?: string; className?: string; children: React.ReactNode }) {\n  const root = useRoot()\n  const autoId = React.useId()\n  return (\n    <motion.div id={id ?? autoId} data-pc-menu-label=\"\" variants={itemVariants(root.reduce || !root.stagger, root.rtl)} className={cn(\"px-2 pt-1.5 pb-1 text-xs font-medium text-muted-foreground\", className)}>\n      {children}\n    </motion.div>\n  )\n}\n\nexport function DropdownStaggerSeparator({ className }: { className?: string }) {\n  const root = useRoot()\n  return <motion.div role=\"separator\" variants={itemVariants(root.reduce || !root.stagger, root.rtl)} className={cn(\"-mx-1 my-1 h-px bg-border\", className)} />\n}\n",
      "type": "registry:component",
      "target": "components/goodui/dropdown-stagger.tsx"
    }
  ],
  "categories": [
    "components",
    "overlays"
  ],
  "type": "registry:component"
}