{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "stat-feature",
  "title": "Stat Feature",
  "description": "A metrics section with a concentric ring chart, a trend caption and count-up stats that enter with a blur, slide, fade or scale animation.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/stat-feature/stat-feature.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { animate, motion, useInView, useReducedMotion, type TargetAndTransition } from \"motion/react\";\nimport { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nfunction cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\nexport type StatFeatureAnimation = \"blur\" | \"slide\" | \"fade\" | \"scale\";\n\nexport interface StatFeatureRing {\n  /** 0–100. */\n  value: number;\n  color: string;\n}\n\nexport interface StatFeatureStat {\n  /** Counted up from zero; a decimal like \"4.8\" counts with one decimal, non-numeric text is shown as is. */\n  number: string;\n  suffix?: string;\n  label: string;\n}\n\nexport interface StatFeatureProps {\n  badge?: string;\n  title: string;\n  description?: string;\n  rings?: StatFeatureRing[];\n  chartCaption?: string;\n  chartSubcaption?: string;\n  showTrend?: boolean;\n  trendText?: string;\n  stats: StatFeatureStat[];\n  theme?: \"dark\" | \"light\";\n  animation?: StatFeatureAnimation;\n  /** Seconds each block takes to fade in. */\n  animationDuration?: number;\n  /** Milliseconds the numbers take to count up. */\n  countDuration?: number;\n  /** Milliseconds between the stat rows entering. */\n  staggerDelay?: number;\n  /** Replay the entrance every time the section scrolls back into view. */\n  replayOnReenter?: boolean;\n  titleSize?: number;\n  descriptionSize?: number;\n  titleFontFamily?: string;\n  uiFontFamily?: string;\n  className?: string;\n}\n\nconst THEMES = {\n  dark: { page: \"#0A0A0A\", badgeBg: \"rgba(255,255,255,0.08)\", badgeText: \"rgba(255,255,255,0.65)\", badgeBorder: \"rgba(255,255,255,0.1)\", title: \"#FFFFFF\", desc: \"rgba(255,255,255,0.5)\", statNumber: \"#FFFFFF\", statLabel: \"rgba(255,255,255,0.45)\", track: \"rgba(255,255,255,0.08)\", subcaption: \"rgba(255,255,255,0.4)\", trend: \"rgba(255,255,255,0.65)\" },\n  light: { page: \"#FFFFFF\", badgeBg: \"rgba(18,18,18,0.05)\", badgeText: \"rgba(18,18,18,0.55)\", badgeBorder: \"rgba(18,18,18,0.08)\", title: \"#121212\", desc: \"rgba(18,18,18,0.55)\", statNumber: \"#121212\", statLabel: \"rgba(18,18,18,0.5)\", track: \"rgba(18,18,18,0.08)\", subcaption: \"rgba(18,18,18,0.45)\", trend: \"rgba(18,18,18,0.65)\" },\n};\n\nconst HIDDEN: Record<StatFeatureAnimation, TargetAndTransition> = {\n  blur: { opacity: 0, y: 24, filter: \"blur(10px)\" },\n  slide: { opacity: 0, y: 32 },\n  fade: { opacity: 0 },\n  scale: { opacity: 0, scale: 0.9 },\n};\n\nconst SHOWN: Record<StatFeatureAnimation, TargetAndTransition> = {\n  blur: { opacity: 1, y: 0, filter: \"blur(0px)\" },\n  slide: { opacity: 1, y: 0 },\n  fade: { opacity: 1 },\n  scale: { opacity: 1, scale: 1 },\n};\n\nconst DEFAULT_RINGS: StatFeatureRing[] = [\n  { value: 88, color: \"#3B82F6\" },\n  { value: 72, color: \"#60A5FA\" },\n  { value: 55, color: \"#93C5FD\" },\n  { value: 40, color: \"#BFDBFE\" },\n];\n\nconst easeOutExpo = (t: number) => (t === 1 ? 1 : 1 - Math.pow(2, -10 * t));\n\nfunction formatCount(n: number, decimals: number | null) {\n  return decimals !== null ? n.toFixed(decimals) : String(Math.round(n));\n}\n\nfunction CountUp({ value, start, delay, duration, reduce, className, style }: { value: string; start: boolean; delay: number; duration: number; reduce: boolean; className?: string; style?: React.CSSProperties }) {\n  const ref = React.useRef<HTMLSpanElement>(null);\n  const target = parseFloat(value);\n  const decimals = value.includes(\".\") ? value.split(\".\")[1].length : null;\n  const numeric = !Number.isNaN(target);\n\n  React.useEffect(() => {\n    const el = ref.current;\n    if (!el || !numeric) return;\n    if (reduce) {\n      el.textContent = formatCount(target, decimals);\n      return;\n    }\n    if (!start) {\n      el.textContent = formatCount(0, decimals);\n      return;\n    }\n    const controls = animate(0, target, {\n      duration: duration / 1000,\n      delay: delay / 1000,\n      ease: easeOutExpo,\n      onUpdate: (v) => {\n        el.textContent = formatCount(v, decimals);\n      },\n    });\n    return () => controls.stop();\n  }, [start, target, decimals, numeric, duration, delay, reduce]);\n\n  return (\n    <span ref={ref} className={className} style={style}>\n      {numeric ? formatCount(0, decimals) : value}\n    </span>\n  );\n}\n\nfunction ConcentricChart({ rings, trackColor, show, reduce, label }: { rings: StatFeatureRing[]; trackColor: string; show: boolean; reduce: boolean; label: string }) {\n  const uid = React.useId();\n  const size = 280;\n  const center = size / 2;\n  const maxRadius = size / 2 - 12;\n  const strokeWidth = 14;\n  const gap = 10;\n  const summary = rings.map((r, i) => `Ring ${i + 1}: ${r.value}%`).join(\". \");\n\n  return (\n    <svg viewBox={`0 0 ${size} ${size}`} role=\"img\" aria-labelledby={`${uid}-t ${uid}-d`} className=\"block h-auto w-[240px] @[720px]:w-[280px]\">\n      <title id={`${uid}-t`}>{label || \"Performance chart\"}</title>\n      <desc id={`${uid}-d`}>{summary}</desc>\n      {rings.map((ring, i) => {\n        const radius = maxRadius - i * (strokeWidth + gap);\n        const progress = Math.min(Math.max(ring.value, 0), 100) / 100;\n        return (\n          <g key={i} transform={`rotate(-90 ${center} ${center})`}>\n            <circle cx={center} cy={center} r={radius} fill=\"none\" stroke={trackColor} strokeWidth={strokeWidth} />\n            <motion.circle\n              cx={center}\n              cy={center}\n              r={radius}\n              fill=\"none\"\n              stroke={ring.color}\n              strokeWidth={strokeWidth}\n              strokeLinecap=\"round\"\n              initial={reduce ? false : { pathLength: 0, opacity: 0 }}\n              animate={show || reduce ? { pathLength: progress, opacity: 1 } : { pathLength: 0, opacity: 0 }}\n              transition={{ duration: 1.4, delay: 0.22, ease: [0.33, 1, 0.68, 1] }}\n            />\n          </g>\n        );\n      })}\n      <circle cx={center} cy={center} r={18} fill={rings[rings.length - 1]?.color ?? \"#60A5FA\"} opacity={0.9} />\n    </svg>\n  );\n}\n\nexport function StatFeature({\n  badge,\n  title,\n  description,\n  rings = DEFAULT_RINGS,\n  chartCaption,\n  chartSubcaption,\n  showTrend = true,\n  trendText,\n  stats,\n  theme = \"dark\",\n  animation = \"blur\",\n  animationDuration = 1.5,\n  countDuration = 2200,\n  staggerDelay = 140,\n  replayOnReenter = false,\n  titleSize = 44,\n  descriptionSize = 16,\n  titleFontFamily = \"Georgia, 'Times New Roman', serif\",\n  uiFontFamily = \"'Helvetica Neue', Helvetica, Arial, sans-serif\",\n  className,\n}: StatFeatureProps) {\n  const t = THEMES[theme];\n  const uid = React.useId();\n  const reduce = useReducedMotion() ?? false;\n  const rootRef = React.useRef<HTMLElement>(null);\n  const inView = useInView(rootRef, { once: !replayOnReenter, amount: 0.15 });\n  const active = inView || reduce;\n\n  const reveal = (delayMs: number) =>\n    reduce\n      ? { initial: false as const }\n      : {\n          initial: HIDDEN[animation],\n          animate: active ? SHOWN[animation] : HIDDEN[animation],\n          transition: { duration: animationDuration, ease: [0.16, 1, 0.3, 1] as const, delay: delayMs / 1000 },\n        };\n\n  const vars = { [\"--sf-title\" as string]: `${titleSize}px`, [\"--sf-desc\" as string]: `${descriptionSize}px` } as React.CSSProperties;\n\n  return (\n    <section ref={rootRef} aria-labelledby={`${uid}-title`} className={cn(\"@container w-full\", className)} style={{ background: t.page, fontFamily: uiFontFamily, ...vars }}>\n      {/* Remounting on animation change replays the whole entrance with the new style. */}\n      <div key={animation} className=\"flex flex-col items-center gap-10 px-4 py-8 @[720px]:gap-14 @[720px]:px-6 @[720px]:pt-[39px] @[720px]:pb-12\">\n        <motion.header {...reveal(60)} className=\"flex max-w-[640px] flex-col items-center gap-3.5 text-center\">\n          {badge && (\n            <p className=\"m-0 rounded-full px-3.5 py-[5px] text-[11px] leading-[1.3] font-semibold tracking-[0.1em] uppercase\" style={{ background: t.badgeBg, border: `1px solid ${t.badgeBorder}`, color: t.badgeText }}>\n              {badge}\n            </p>\n          )}\n          <h2\n            id={`${uid}-title`}\n            className=\"m-0 leading-[1.15] font-medium tracking-[-0.03em] [font-size:max(28px,calc(var(--sf-title)*0.7))] @[720px]:[font-size:var(--sf-title)]\"\n            style={{ fontFamily: titleFontFamily, color: t.title }}\n          >\n            {title}\n          </h2>\n          {description && (\n            <p className=\"m-0 max-w-[480px] leading-[1.6] [font-size:max(14px,calc(var(--sf-desc)*0.92))] @[720px]:[font-size:var(--sf-desc)]\" style={{ color: t.desc }}>\n              {description}\n            </p>\n          )}\n        </motion.header>\n\n        <div className=\"grid w-full max-w-[900px] grid-cols-1 items-center gap-12 @[720px]:grid-cols-[1.1fr_0.9fr] @[720px]:gap-16\">\n          <motion.figure {...reveal(220)} className=\"m-0 flex flex-col items-center gap-5\">\n            <ConcentricChart rings={rings} trackColor={t.track} show={active} reduce={reduce} label={chartCaption ?? title} />\n            <figcaption className=\"text-center\">\n              {showTrend && trendText && (\n                <p className=\"m-0 text-[14px] leading-[1.4] font-medium\" style={{ color: t.trend }}>\n                  {trendText} <span aria-hidden=\"true\">{\"\\u2197\"}</span>\n                </p>\n              )}\n              {(chartCaption || chartSubcaption) && (\n                <p className=\"m-0 text-[13px] leading-[1.4]\" style={{ color: t.subcaption }}>\n                  {[chartCaption, chartSubcaption].filter(Boolean).join(\" \\u00b7 \")}\n                </p>\n              )}\n            </figcaption>\n          </motion.figure>\n\n          <ul className=\"m-0 flex list-none flex-col gap-9 p-0\">\n            {stats.map((stat, i) => {\n              const delay = 380 + i * staggerDelay;\n              return (\n                <motion.li key={stat.label} {...reveal(delay)} className=\"flex flex-col gap-1.5\">\n                  <div className=\"flex items-baseline gap-0.5\">\n                    <CountUp\n                      value={stat.number}\n                      start={active}\n                      delay={delay}\n                      duration={countDuration}\n                      reduce={reduce}\n                      className=\"text-[36px] leading-none font-medium tracking-[-0.03em] @[720px]:text-[42px]\"\n                      style={{ fontFamily: titleFontFamily, color: t.statNumber, fontVariantNumeric: \"tabular-nums\" }}\n                    />\n                    {stat.suffix && (\n                      <span className=\"text-[22px] leading-none @[720px]:text-[26px]\" style={{ fontFamily: titleFontFamily, color: t.statNumber, opacity: 0.85 }}>\n                        {stat.suffix}\n                      </span>\n                    )}\n                  </div>\n                  <p className=\"m-0 text-[15px] leading-[1.4]\" style={{ color: t.statLabel }}>{stat.label}</p>\n                </motion.li>\n              );\n            })}\n          </ul>\n        </div>\n      </div>\n    </section>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}