{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "speed-dial",
  "title": "Speed Dial",
  "description": "A floating action button that opens into a short menu of actions: the plus turns into a close cross while actions spring out one after another in a line or a quarter-circle fan, each with a label, with an optional dimmed backdrop and full keyboard control.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/speed-dial/speed-dial.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { motion, AnimatePresence, useReducedMotion } from \"motion/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 SpeedDialIcon = \"edit\" | \"camera\" | \"upload\" | \"link\" | \"share\" | \"folder\" | \"mic\" | \"calendar\";\n\nexport interface SpeedDialAction {\n  label: string;\n  icon: SpeedDialIcon | React.ReactNode;\n  onClick?: () => void;\n}\n\nexport interface SpeedDialProps {\n  actions?: SpeedDialAction[];\n  /** Which way the actions open. radial fans them over a quarter circle. */\n  direction?: \"up\" | \"down\" | \"left\" | \"right\" | \"radial\";\n  /** Open on hover as well as on click. */\n  openOnHover?: boolean;\n  /** Dim everything behind while open. */\n  backdrop?: boolean;\n  /** Corner of the positioned parent (or the screen) to sit in. */\n  corner?: \"bottom-right\" | \"bottom-left\" | \"top-right\" | \"top-left\";\n  /** Place it inside the nearest positioned ancestor instead of fixed on the screen. */\n  contained?: boolean;\n  label?: string;\n  theme?: \"dark\" | \"light\";\n  className?: string;\n}\n\nconst PALETTES = {\n  dark: { fab: \"#F5F4F1\", fabText: \"#0A0A0A\", item: \"#1A1A1A\", itemText: \"#F5F4F1\", border: \"rgba(255,255,255,0.12)\", tip: \"#F5F4F1\", tipText: \"#0A0A0A\", scrim: \"rgba(0,0,0,0.45)\", focus: \"rgba(245,244,241,0.85)\" },\n  light: { fab: \"#0A0A0A\", fabText: \"#FFFFFF\", item: \"#FFFFFF\", itemText: \"#0A0A0A\", border: \"rgba(10,10,10,0.12)\", tip: \"#0A0A0A\", tipText: \"#FFFFFF\", scrim: \"rgba(10,10,10,0.18)\", focus: \"rgba(10,10,10,0.85)\" },\n};\n\nconst ICONS: Record<SpeedDialIcon, string[]> = {\n  edit: [\"M15.5 4.5a2.1 2.1 0 0 1 3 3L8 18l-4 1 1-4Z\"],\n  camera: [\"M4.5 7.5h2.6l1.4-2.1a1 1 0 0 1 .8-.4h5.4a1 1 0 0 1 .8.4l1.4 2.1h2.6A1.5 1.5 0 0 1 21 9v9a1.5 1.5 0 0 1-1.5 1.5h-15A1.5 1.5 0 0 1 3 18V9a1.5 1.5 0 0 1 1.5-1.5Z\", \"M15.5 13a3.5 3.5 0 1 1-7 0 3.5 3.5 0 0 1 7 0Z\"],\n  upload: [\"M4 15v3.5A1.5 1.5 0 0 0 5.5 20h13a1.5 1.5 0 0 0 1.5-1.5V15\", \"M12 15V4.5\", \"m7.5 9 4.5-4.5L16.5 9\"],\n  link: [\"M10 13a4.5 4.5 0 0 0 6.4.4l2.8-2.8a4.5 4.5 0 0 0-6.4-6.4l-1.2 1.2\", \"M14 11a4.5 4.5 0 0 0-6.4-.4l-2.8 2.8a4.5 4.5 0 0 0 6.4 6.4l1.1-1.1\"],\n  share: [\"M12 3v12\", \"M7.5 7.5 12 3l4.5 4.5\", \"M5 13v5.5A1.5 1.5 0 0 0 6.5 20h11a1.5 1.5 0 0 0 1.5-1.5V13\"],\n  folder: [\"M4 19.5h16a1 1 0 0 0 1-1v-10a1 1 0 0 0-1-1h-8L10 5H4a1 1 0 0 0-1 1v12.5a1 1 0 0 0 1 1Z\"],\n  mic: [\"M12 3a3 3 0 0 1 3 3v5a3 3 0 0 1-6 0V6a3 3 0 0 1 3-3Z\", \"M5.5 11a6.5 6.5 0 0 0 13 0\", \"M12 17.5V21\"],\n  calendar: [\"M6 5h12a2.5 2.5 0 0 1 2.5 2.5v10.5a2.5 2.5 0 0 1-2.5 2.5H6A2.5 2.5 0 0 1 3.5 18V7.5A2.5 2.5 0 0 1 6 5Z\", \"M3.5 10h17\", \"M8 3v4\", \"M16 3v4\"],\n};\n\nconst DEFAULT_ACTIONS: SpeedDialAction[] = [\n  { label: \"New note\", icon: \"edit\" },\n  { label: \"Take photo\", icon: \"camera\" },\n  { label: \"Upload file\", icon: \"upload\" },\n  { label: \"Record voice\", icon: \"mic\" },\n];\n\nfunction Glyph({ icon }: { icon: SpeedDialAction[\"icon\"] }) {\n  if (typeof icon === \"string\" && icon in ICONS) {\n    return (\n      <svg width=\"18\" height=\"18\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.7\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n        {ICONS[icon as SpeedDialIcon].map((d) => (\n          <path key={d} d={d} />\n        ))}\n      </svg>\n    );\n  }\n  return <>{icon}</>;\n}\n\nexport function SpeedDial({ actions = DEFAULT_ACTIONS, direction = \"up\", openOnHover = false, backdrop = false, corner = \"bottom-right\", contained = false, label = \"Quick actions\", theme = \"dark\", className }: SpeedDialProps) {\n  const p = PALETTES[theme];\n  const uid = React.useId();\n  const reduce = Boolean(useReducedMotion());\n  const [open, setOpen] = React.useState(false);\n  const fabRef = React.useRef<HTMLButtonElement>(null);\n  const listRef = React.useRef<HTMLUListElement>(null);\n\n  const [vy, vx] = corner.split(\"-\") as [\"top\" | \"bottom\", \"left\" | \"right\"];\n  // Where each action ends up, relative to the main button's centre.\n  const offset = (i: number) => {\n    const step = 58;\n    if (direction === \"radial\") {\n      const n = actions.length;\n      const start = vx === \"right\" ? 180 : 0;\n      const sweep = vx === \"right\" ? 90 : -90;\n      const a = ((start + (n === 1 ? sweep / 2 : (sweep * i) / (n - 1))) * Math.PI) / 180;\n      const r = 96;\n      return { x: Math.cos(a) * r, y: (vy === \"bottom\" ? -1 : 1) * Math.abs(Math.sin(a)) * r };\n    }\n    const d = (i + 1) * step;\n    return direction === \"up\" ? { x: 0, y: -d } : direction === \"down\" ? { x: 0, y: d } : direction === \"left\" ? { x: -d, y: 0 } : { x: d, y: 0 };\n  };\n  // Labels go on the side facing into the screen.\n  const labelSide = direction === \"left\" || direction === \"right\" ? (vy === \"bottom\" ? \"top\" : \"bottom\") : vx === \"right\" ? \"left\" : \"right\";\n\n  React.useEffect(() => {\n    if (!open) return;\n    const onKey = (e: KeyboardEvent) => {\n      if (e.key === \"Escape\") {\n        setOpen(false);\n        fabRef.current?.focus();\n      }\n    };\n    document.addEventListener(\"keydown\", onKey);\n    return () => document.removeEventListener(\"keydown\", onKey);\n  }, [open]);\n\n  const moveFocus = (e: React.KeyboardEvent, i: number) => {\n    const next = e.key === \"ArrowUp\" || e.key === \"ArrowLeft\" ? i + (direction === \"up\" || direction === \"left\" ? 1 : -1) : e.key === \"ArrowDown\" || e.key === \"ArrowRight\" ? i + (direction === \"up\" || direction === \"left\" ? -1 : 1) : null;\n    if (next === null) return;\n    e.preventDefault();\n    const items = listRef.current?.querySelectorAll<HTMLButtonElement>(\"button\");\n    if (next < 0) fabRef.current?.focus();\n    else items?.[Math.min(next, actions.length - 1)]?.focus();\n  };\n\n  const pos = contained ? \"absolute\" : \"fixed\";\n\n  return (\n    <>\n      <AnimatePresence>{backdrop && open && <motion.div key=\"scrim\" aria-hidden=\"true\" className={cn(pos, \"inset-0 z-40\")} style={{ background: p.scrim }} initial={{ opacity: 0 }} animate={{ opacity: 1 }} exit={{ opacity: 0 }} onClick={() => setOpen(false)} />}</AnimatePresence>\n      <div\n        className={cn(pos, \"z-50\", vy === \"bottom\" ? \"bottom-6\" : \"top-6\", vx === \"right\" ? \"right-6\" : \"left-6\", className)}\n        style={{ width: 56, height: 56, fontFamily: \"Inter, sans-serif\" }}\n        onMouseEnter={() => openOnHover && setOpen(true)}\n        onMouseLeave={() => openOnHover && setOpen(false)}\n      >\n        <ul ref={listRef} id={`${uid}-menu`} role=\"menu\" aria-label={label} className=\"m-0 list-none p-0\">\n          <AnimatePresence>\n            {open &&\n              actions.map((a, i) => {\n                const o = offset(i);\n                return (\n                  <motion.li\n                    key={a.label}\n                    role=\"none\"\n                    className=\"absolute top-1/2 left-1/2\"\n                    style={{ width: 44, height: 44, marginLeft: -22, marginTop: -22 }}\n                    initial={{ x: 0, y: 0, scale: 0.4, opacity: 0 }}\n                    animate={{ x: o.x, y: o.y, scale: 1, opacity: 1 }}\n                    exit={{ x: 0, y: 0, scale: 0.4, opacity: 0, transition: { duration: reduce ? 0 : 0.16, delay: reduce ? 0 : (actions.length - 1 - i) * 0.025 } }}\n                    transition={reduce ? { duration: 0 } : { type: \"spring\", stiffness: 520, damping: 30, delay: i * 0.04 }}\n                  >\n                    <button\n                      type=\"button\"\n                      role=\"menuitem\"\n                      onClick={() => {\n                        a.onClick?.();\n                        setOpen(false);\n                      }}\n                      onKeyDown={(e) => moveFocus(e, i)}\n                      className=\"group relative flex h-full w-full cursor-pointer items-center justify-center rounded-full outline-none focus-visible:ring-2\"\n                      style={{ background: p.item, color: p.itemText, border: `1px solid ${p.border}`, boxShadow: \"0 8px 20px rgba(0,0,0,0.35)\", [\"--tw-ring-color\" as string]: p.focus }}\n                    >\n                      <Glyph icon={a.icon} />\n                      <span\n                        className={cn(\n                          \"pointer-events-none absolute rounded-md text-[12px] font-semibold whitespace-nowrap transition-opacity duration-150\",\n                          labelSide === \"left\" && \"right-full mr-3\",\n                          labelSide === \"right\" && \"left-full ml-3\",\n                          labelSide === \"top\" && \"bottom-full mb-3\",\n                          labelSide === \"bottom\" && \"top-full mt-3\",\n                          direction === \"radial\" ? \"opacity-0 group-hover:opacity-100 group-focus-visible:opacity-100\" : \"opacity-100\",\n                        )}\n                        style={{ padding: \"4px 9px\", background: p.tip, color: p.tipText }}\n                      >\n                        {a.label}\n                      </span>\n                    </button>\n                  </motion.li>\n                );\n              })}\n          </AnimatePresence>\n        </ul>\n        <motion.button\n          ref={fabRef}\n          type=\"button\"\n          aria-haspopup=\"menu\"\n          aria-expanded={open}\n          aria-controls={`${uid}-menu`}\n          aria-label={open ? `Close ${label.toLowerCase()}` : label}\n          onClick={() => setOpen((o) => !o)}\n          onKeyDown={(e) => {\n            if (open && (e.key === \"ArrowUp\" || e.key === \"ArrowDown\" || e.key === \"ArrowLeft\" || e.key === \"ArrowRight\")) {\n              e.preventDefault();\n              listRef.current?.querySelector<HTMLButtonElement>(\"button\")?.focus();\n            }\n          }}\n          className=\"relative flex h-14 w-14 cursor-pointer items-center justify-center rounded-full border-none outline-none focus-visible:ring-2 focus-visible:ring-offset-2\"\n          style={{ background: p.fab, color: p.fabText, boxShadow: \"0 12px 30px rgba(0,0,0,0.4)\", [\"--tw-ring-color\" as string]: p.focus }}\n          whileHover={reduce ? undefined : { scale: 1.05 }}\n          whileTap={{ scale: 0.93 }}\n        >\n          <motion.svg width=\"22\" height=\"22\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2.2\" strokeLinecap=\"round\" aria-hidden=\"true\" animate={{ rotate: open ? 135 : 0 }} transition={reduce ? { duration: 0 } : { type: \"spring\", stiffness: 420, damping: 22 }}>\n            <path d=\"M12 5v14M5 12h14\" />\n          </motion.svg>\n        </motion.button>\n      </div>\n    </>\n  );\n}\n\nexport default SpeedDial;\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}