{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "radix-tooltip",
  "type": "registry:ui",
  "title": "Radix Tooltip",
  "description": "A popup that displays information related to an element when the element receives keyboard focus or the mouse hovers over it.",
  "dependencies": [
    "motion",
    "radix-ui"
  ],
  "files": [
    {
      "path": "registry/radix/tooltip/index.tsx",
      "content": "'use client';\n\nimport * as React from 'react';\nimport { Tooltip as TooltipPrimitive } from 'radix-ui';\nimport { AnimatePresence, motion, type Transition } from 'motion/react';\n\nimport { cn } from '@/lib/utils';\n\ntype TooltipContextType = {\n  isOpen: boolean;\n};\n\nconst TooltipContext = React.createContext<TooltipContextType | undefined>(\n  undefined,\n);\n\nconst useTooltip = (): TooltipContextType => {\n  const context = React.useContext(TooltipContext);\n  if (!context) {\n    throw new Error('useTooltip must be used within a Tooltip');\n  }\n  return context;\n};\n\ntype Side = 'top' | 'bottom' | 'left' | 'right';\n\nconst getInitialPosition = (side: Side) => {\n  switch (side) {\n    case 'top':\n      return { y: 15 };\n    case 'bottom':\n      return { y: -15 };\n    case 'left':\n      return { x: 15 };\n    case 'right':\n      return { x: -15 };\n  }\n};\n\ntype TooltipProviderProps = React.ComponentProps<\n  typeof TooltipPrimitive.Provider\n>;\n\nfunction TooltipProvider(props: TooltipProviderProps) {\n  return <TooltipPrimitive.Provider data-slot=\"tooltip-provider\" {...props} />;\n}\n\ntype TooltipProps = React.ComponentProps<typeof TooltipPrimitive.Root>;\n\nfunction Tooltip(props: TooltipProps) {\n  const [isOpen, setIsOpen] = React.useState(\n    props?.open ?? props?.defaultOpen ?? false,\n  );\n\n  React.useEffect(() => {\n    if (props?.open !== undefined) setIsOpen(props.open);\n  }, [props?.open]);\n\n  const handleOpenChange = React.useCallback(\n    (open: boolean) => {\n      setIsOpen(open);\n      props.onOpenChange?.(open);\n    },\n    [props],\n  );\n\n  return (\n    <TooltipContext.Provider value={{ isOpen }}>\n      <TooltipPrimitive.Root\n        data-slot=\"tooltip\"\n        {...props}\n        onOpenChange={handleOpenChange}\n      />\n    </TooltipContext.Provider>\n  );\n}\n\ntype TooltipTriggerProps = React.ComponentProps<\n  typeof TooltipPrimitive.Trigger\n>;\n\nfunction TooltipTrigger(props: TooltipTriggerProps) {\n  return <TooltipPrimitive.Trigger data-slot=\"tooltip-trigger\" {...props} />;\n}\n\ntype TooltipContentProps = React.ComponentProps<\n  typeof TooltipPrimitive.Content\n> & {\n  transition?: Transition;\n  arrow?: boolean;\n};\n\nfunction TooltipContent({\n  className,\n  side = 'top',\n  sideOffset = 4,\n  transition = { type: 'spring', stiffness: 300, damping: 25 },\n  arrow = true,\n  children,\n  ...props\n}: TooltipContentProps) {\n  const { isOpen } = useTooltip();\n  const initialPosition = getInitialPosition(side);\n\n  return (\n    <AnimatePresence>\n      {isOpen && (\n        <TooltipPrimitive.Portal forceMount data-slot=\"tooltip-portal\">\n          <TooltipPrimitive.Content\n            forceMount\n            sideOffset={sideOffset}\n            className=\"z-50\"\n            {...props}\n          >\n            <motion.div\n              key=\"tooltip-content\"\n              data-slot=\"tooltip-content\"\n              initial={{ opacity: 0, scale: 0, ...initialPosition }}\n              animate={{ opacity: 1, scale: 1, x: 0, y: 0 }}\n              exit={{ opacity: 0, scale: 0, ...initialPosition }}\n              transition={transition}\n              className={cn(\n                'relative bg-primary text-primary-foreground shadow-md w-fit origin-(--radix-tooltip-content-transform-origin) rounded-md px-3 py-1.5 text-sm text-balance',\n                className,\n              )}\n            >\n              {children}\n\n              {arrow && (\n                <TooltipPrimitive.Arrow\n                  data-slot=\"tooltip-content-arrow\"\n                  className=\"bg-primary fill-primary z-50 size-2.5 translate-y-[calc(-50%-2px)] rotate-45 rounded-[2px]\"\n                />\n              )}\n            </motion.div>\n          </TooltipPrimitive.Content>\n        </TooltipPrimitive.Portal>\n      )}\n    </AnimatePresence>\n  );\n}\n\nexport {\n  Tooltip,\n  TooltipTrigger,\n  TooltipContent,\n  TooltipProvider,\n  useTooltip,\n  type TooltipContextType,\n  type TooltipProps,\n  type TooltipTriggerProps,\n  type TooltipContentProps,\n  type TooltipProviderProps,\n};\n",
      "type": "registry:ui",
      "target": "components/animate-ui/radix/tooltip.tsx"
    }
  ]
}