{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "stat-line",
  "title": "Stat Line",
  "description": "One line of several figures, before and after included: equal columns, a running sentence or one big number above the rest.",
  "dependencies": [
    "lucide-react",
    "motion"
  ],
  "registryDependencies": [
    "utils"
  ],
  "files": [
    {
      "path": "registry/miseui/ui/stat-line.tsx",
      "content": "import type * as React from \"react\"\nimport { ArrowRight } from \"lucide-react\"\nimport { useReducedMotion } from \"motion/react\"\nimport { CountFigure } from \"@/registry/miseui/ui/stat-line-count\"\nimport { cn } from \"@/registry/miseui/lib/utils\"\n\ntype StatLineVariant = \"divided\" | \"run\" | \"lead\"\ntype StatLineEffect = \"count-up\"\n\ninterface StatLineItem {\n  label: React.ReactNode\n  /** A number can be formatted and counted; a string such as \"4m 12s\" is shown as it is. */\n  value: number | string\n  /** The value before, drawn in front of the new one: 98 to 50. */\n  from?: number\n  /** Written after the value, smaller. */\n  unit?: string\n}\n\nconst ROOT_CLASS: Record<StatLineVariant, string> = {\n  divided: \"grid grid-cols-2 gap-y-4 @xs:auto-cols-fr @xs:grid-flow-col @xs:grid-cols-none\",\n  run: \"flex flex-wrap items-baseline gap-x-4 gap-y-1\",\n  // auto-fit keeps the tracks explicit, which is what lets the first figure span them all at any width.\n  lead: \"grid grid-cols-[repeat(auto-fit,minmax(min(100%,7rem),1fr))] gap-4\",\n}\n\n/** A line runs between columns, never in front of the first in a row, and the row length changes with the width. */\nconst DIVIDED_ITEM = \"min-w-0 border-s ps-4 odd:border-s-0 odd:ps-0 @xs:not-first:border-s @xs:not-first:ps-4\"\n\nconst ITEM_CLASS: Record<StatLineVariant, string> = {\n  divided: cn(\"grid content-start gap-1\", DIVIDED_ITEM),\n  run: \"flex min-w-0 items-baseline gap-1\",\n  lead: \"grid min-w-0 content-start gap-1 border-t pt-4 first:col-span-full first:border-t-0 first:pt-0\",\n}\n\nconst VALUE_CLASS: Record<StatLineVariant, string> = {\n  divided: \"text-[clamp(20px,9cqi,28px)] leading-tight font-semibold tracking-tight\",\n  run: \"order-first text-[15px] leading-6 font-semibold\",\n  lead: \"text-[clamp(20px,9cqi,28px)] leading-tight font-semibold tracking-tight\",\n}\n\nconst LEAD_VALUE_CLASS = \"text-[clamp(40px,22cqi,72px)] leading-none font-semibold tracking-tighter\"\n\nconst defaultFormat = (locale?: string) => (value: number) => new Intl.NumberFormat(locale, { maximumFractionDigits: 20 }).format(value)\n\ninterface FigureProps {\n  item: StatLineItem\n  format: (value: number) => string\n  counting: boolean\n}\n\nfunction Figure({ item, format, counting }: FigureProps) {\n  const { value, from, unit } = item\n  const shown = typeof value === \"number\" ? format(value) : value\n  return (\n    <span data-slot=\"stat-line-figure\" className=\"flex min-w-0 flex-wrap items-baseline gap-x-1 tabular-nums\">\n      {from === undefined ? null : (\n        <span data-slot=\"stat-line-from\" className=\"inline-flex items-center gap-1 text-[0.6em] font-medium tracking-normal text-muted-foreground\">\n          <span>{format(from)}</span>\n          <ArrowRight aria-hidden=\"true\" className=\"size-[1em] shrink-0 rtl:rotate-180\" />\n          <span className=\"sr-only\">to</span>\n        </span>\n      )}\n      <span className=\"min-w-0 wrap-anywhere\">\n        {counting && typeof value === \"number\" ? <CountFigure from={from ?? 0} to={value} format={format} /> : shown}\n        {unit ? <span data-slot=\"stat-line-unit\" className=\"ms-0.5 text-[0.6em] font-medium tracking-normal\">{unit}</span> : null}\n      </span>\n    </span>\n  )\n}\n\ntype StatLineProps = Omit<React.ComponentProps<\"div\">, \"children\"> & {\n  items: readonly StatLineItem[]\n  /** `divided` equal columns with hairlines, `run` a sentence of figures that wraps, `lead` one big figure above the rest. */\n  variant?: StatLineVariant\n  /** `count-up` counts each number once when first seen. People who turned motion off get the final figure. */\n  effect?: StatLineEffect\n  /** Formats numeric values. Defaults to grouped digits in the given locale. */\n  format?: (value: number) => string\n  locale?: string\n}\n\nfunction StatLine({ items, variant = \"divided\", effect, format, locale, className, ...props }: StatLineProps) {\n  const reduceMotion = useReducedMotion() ?? false\n  const counting = effect === \"count-up\" && !reduceMotion\n  const toText = format ?? defaultFormat(locale)\n  return (\n    // The container is the size-aware part, so the figures fit whatever cell this is dropped in.\n    <div data-slot=\"stat-line\" data-variant={variant} data-effect={effect} className={cn(\"@container w-full min-w-0\", className)} {...props}>\n      <dl className={ROOT_CLASS[variant]}>\n        {items.map((item, index) => (\n          <div key={index} data-slot=\"stat-line-item\" className={ITEM_CLASS[variant]}>\n            <dt className=\"min-w-0 text-[13px] leading-5 text-muted-foreground\">{item.label}</dt>\n            <dd className={cn(\"min-w-0\", variant === \"lead\" && index === 0 ? LEAD_VALUE_CLASS : VALUE_CLASS[variant])}>\n              <Figure item={item} format={toText} counting={counting} />\n            </dd>\n          </div>\n        ))}\n      </dl>\n    </div>\n  )\n}\n\nexport { StatLine, type StatLineItem, type StatLineProps, type StatLineVariant, type StatLineEffect }\n",
      "type": "registry:ui"
    },
    {
      "path": "registry/miseui/ui/stat-line-count.tsx",
      "content": "import { useEffect, useRef } from \"react\"\nimport { animate, motion, useInView, useMotionValue, useTransform } from \"motion/react\"\n\n/** Long enough to be seen moving, then it settles without overshooting the real number. */\nconst COUNT_SPRING = { type: \"spring\", bounce: 0, duration: 1.2 } as const\n\nfunction decimalsIn(value: number) {\n  const text = String(value)\n  return text.includes(\".\") && !text.includes(\"e\") ? text.length - text.indexOf(\".\") - 1 : 0\n}\n\ninterface CountFigureProps {\n  /** Where the count starts: the old value of a before and after, or zero. */\n  from: number\n  to: number\n  format: (value: number) => string\n}\n\nfunction CountFigure({ from, to, format }: CountFigureProps) {\n  const ref = useRef<HTMLSpanElement>(null)\n  const seen = useInView(ref, { once: true })\n  const count = useMotionValue(from)\n  const factor = 10 ** decimalsIn(to)\n  const text = useTransform(count, (current) => format(Math.round(current * factor) / factor))\n  useEffect(() => {\n    if (!seen) return\n    const controls = animate(count, to, COUNT_SPRING)\n    return () => controls.stop()\n  }, [seen, count, to])\n  const final = format(to)\n  return (\n    <span ref={ref} data-slot=\"stat-line-count\" className=\"relative inline-block max-w-full\">\n      {/* The final text holds the width, so a figure counting up cannot push its neighbours along. */}\n      <span aria-hidden=\"true\" className=\"invisible\">\n        {final}\n      </span>\n      <motion.span aria-hidden=\"true\" data-slot=\"stat-line-count-value\" className=\"absolute inset-0\">\n        {text}\n      </motion.span>\n      <span className=\"sr-only\">{final}</span>\n    </span>\n  )\n}\n\nexport { CountFigure }\n",
      "type": "registry:ui"
    }
  ],
  "categories": [
    "display"
  ],
  "type": "registry:ui"
}