{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "pop-out-circle-menu",
  "title": "Pop-out Circle Menu",
  "description": "A round button circled by slowly turning text that pops its links out along an arc: a hairline ring opens behind them, icons spring out in a stagger with labels sliding outward, from a corner, an edge or in a full circle.",
  "dependencies": [
    "motion",
    "lucide-react",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/pop-out-circle-menu/pop-out-circle-menu.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { AnimatePresence, motion } from \"motion/react\";\nimport { Folder, Grid2X2, Layers, Mail, Plus, ShoppingBag } from \"lucide-react\";\nimport { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nfunction cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\nexport type MenuTheme = \"dark\" | \"light\";\nexport type PopOutPlacement = \"bottom-right\" | \"bottom-left\" | \"top-right\" | \"top-left\" | \"top\" | \"bottom\" | \"center\";\n\nexport interface PopOutMenuItem {\n  /** A stable, unique item identifier. */\n  id: string;\n  label: string;\n  href?: string;\n  icon: React.ReactNode;\n}\n\nconst DEFAULT_ITEMS: PopOutMenuItem[] = [\n  { id: \"work\", label: \"Work\", href: \"/work\", icon: <Grid2X2 size={17} strokeWidth={1.6} /> },\n  { id: \"studio\", label: \"Studio\", href: \"/studio\", icon: <Layers size={17} strokeWidth={1.6} /> },\n  { id: \"journal\", label: \"Journal\", href: \"/journal\", icon: <Folder size={17} strokeWidth={1.6} /> },\n  { id: \"shop\", label: \"Objects\", href: \"/objects\", icon: <ShoppingBag size={17} strokeWidth={1.6} /> },\n  { id: \"contact\", label: \"Say hello\", href: \"/contact\", icon: <Mail size={17} strokeWidth={1.6} /> },\n];\n\nfunction palette(theme: MenuTheme): React.CSSProperties & Record<`--${string}`, string> {\n  const light = theme === \"light\";\n  return {\n    \"--nav-page\": light ? \"#f5f4f1\" : \"#0e0e0e\",\n    \"--nav-ink\": light ? \"#0a0a0a\" : \"#f5f4f1\",\n    \"--nav-muted\": light ? \"rgba(10,10,10,.52)\" : \"rgba(245,244,241,.52)\",\n    \"--nav-line\": light ? \"rgba(10,10,10,.1)\" : \"rgba(245,244,241,.1)\",\n    \"--nav-soft\": light ? \"rgba(10,10,10,.045)\" : \"rgba(245,244,241,.045)\",\n    \"--nav-panel\": light ? \"rgba(245,244,241,.96)\" : \"rgba(14,14,14,.96)\",\n    \"--nav-serif\": \"var(--navbar-serif, 'Instrument Serif', Georgia, serif)\",\n  };\n}\n\nconst focus = \"outline-none focus-visible:ring-2 focus-visible:ring-[var(--nav-ink)]/40 focus-visible:ring-offset-4 focus-visible:ring-offset-[var(--nav-page)]\";\nconst muted = \"text-[color:var(--nav-muted)]\";\nconst SPRING = { type: \"spring\" as const, stiffness: 380, damping: 24, mass: 0.8 };\n\nfunction subscribeReducedMotion(onChange: () => void) {\n  const query = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n  query.addEventListener(\"change\", onChange);\n  return () => query.removeEventListener(\"change\", onChange);\n}\nconst reducedMotionSnapshot = () => window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\nconst serverReducedMotionSnapshot = () => false;\nfunction useReducedMotion() {\n  return React.useSyncExternalStore(subscribeReducedMotion, reducedMotionSnapshot, serverReducedMotionSnapshot);\n}\n\nfunction useDisclosure(value: boolean | undefined, defaultValue: boolean, onChange?: (open: boolean) => void) {\n  const [internal, setInternal] = React.useState(defaultValue);\n  const open = value ?? internal;\n  const setOpen = React.useCallback(\n    (next: boolean) => {\n      if (value === undefined) setInternal(next);\n      onChange?.(next);\n    },\n    [value, onChange],\n  );\n  return [open, setOpen] as const;\n}\n\n/** The arc each placement fans across, in degrees (0 = right, 90 = up). */\nconst ARCS: Record<PopOutPlacement, [number, number, boolean]> = {\n  \"bottom-right\": [90, 180, false],\n  \"bottom-left\": [90, 0, false],\n  \"top-right\": [270, 180, false],\n  \"top-left\": [270, 360, false],\n  top: [180, 360, false],\n  bottom: [180, 0, false],\n  center: [90, 450, true],\n};\n\nfunction positions(count: number, placement: PopOutPlacement, radius: number) {\n  const [from, to, closed] = ARCS[placement];\n  const steps = closed ? count : Math.max(count - 1, 1);\n  return Array.from({ length: count }, (_, i) => {\n    const a = (from + ((to - from) * i) / steps) * (Math.PI / 180);\n    // y is flipped: up on screen is negative. Rounded so server and browser agree.\n    return { x: Math.round(Math.cos(a) * radius * 100) / 100, y: Math.round(-Math.sin(a) * radius * 100) / 100, cos: Math.cos(a), sin: Math.sin(a) };\n  });\n}\n\nexport interface PopOutCircleMenuProps extends Omit<React.ComponentPropsWithoutRef<\"nav\">, \"children\" | \"onSelect\"> {\n  theme?: MenuTheme;\n  items?: PopOutMenuItem[];\n  /** Where the button sits, which decides the arc the items fan across. */\n  placement?: PopOutPlacement;\n  /** Distance from the button's centre to the items' centres. Defaults to 180 from a corner, 150 from an edge, 132 around the centre. */\n  radius?: number;\n  open?: boolean;\n  defaultOpen?: boolean;\n  onOpenChange?: (open: boolean) => void;\n  showLabels?: boolean;\n  showRing?: boolean;\n  /** Small circular text that turns around the closed button. */\n  orbitText?: string | false;\n  onSelect?: (item: PopOutMenuItem, event: React.MouseEvent<HTMLElement>) => void;\n}\n\nexport function PopOutCircleMenu({\n  theme = \"dark\",\n  items = DEFAULT_ITEMS,\n  placement = \"bottom-right\",\n  radius: radiusProp,\n  open: controlledOpen,\n  defaultOpen = false,\n  onOpenChange,\n  showLabels = true,\n  showRing = true,\n  orbitText = \"Explore ✦ the studio ✦ \",\n  onSelect,\n  className,\n  style,\n  ...props\n}: PopOutCircleMenuProps) {\n  const [open, setOpen] = useDisclosure(controlledOpen, defaultOpen, onOpenChange);\n  const reduce = useReducedMotion();\n  const rootRef = React.useRef<HTMLElement>(null);\n  const triggerRef = React.useRef<HTMLButtonElement>(null);\n  const itemRefs = React.useRef<(HTMLElement | null)[]>([]);\n  const id = React.useId();\n  const pathId = `${id.replace(/:/g, \"\")}-orbit`;\n  const radius = radiusProp ?? (placement === \"center\" ? 132 : placement === \"top\" || placement === \"bottom\" ? 150 : 180);\n  const spots = React.useMemo(() => positions(items.length, placement, radius), [items.length, placement, radius]);\n  const [hovered, setHovered] = React.useState<number | null>(null);\n\n  // Focus the first item once the fan is out; hand focus back to the button when it folds.\n  const wasOpen = React.useRef(open);\n  React.useEffect(() => {\n    if (open && !wasOpen.current) {\n      const t = window.setTimeout(() => itemRefs.current[0]?.focus({ preventScroll: true }), reduce ? 0 : 160);\n      wasOpen.current = true;\n      return () => window.clearTimeout(t);\n    }\n    if (!open && wasOpen.current && rootRef.current?.contains(document.activeElement)) triggerRef.current?.focus({ preventScroll: true });\n    wasOpen.current = open;\n  }, [open, reduce]);\n\n  // Close on a click outside or Escape.\n  React.useEffect(() => {\n    if (!open) return;\n    const pointer = (e: PointerEvent) => {\n      if (rootRef.current && !rootRef.current.contains(e.target as Node)) setOpen(false);\n    };\n    const key = (e: KeyboardEvent) => {\n      if (e.key === \"Escape\") {\n        e.preventDefault();\n        setOpen(false);\n        triggerRef.current?.focus();\n      }\n    };\n    document.addEventListener(\"pointerdown\", pointer);\n    document.addEventListener(\"keydown\", key);\n    return () => {\n      document.removeEventListener(\"pointerdown\", pointer);\n      document.removeEventListener(\"keydown\", key);\n    };\n  }, [open, setOpen]);\n\n  // Arrow keys walk round the ring.\n  const onItemKey = (e: React.KeyboardEvent, i: number) => {\n    const n = items.length;\n    let next = -1;\n    if (e.key === \"ArrowRight\" || e.key === \"ArrowDown\") next = (i + 1) % n;\n    else if (e.key === \"ArrowLeft\" || e.key === \"ArrowUp\") next = (i - 1 + n) % n;\n    else if (e.key === \"Home\") next = 0;\n    else if (e.key === \"End\") next = n - 1;\n    if (next < 0) return;\n    e.preventDefault();\n    itemRefs.current[next]?.focus();\n  };\n\n  // Labels point outward along each item's angle, so neighbours on the arc never cover each other.\n  const labelSide = (cos: number, sin: number) => {\n    if (cos > 0.38) return \"right\";\n    if (cos < -0.38) return \"left\";\n    return sin > 0 ? \"top\" : \"bottom\";\n  };\n\n  return (\n    <nav ref={rootRef} {...props} aria-label={props[\"aria-label\"] ?? \"Quick menu\"} data-theme={theme} className={cn(\"relative size-14 text-[color:var(--nav-ink)]\", className)} style={{ ...palette(theme), ...style }}>\n      {showRing && (\n        <motion.span\n          aria-hidden=\"true\"\n          className=\"pointer-events-none absolute top-1/2 left-1/2 rounded-full border border-[var(--nav-line)] bg-[radial-gradient(circle,var(--nav-soft),transparent_70%)]\"\n          style={{ width: radius * 2, height: radius * 2, marginLeft: -radius, marginTop: -radius }}\n          initial={false}\n          animate={{ scale: open ? 1 : 0.3, opacity: open ? 1 : 0 }}\n          transition={reduce ? { duration: 0 } : { duration: 0.55, ease: [0.16, 1, 0.3, 1] }}\n        />\n      )}\n      {showRing && (\n        <motion.span\n          aria-hidden=\"true\"\n          className=\"pointer-events-none absolute top-1/2 left-1/2 rounded-full border border-dashed border-[var(--nav-line)]\"\n          style={{ width: radius * 1.3, height: radius * 1.3, marginLeft: -radius * 0.65, marginTop: -radius * 0.65 }}\n          initial={false}\n          animate={{ scale: open ? 1 : 0.4, opacity: open ? 1 : 0, rotate: open ? 45 : 0 }}\n          transition={reduce ? { duration: 0 } : { duration: 0.7, ease: [0.16, 1, 0.3, 1] }}\n        />\n      )}\n\n      <ul id={id} className=\"absolute top-1/2 left-1/2\" onMouseLeave={() => setHovered(null)}>\n        <AnimatePresence>\n          {open &&\n            items.map((item, i) => {\n              const s = spots[i];\n              const side = labelSide(s.cos, s.sin);\n              const lit = hovered === i;\n              const Tag = item.href ? \"a\" : \"button\";\n              return (\n                <motion.li\n                  key={item.id}\n                  className=\"absolute top-0 left-0\"\n                  initial={{ x: 0, y: 0, scale: 0.3, opacity: 0, rotate: -60 }}\n                  animate={{ x: s.x, y: s.y, scale: 1, opacity: 1, rotate: 0 }}\n                  exit={{ x: 0, y: 0, scale: 0.3, opacity: 0, rotate: -40, transition: reduce ? { duration: 0 } : { duration: 0.28, ease: [0.7, 0, 0.84, 0], delay: (items.length - 1 - i) * 0.03 } }}\n                  transition={reduce ? { duration: 0 } : { ...SPRING, delay: i * 0.045, opacity: { duration: 0.2, delay: i * 0.045 } }}\n                >\n                  <Tag\n                    ref={(el: HTMLElement | null) => {\n                      itemRefs.current[i] = el;\n                    }}\n                    {...(item.href ? { href: item.href } : { type: \"button\" as const })}\n                    aria-label={item.label}\n                    onMouseEnter={() => setHovered(i)}\n                    // Keyboard focus lights an item; the focus moved in after a click doesn't.\n                    onFocus={(e: React.FocusEvent<HTMLElement>) => e.currentTarget.matches(\":focus-visible\") && setHovered(i)}\n                    onBlur={() => setHovered(null)}\n                    onKeyDown={(e: React.KeyboardEvent) => onItemKey(e, i)}\n                    onClick={(e: React.MouseEvent<HTMLElement>) => {\n                      onSelect?.(item, e);\n                      setOpen(false);\n                    }}\n                    className={cn(\n                      \"absolute -top-[22px] -left-[22px] flex size-11 cursor-pointer items-center justify-center rounded-full border border-[var(--nav-line)] backdrop-blur-md transition-[background-color,color,transform] duration-300\",\n                      lit ? \"scale-110 bg-[var(--nav-ink)] text-[color:var(--nav-page)]\" : \"bg-[var(--nav-panel)] text-[color:var(--nav-ink)]\",\n                      focus,\n                    )}\n                  >\n                    {item.icon}\n                  </Tag>\n                  {showLabels && (\n                    <motion.span\n                      aria-hidden=\"true\"\n                      className={cn(\n                        \"pointer-events-none absolute flex items-center gap-1.5 rounded-full border px-2.5 py-1 text-[11px] whitespace-nowrap transition-colors duration-300\",\n                        lit ? \"border-[var(--nav-ink)] bg-[var(--nav-ink)] text-[color:var(--nav-page)]\" : \"border-[var(--nav-line)] bg-[var(--nav-panel)]\",\n                        side === \"right\" && \"top-0 left-8 -translate-y-1/2\",\n                        side === \"left\" && \"top-0 right-8 -translate-y-1/2\",\n                        side === \"top\" && \"bottom-8 left-0 -translate-x-1/2\",\n                        side === \"bottom\" && \"top-8 left-0 -translate-x-1/2\",\n                      )}\n                      initial={{ opacity: 0, x: side === \"left\" ? 8 : side === \"right\" ? -8 : 0 }}\n                      animate={{ opacity: 1, x: 0 }}\n                      exit={{ opacity: 0, transition: { duration: 0.1 } }}\n                      transition={{ duration: reduce ? 0 : 0.35, delay: reduce ? 0 : 0.18 + i * 0.045, ease: [0.16, 1, 0.3, 1] }}\n                    >\n                      <span className={cn(\"text-[9px] tabular-nums\", lit ? \"opacity-60\" : muted)}>{String(i + 1).padStart(2, \"0\")}</span>\n                      {item.label}\n                    </motion.span>\n                  )}\n                </motion.li>\n              );\n            })}\n        </AnimatePresence>\n      </ul>\n\n      {orbitText && (\n        <svg\n          aria-hidden=\"true\"\n          viewBox=\"0 0 100 100\"\n          className=\"pointer-events-none absolute -inset-[18px] animate-[popout-orbit_14s_linear_infinite] transition-opacity duration-300 motion-reduce:animate-none\"\n          style={{ opacity: open ? 0 : 1 }}\n        >\n          <defs>\n            <path id={pathId} d=\"M50,50 m-42,0 a42,42 0 1,1 84,0 a42,42 0 1,1 -84,0\" />\n          </defs>\n          <text className=\"fill-[var(--nav-muted)] text-[7.2px] tracking-[.32em] uppercase\">\n            <textPath href={`#${pathId}`}>{orbitText.repeat(2)}</textPath>\n          </text>\n        </svg>\n      )}\n\n      <button\n        ref={triggerRef}\n        type=\"button\"\n        onClick={() => setOpen(!open)}\n        aria-expanded={open}\n        aria-controls={id}\n        aria-label={open ? \"Close quick menu\" : \"Open quick menu\"}\n        className={cn(\"relative z-10 flex size-14 cursor-pointer items-center justify-center rounded-full bg-[var(--nav-ink)] text-[color:var(--nav-page)] shadow-[0_12px_32px_rgba(0,0,0,.28)] transition-transform duration-300 hover:scale-105 active:scale-95\", focus)}\n      >\n        <span className=\"block transition-transform duration-500\" style={{ transform: `rotate(${open ? 135 : 0}deg)`, transitionTimingFunction: \"cubic-bezier(.16,1,.3,1)\" }}>\n          <Plus size={22} strokeWidth={1.6} />\n        </span>\n      </button>\n\n      <style>{`@keyframes popout-orbit { to { transform: rotate(360deg); } }`}</style>\n    </nav>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}