{"name":"tooltip-card","type":"registry:ui","files":[{"path":"tooltip-card.tsx","type":"registry:ui","content":"\"use client\";\n\nimport {\n  roundnessClass,\n  tooltipVariantClass,\n  type TooltipRoundness,\n  type TooltipVariant,\n} from \"@/components/ui/charts/tooltip\";\nimport { indicatorBackground } from \"@/components/ui/charts/chart\";\nimport { useLayoutEffect, useRef, useState, type ReactNode } from \"react\";\n\n/**\n * The chart tooltip as React markup, for charts drawn with DOM elements\n * instead of a canvas. The classes mirror `tooltipShell` and `tooltipRow`, so\n * a Tracker or Bar List tooltip is indistinguishable from an ECharts one.\n */\nexport function ChartTooltipCard({\n  label,\n  children,\n  roundness = \"lg\",\n  variant = \"default\",\n}: {\n  label?: ReactNode;\n  children: ReactNode;\n  roundness?: TooltipRoundness;\n  variant?: TooltipVariant;\n}) {\n  return (\n    <div\n      className={`grid min-w-32 items-start gap-1.5 border border-border/50 px-2.5 py-1.5 text-xs shadow-xl ${roundnessClass[roundness]} ${tooltipVariantClass[variant]}`}\n    >\n      {label != null && <div className=\"text-primary font-medium\">{label}</div>}\n      <div className=\"grid gap-1.5\">{children}</div>\n    </div>\n  );\n}\n\nexport function ChartTooltipItem({\n  dataKey,\n  colorsCount = 1,\n  label,\n  value,\n  detail,\n}: {\n  dataKey: string;\n  colorsCount?: number;\n  label: ReactNode;\n  value?: ReactNode;\n  detail?: ReactNode;\n}) {\n  return (\n    <div className=\"flex w-full flex-wrap items-center gap-2\">\n      <div\n        aria-hidden\n        className=\"h-2.5 w-2.5 shrink-0 rounded-[2px]\"\n        style={{ background: indicatorBackground(dataKey, colorsCount) }}\n      />\n      <div className=\"flex flex-1 items-center justify-between gap-4 leading-none\">\n        <span className=\"text-muted-foreground\">{label}</span>\n        {value != null && (\n          <span className=\"text-foreground font-mono font-medium tabular-nums\">{value}</span>\n        )}\n      </div>\n      {detail != null && (\n        <div className=\"text-muted-foreground basis-full pl-[18px] leading-none\">{detail}</div>\n      )}\n    </div>\n  );\n}\n\n/**\n * Places a tooltip above an anchor point inside a positioned container. Like\n * the ECharts tooltip with `confine`, it is shifted horizontally so it never\n * spills past the container's edges.\n */\nexport function FloatingChartTooltip({\n  anchor,\n  containerWidth,\n  children,\n}: {\n  /** Center x and top y of the hovered mark, relative to the container. */\n  anchor: { x: number; y: number } | null;\n  containerWidth: number;\n  children: ReactNode;\n}) {\n  const ref = useRef<HTMLDivElement>(null);\n  const [width, setWidth] = useState(0);\n\n  useLayoutEffect(() => {\n    if (!anchor || !ref.current) return;\n    const next = ref.current.offsetWidth;\n    if (next !== width) setWidth(next);\n  }, [anchor, children, width]);\n\n  if (!anchor) return null;\n  const left =\n    containerWidth > width\n      ? Math.min(Math.max(anchor.x - width / 2, 0), containerWidth - width)\n      : anchor.x - width / 2;\n\n  return (\n    <div\n      ref={ref}\n      role=\"presentation\"\n      className=\"pointer-events-none absolute z-30 w-max\"\n      style={{\n        left,\n        top: anchor.y,\n        transform: \"translateY(calc(-100% - 8px))\",\n        visibility: width ? \"visible\" : \"hidden\",\n      }}\n    >\n      {children}\n    </div>\n  );\n}\n","target":"components/ui/tooltip-card.tsx"}],"registryDependencies":["https://www.honestui.com/r/chart.json","https://www.honestui.com/r/tooltip.json"]}