{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"micro-stat","title":"Micro stat","description":"The figures under a chart: a change indicator (\"vs LY ▲6.2%\") toned by whether up is good or bad, and a labelled figure (\"OTB $42k\"), each explained in a tooltip.","registryDependencies":["tooltip","https://ui.twelfth.ai/r/market-side.json"],"files":[{"path":"src/registry/catman/ui/micro-stat.tsx","content":"\"use client\"\n\nimport type { ReactNode } from \"react\"\n\nimport { Tooltip, TooltipContent, TooltipTrigger } from \"@/components/ui/tooltip\"\nimport { cn } from \"@/lib/utils\"\n\n/**\n * The small figures that sit under or beside a chart.\n *\n * `ChangeIndicator` is a movement with its direction and its verdict:\n * \"vs LY ▲6.2%\" in the favourable tone, \"MAPE ▲7 pts\" in the exposed one,\n * \"flat\" inside the noise. You say whether up is good.\n *\n * `MicroStat` is a labelled figure, \"OTB $42k\", with the sentence that\n * explains it in a tooltip.\n *\n * Part of the twelfth catman registry (`@twelfth/micro-stat`).\n */\n\nfunction Hint({ hint, children, className }: { hint?: ReactNode; children: ReactNode; className?: string }) {\n  if (!hint) return <span className={className}>{children}</span>\n  return (\n    <Tooltip>\n      <TooltipTrigger\n        delay={150}\n        render={<span tabIndex={0} />}\n        className={cn(\"cursor-help rounded-sm underline decoration-dotted decoration-from-font underline-offset-2 outline-none transition-colors hover:decoration-solid focus-visible:ring-2 focus-visible:ring-ring\", className)}\n      >\n        {children}\n      </TooltipTrigger>\n      <TooltipContent side=\"top\" className=\"max-w-56 text-xs\">{hint}</TooltipContent>\n    </Tooltip>\n  )\n}\n\nexport function ChangeIndicator({\n  value,\n  label,\n  higherIs,\n  format = (magnitude) => magnitude.toLocaleString(\"en-AU\", { maximumFractionDigits: 1 }),\n  flatWithin = 0,\n  strongAt,\n  hint,\n  className,\n}: {\n  /** Signed change; null renders nothing. */\n  value: number | null\n  /** What moved, e.g. \"vs LY\" or \"MAPE\". */\n  label?: string\n  /** Whether a rise is good news (sales, sell-through) or bad (forecast error, aged stock). */\n  higherIs: \"better\" | \"worse\"\n  /** Formats the size of the change, e.g. \"6.2%\" or \"3.2 pts\". */\n  format?: (magnitude: number) => string\n  /** Changes this small read \"flat\". */\n  flatWithin?: number\n  /** A worsening at least this large is set heavier, so it reads first. */\n  strongAt?: number\n  /** Explains how the change was measured. */\n  hint?: ReactNode\n  className?: string\n}) {\n  if (value === null || !Number.isFinite(value)) return null\n  const prefix = label ? `${label} ` : \"\"\n  if (Math.abs(value) <= flatWithin) {\n    return <Hint hint={hint} className={cn(\"text-muted-foreground\", className)}>{prefix}flat</Hint>\n  }\n  const worse = higherIs === \"worse\" ? value > 0 : value < 0\n  const strong = worse && strongAt !== undefined && Math.abs(value) >= strongAt\n  return (\n    <Hint\n      hint={hint}\n      className={cn(\"whitespace-nowrap tabular-nums\", worse ? \"text-exposed-foreground\" : \"text-favourable-foreground\", strong && \"rounded-sm bg-exposed px-1 font-semibold\", className)}\n    >\n      {prefix}{value > 0 ? \"▲\" : \"▼\"}{format(Math.abs(value))}\n    </Hint>\n  )\n}\n\nexport function MicroStat({ label, value, hint, className }: { label: ReactNode; value: ReactNode; hint?: ReactNode; className?: string }) {\n  return (\n    <Hint hint={hint} className={cn(\"whitespace-nowrap tabular-nums\", className)}>\n      {label} {value}\n    </Hint>\n  )\n}\n","type":"registry:ui"}],"type":"registry:ui"}