{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "tooltip",
  "title": "Tooltip",
  "author": "zyx1121 (https://github.com/zyx1121)",
  "description": "Short lowercase label in a small window on hover or focus.",
  "dependencies": [
    "@base-ui/react",
    "cn"
  ],
  "registryDependencies": [
    "https://ui.zyx.tw/r/utils.json",
    "https://ui.zyx.tw/r/frame.json"
  ],
  "files": [
    {
      "path": "registry/zyx/components/ui/tooltip.tsx",
      "content": "\"use client\"\n\nimport { Tooltip as TooltipPrimitive } from \"@base-ui/react/tooltip\"\n\nimport { cn } from \"../../lib/utils\"\nimport { FrameEdges } from \"./frame\"\n\nfunction TooltipProvider({\n  delay = 0,\n  ...props\n}: TooltipPrimitive.Provider.Props) {\n  return (\n    <TooltipPrimitive.Provider\n      data-slot=\"tooltip-provider\"\n      delay={delay}\n      {...props}\n    />\n  )\n}\n\nfunction Tooltip({ ...props }: TooltipPrimitive.Root.Props) {\n  return <TooltipPrimitive.Root data-slot=\"tooltip\" {...props} />\n}\n\nfunction TooltipTrigger({ ...props }: TooltipPrimitive.Trigger.Props) {\n  return <TooltipPrimitive.Trigger data-slot=\"tooltip-trigger\" {...props} />\n}\n\n// Where a line of words has its ink. A line box keeps room above for tall\n// letters and below for descenders; words that use neither, such as \"zyx\",\n// would sit low in it. The four edges trim the box to what the words really\n// fill: from cap height when a letter is tall, else from x-height, and down\n// to the descender when a letter has one, else to the baseline. The tooltip\n// shows its words in lowercase, so only the lowercase shapes count.\nconst TALL = /[bdfhijklt0-9]/\nconst DESCENDER = /[gjpqy]/\nfunction inkEdges(words: string) {\n  const text = words.toLowerCase()\n  // Latin only: other scripts have their own proportions and keep the line box.\n  if (/[^ -\\u024f]/.test(text)) return undefined\n  const tall = TALL.test(text)\n  const low = DESCENDER.test(text)\n  if (tall && low) return \"[text-box:trim-both_cap_text]\"\n  if (tall) return \"[text-box:trim-both_cap_alphabetic]\"\n  if (low) return \"[text-box:trim-both_ex_text]\"\n  return \"[text-box:trim-both_ex_alphabetic]\"\n}\n\n// A small terminal window, opaque and outlined like every layer-2 window, in\n// lowercase like a shell. No arrow. Plain words are centered by their ink\n// (inkEdges), so the space above and below them is the same.\nfunction TooltipContent({\n  className,\n  side = \"top\",\n  sideOffset = 8,\n  align = \"center\",\n  alignOffset = 0,\n  children,\n  ...props\n}: TooltipPrimitive.Popup.Props &\n  Pick<\n    TooltipPrimitive.Positioner.Props,\n    \"align\" | \"alignOffset\" | \"side\" | \"sideOffset\"\n  >) {\n  return (\n    <TooltipPrimitive.Portal>\n      <TooltipPrimitive.Positioner\n        align={align}\n        alignOffset={alignOffset}\n        side={side}\n        sideOffset={sideOffset}\n        className=\"isolate z-50\"\n      >\n        <TooltipPrimitive.Popup\n          data-slot=\"tooltip-content\"\n          className={cn(\n            \"relative z-50 inline-flex min-h-10 w-fit max-w-xs origin-(--transform-origin) items-center rounded-control bg-background px-3 py-3 text-body text-foreground lowercase shadow-window duration-overlay data-instant:animate-none data-open:animate-in data-open:fade-in-0 data-open:zoom-in-96 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-96\",\n            className\n          )}\n          {...props}\n        >\n          {typeof children === \"string\" ? (\n            <span className={cn(\"block\", inkEdges(children))}>{children}</span>\n          ) : (\n            children\n          )}\n          <FrameEdges />\n        </TooltipPrimitive.Popup>\n      </TooltipPrimitive.Positioner>\n    </TooltipPrimitive.Portal>\n  )\n}\n\nexport { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger }\n",
      "type": "registry:ui"
    }
  ],
  "meta": {
    "useWhen": "A short lowercase label for an icon or a corner link.",
    "notFor": "Content people need to read; put it on the page.",
    "related": [
      "popover"
    ]
  },
  "docs": "Use when: A short lowercase label for an icon or a corner link.\nNot for: Content people need to read; put it on the page.\nGuide: https://ui.zyx.tw/tooltip.md",
  "categories": [
    "overlay"
  ],
  "type": "registry:ui"
}