{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"tooltip","type":"registry:block","title":"Tooltip","description":"A selection toolbar whose tooltips spring from each action's edge, with shortcuts, focus support and an Escape dismissal.","dependencies":["motion","lucide-react"],"registryDependencies":["utils"],"files":[{"path":"registry/prequel/tooltip/tooltip.tsx","type":"registry:component","content":"\"use client\";\n\nimport { Fragment, useId, useRef, useState } from \"react\";\nimport {\n  AnimatePresence,\n  MotionConfig,\n  motion,\n  useInView,\n} from \"motion/react\";\nimport {\n  Bold,\n  Command,\n  Italic,\n  Link2,\n  MessageSquare,\n  Undo2,\n  type LucideIcon,\n} from \"lucide-react\";\nimport { cn } from \"@/lib/utils\";\n\nconst EASE: [number, number, number, number] = [0.22, 1, 0.36, 1];\n\n/* ------------------------------------------------------------------ */\n/* types                                                               */\n/* ------------------------------------------------------------------ */\n\nexport type TooltipAction = {\n  id: string;\n  /** Short label shown inside the tooltip. */\n  label: string;\n  /** Keyboard hint, e.g. \"⌘B\". */\n  shortcut?: string;\n  icon?: LucideIcon;\n};\n\nexport type TooltipProps = {\n  className?: string;\n  title?: string;\n  description?: string;\n  actions?: TooltipAction[];\n  /** Which side of each action the tooltip grows from. Defaults to \"top\". */\n  side?: \"top\" | \"bottom\";\n};\n\n/* ------------------------------------------------------------------ */\n/* demo data                                                           */\n/* ------------------------------------------------------------------ */\n\nconst DEFAULT_ACTIONS: TooltipAction[] = [\n  { id: \"bold\", label: \"Bold\", shortcut: \"⌘B\", icon: Bold },\n  { id: \"italic\", label: \"Italic\", shortcut: \"⌘I\", icon: Italic },\n  { id: \"link\", label: \"Add link\", shortcut: \"⌘K\", icon: Link2 },\n  { id: \"comment\", label: \"Comment\", shortcut: \"⌘M\", icon: MessageSquare },\n  { id: \"undo\", label: \"Undo\", shortcut: \"⌘Z\", icon: Undo2 },\n];\n\n/* ------------------------------------------------------------------ */\n/* block                                                               */\n/* ------------------------------------------------------------------ */\n\nexport function Tooltip({\n  className,\n  title = \"Quick actions\",\n  description = \"Format the selected sentence without leaving the keyboard.\",\n  actions = DEFAULT_ACTIONS,\n  side = \"top\",\n}: TooltipProps) {\n  const ref = useRef<HTMLDivElement | null>(null);\n  const uid = useId().replace(/:/g, \"\");\n  const inView = useInView(ref, { once: true, margin: \"-10% 0px\" });\n\n  const [hovered, setHovered] = useState<string | null>(null);\n  const [focused, setFocused] = useState<string | null>(null);\n  const [status, setStatus] = useState(\"Selection · 38 words\");\n\n  const active = hovered ?? focused;\n  const safeActions = actions.length > 0 ? actions : DEFAULT_ACTIONS;\n\n  return (\n    <MotionConfig reducedMotion=\"user\">\n      <motion.div\n        ref={ref}\n        initial={{ opacity: 0, y: 16 }}\n        animate={inView ? { opacity: 1, y: 0 } : { opacity: 0, y: 16 }}\n        transition={{ duration: 0.6, ease: EASE }}\n        className={cn(\n          \"w-full rounded-xl border border-border bg-card p-5 text-card-foreground sm:p-6\",\n          className\n        )}\n      >\n        <div className=\"flex flex-wrap items-start justify-between gap-x-4 gap-y-2\">\n          <div className=\"min-w-0\">\n            <h2 className=\"text-[15px] font-semibold tracking-[-0.01em]\">\n              {title}\n            </h2>\n            <p className=\"mt-0.5 text-[12.5px] leading-relaxed text-muted-foreground\">\n              {description}\n            </p>\n          </div>\n          <span className=\"flex flex-none items-center gap-1.5 rounded-md border border-border px-2 py-1 text-[11px] text-muted-foreground\">\n            <span className=\"h-1.5 w-1.5 rounded-full bg-success\" aria-hidden=\"true\" />\n            Draft saved\n          </span>\n        </div>\n\n        <div className=\"mt-5 rounded-lg border border-border bg-muted/30 p-4\">\n          <div className=\"flex flex-wrap items-center justify-between gap-x-4 gap-y-1 text-[11.5px] text-muted-foreground\">\n            <span>Inventory memo · Q4</span>\n            <span className=\"tabular-nums\">Edited 4 min ago</span>\n          </div>\n\n          <p className=\"mt-3 text-[13.5px] leading-relaxed text-muted-foreground\">\n            We are moving the warehouse cut-off to{\" \"}\n            <span className=\"rounded bg-muted px-1 py-0.5 font-medium text-foreground\">\n              Thursday, 18:00\n            </span>{\" \"}\n            so the December batch clears before the holiday window.\n          </p>\n\n          <div className=\"mt-4 flex flex-wrap items-center gap-2\">\n            <div\n              role=\"toolbar\"\n              aria-label=\"Selection actions\"\n              className=\"inline-flex items-center gap-0.5 rounded-lg border border-border bg-card p-1 shadow-sm\"\n            >\n              {safeActions.map((action, index) => {\n                const Icon = action.icon ?? Command;\n                const visible = active === action.id;\n                const tipId = `${uid}-${action.id}-tip`;\n\n                return (\n                  <Fragment key={action.id}>\n                    {index === 3 ? (\n                      <span\n                        aria-hidden=\"true\"\n                        className=\"mx-1 h-5 w-px self-center bg-border\"\n                      />\n                    ) : null}\n                    <span className=\"relative inline-flex\">\n                    <button\n                      type=\"button\"\n                      aria-label={action.label}\n                      aria-describedby={visible ? tipId : undefined}\n                      onPointerEnter={() => setHovered(action.id)}\n                      onPointerLeave={() => setHovered(null)}\n                      onFocus={() => setFocused(action.id)}\n                      onBlur={() => setFocused(null)}\n                      onKeyDown={(event) => {\n                        if (event.key === \"Escape\") {\n                          event.currentTarget.blur();\n                        }\n                      }}\n                      onClick={() => setStatus(`${action.label} applied`)}\n                      className=\"grid h-8 w-8 place-items-center rounded-md text-muted-foreground transition-[background-color,color,transform] duration-150 hover:bg-muted hover:text-foreground active:scale-95 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring\"\n                    >\n                      <Icon className=\"h-4 w-4\" aria-hidden=\"true\" />\n                    </button>\n\n                    <AnimatePresence>\n                      {visible ? (\n                        <span\n                          className={cn(\n                            \"pointer-events-none absolute left-1/2 z-30 -translate-x-1/2\",\n                            side === \"top\"\n                              ? \"bottom-full mb-2\"\n                              : \"top-full mt-2\"\n                          )}\n                        >\n                          <motion.span\n                            role=\"tooltip\"\n                            id={tipId}\n                            initial={{\n                              opacity: 0,\n                              scale: 0.82,\n                              y: side === \"top\" ? 4 : -4,\n                            }}\n                            animate={{ opacity: 1, scale: 1, y: 0 }}\n                            exit={{\n                              opacity: 0,\n                              scale: 0.9,\n                              y: side === \"top\" ? 2 : -2,\n                            }}\n                            transition={{\n                              type: \"spring\",\n                              stiffness: 480,\n                              damping: 32,\n                              mass: 0.6,\n                            }}\n                            style={{\n                              transformOrigin:\n                                side === \"top\" ? \"50% 100%\" : \"50% 0%\",\n                            }}\n                            className=\"flex items-center gap-1.5 whitespace-nowrap rounded-md border border-border bg-foreground px-2.5 py-1.5 text-[11.5px] font-medium text-background shadow-lg\"\n                          >\n                            {action.label}\n                            {action.shortcut ? (\n                              <kbd className=\"rounded border border-background/25 px-1 py-px font-sans text-[10px] font-normal text-background/70\">\n                                {action.shortcut}\n                              </kbd>\n                            ) : null}\n                          </motion.span>\n                        </span>\n                      ) : null}\n                    </AnimatePresence>\n                    </span>\n                  </Fragment>\n                );\n              })}\n            </div>\n\n            <span className=\"text-[11.5px] text-muted-foreground\" aria-live=\"polite\">\n              {status}\n            </span>\n          </div>\n        </div>\n\n        <div className=\"mt-4 flex flex-wrap items-center justify-between gap-x-4 gap-y-1 text-[11.5px] text-muted-foreground\">\n          <span>Shortcuts match the desktop editor.</span>\n          <span>\n            <kbd className=\"rounded border border-border px-1 py-px text-[10px]\">Tab</kbd>{\" \"}\n            to focus ·{\" \"}\n            <kbd className=\"rounded border border-border px-1 py-px text-[10px]\">Esc</kbd>{\" \"}\n            to dismiss\n          </span>\n        </div>\n      </motion.div>\n    </MotionConfig>\n  );\n}\n\nexport default Tooltip;\n"}]}