{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "tooltip",
  "type": "registry:ui",
  "title": "Tooltip",
  "description": "A short label for a control on hover and keyboard focus, with a shortcut hint and a shared delay provider. Built on Radix Tooltip.",
  "dependencies": [
    "radix-ui@^1.6.7"
  ],
  "registryDependencies": [
    "https://ui.klarhimmel.com/r/kbd.json",
    "https://ui.klarhimmel.com/r/theme.json",
    "https://ui.klarhimmel.com/r/utils.json"
  ],
  "files": [
    {
      "path": "src/ui/tooltip.tsx",
      "type": "registry:file",
      "target": "components/klarhimmel/ui/tooltip.tsx",
      "content": "import { createContext, useContext, type ReactNode } from 'react';\nimport { Tooltip as T } from 'radix-ui';\nimport { ThemeRootScope, useThemeRoot } from '../lib/theme-root';\nimport { Kbd } from './kbd';\n\nconst ProviderCtx = createContext(false);\n\n/** Wrap a toolbar or a page once: its tooltips share one open delay, and moving between neighbours shows the next at once. */\nexport function TooltipProvider({ children, delay = 500 }: { children: ReactNode; delay?: number }) {\n  return (\n    <ProviderCtx.Provider value>\n      <T.Provider delayDuration={delay} skipDelayDuration={300} disableHoverableContent>\n        {children}\n      </T.Provider>\n    </ProviderCtx.Provider>\n  );\n}\n\nexport interface TooltipProps {\n  content: ReactNode;\n  /** A keyboard shortcut shown after the text. */\n  shortcut?: string;\n  side?: 'top' | 'right' | 'bottom' | 'left';\n  /** Milliseconds before it opens on hover. Focus opens it at once. */\n  delay?: number;\n  /** Start open (docs and screenshots). It closes on Escape or when the pointer or focus has been and gone. */\n  defaultOpen?: boolean;\n  /** The single element that gets the tooltip. It must be focusable. */\n  children: ReactNode;\n}\n\nfunction Bubble({ content, shortcut, side }: Pick<TooltipProps, 'content' | 'shortcut' | 'side'>) {\n  const root = useThemeRoot();\n  return (\n    <T.Portal container={root}>\n      <T.Content\n        side={side}\n        sideOffset={8}\n        collisionPadding={12}\n        className=\"z-50 flex max-w-64 items-center gap-2 rounded-kh bg-kh-ink px-2.5 py-1 text-kh-caption font-medium text-kh-on-ink shadow-kh-3\"\n      >\n        {content}\n        {shortcut && <Kbd className=\"border-kh-on-ink/30 bg-transparent text-kh-on-ink\">{shortcut}</Kbd>}\n        <T.Arrow className=\"fill-kh-ink\" />\n      </T.Content>\n    </T.Portal>\n  );\n}\n\n/** A short label for a control, shown on hover and on keyboard focus, dismissed with Escape. Never the only home of essential text. */\nexport function Tooltip({ content, shortcut, side = 'top', delay, defaultOpen, children }: TooltipProps) {\n  const shared = useContext(ProviderCtx);\n  const tip = (\n    <ThemeRootScope>\n      <T.Root delayDuration={delay} defaultOpen={defaultOpen}>\n        <T.Trigger asChild>{children}</T.Trigger>\n        <Bubble content={content} shortcut={shortcut} side={side} />\n      </T.Root>\n    </ThemeRootScope>\n  );\n  return shared ? tip : <TooltipProvider>{tip}</TooltipProvider>;\n}\n"
    }
  ]
}
