{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"key-facts","type":"registry:ui","title":"Key facts","description":"Property key facts row with icons and numbers that count up when scrolled into view.","dependencies":["lucide-react","motion"],"registryDependencies":["utils"],"files":[{"path":"registry/items/key-facts/key-facts.tsx","type":"registry:ui","target":"components/facade/key-facts.tsx","content":"\"use client\";\n\nimport * as React from \"react\";\nimport { animate, useInView, useReducedMotion } from \"motion/react\";\nimport { Bath, BedDouble, Calendar, DollarSign, Ruler, Trees, type LucideIcon } from \"lucide-react\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface KeyFact {\n  label: string;\n  value: number;\n  icon?: LucideIcon;\n  prefix?: string;\n  suffix?: string;\n  /** Decimal places to show. */\n  decimals?: number;\n  /** Disable thousands separators (useful for years). */\n  noGrouping?: boolean;\n  /** Use compact notation, e.g. 1.25M. */\n  compact?: boolean;\n}\n\nexport interface KeyFactsProps {\n  facts?: KeyFact[];\n  /** Duration of the count-up in seconds. */\n  duration?: number;\n  className?: string;\n}\n\nconst defaultFacts: KeyFact[] = [\n  { label: \"List price\", value: 1250000, icon: DollarSign, prefix: \"$\", compact: true, decimals: 2 },\n  { label: \"Bedrooms\", value: 4, icon: BedDouble },\n  { label: \"Bathrooms\", value: 3.5, icon: Bath, decimals: 1 },\n  { label: \"Interior\", value: 3120, icon: Ruler, suffix: \" sqft\" },\n  { label: \"Lot size\", value: 0.34, icon: Trees, suffix: \" ac\", decimals: 2 },\n  { label: \"Year built\", value: 2019, icon: Calendar, noGrouping: true },\n];\n\ntype FormatOptions = Pick<KeyFact, \"value\" | \"decimals\" | \"compact\" | \"noGrouping\">;\n\nfunction format(fact: FormatOptions, n: number) {\n  if (fact.compact && Math.abs(fact.value) >= 1000) {\n    const abs = Math.abs(fact.value);\n    const div = abs >= 1_000_000 ? 1_000_000 : 1000;\n    const unit = abs >= 1_000_000 ? \"M\" : \"K\";\n    const scaled = n / div;\n    return `${scaled.toLocaleString(\"en-US\", {\n      minimumFractionDigits: fact.decimals ?? 0,\n      maximumFractionDigits: fact.decimals ?? 0,\n    })}${unit}`;\n  }\n  return n.toLocaleString(\"en-US\", {\n    minimumFractionDigits: fact.decimals ?? 0,\n    maximumFractionDigits: fact.decimals ?? 0,\n    useGrouping: !fact.noGrouping,\n  });\n}\n\nfunction CountUp({ fact, start, duration }: { fact: KeyFact; start: boolean; duration: number }) {\n  const reduce = useReducedMotion();\n  const ref = React.useRef<HTMLSpanElement>(null);\n  const { value, decimals, compact, noGrouping } = fact;\n  const from = noGrouping ? Math.round(value * 0.97) : 0;\n\n  React.useEffect(() => {\n    const el = ref.current;\n    if (!el) return;\n    const opts: FormatOptions = { value, decimals, compact, noGrouping };\n    if (!start) {\n      el.textContent = format(opts, from);\n      return;\n    }\n    if (reduce) {\n      el.textContent = format(opts, value);\n      return;\n    }\n    const controls = animate(from, value, {\n      duration,\n      ease: [0.16, 1, 0.3, 1],\n      onUpdate: (v) => {\n        const factor = Math.pow(10, decimals ?? 0);\n        el.textContent = format(opts, compact ? v : Math.round(v * factor) / factor);\n      },\n    });\n    return () => controls.stop();\n  }, [start, reduce, value, decimals, compact, noGrouping, from, duration]);\n\n  return (\n    <span className=\"whitespace-nowrap tabular-nums\">\n      {fact.prefix}\n      <span ref={ref}>{format(fact, from)}</span>\n      {fact.suffix && <span className=\"text-[0.55em] font-medium text-muted-foreground\">{fact.suffix}</span>}\n    </span>\n  );\n}\n\nexport function KeyFacts({ facts = defaultFacts, duration = 1.4, className }: KeyFactsProps) {\n  const ref = React.useRef<HTMLDListElement>(null);\n  const inView = useInView(ref, { once: true, margin: \"-60px 0px\" });\n\n  return (\n    <dl\n      ref={ref}\n      className={cn(\n        \"grid w-full grid-cols-2 gap-x-4 gap-y-8 rounded-[28px] bg-muted px-6 py-7 text-foreground sm:grid-cols-3 sm:px-8 sm:py-8 lg:grid-cols-6\",\n        className,\n      )}\n    >\n      {facts.map((f) => {\n        const Icon = f.icon;\n        return (\n          <div key={f.label} className=\"flex min-w-0 flex-col gap-2\">\n            <dt className=\"flex items-center gap-1.5 text-[13px] text-muted-foreground\">\n              {Icon && <Icon className=\"size-3.5 shrink-0\" aria-hidden=\"true\" />}\n              <span className=\"truncate\">{f.label}</span>\n            </dt>\n            <dd className=\"font-display text-[26px] font-semibold leading-none tracking-[-0.03em] text-foreground\">\n              <CountUp fact={f} start={inView} duration={duration} />\n            </dd>\n          </div>\n        );\n      })}\n    </dl>\n  );\n}\n\nexport default KeyFacts;\n"}],"categories":["data"],"meta":{"tier":"free","demo":"import { Bath, BedDouble, Calendar, DollarSign, Ruler, Trees } from \"lucide-react\";\nimport { KeyFacts } from \"./key-facts\";\n\nexport default function Demo() {\n  return (\n    <div className=\"w-full max-w-[880px]\">\n      <div className=\"mb-5 flex flex-wrap items-end justify-between gap-2 px-1\">\n        <div>\n          <p className=\"text-xs font-medium uppercase tracking-wider text-muted-foreground\">Just listed</p>\n          <p className=\"mt-1 font-display text-xl font-semibold tracking-[-0.02em] text-foreground\">4417 Wildflower Ridge</p>\n          <p className=\"text-sm text-muted-foreground\">Boulder, CO 80301, single family home</p>\n        </div>\n        <p className=\"text-sm text-muted-foreground\">MLS 1048327</p>\n      </div>\n      <KeyFacts\n        facts={[\n          { label: \"List price\", value: 1_485_000, icon: DollarSign, prefix: \"$\", compact: true, decimals: 2 },\n          { label: \"Bedrooms\", value: 4, icon: BedDouble },\n          { label: \"Bathrooms\", value: 3.5, icon: Bath, decimals: 1 },\n          { label: \"Interior\", value: 3_264, icon: Ruler, suffix: \" sqft\" },\n          { label: \"Lot size\", value: 0.42, icon: Trees, suffix: \" ac\", decimals: 2 },\n          { label: \"Year built\", value: 2021, icon: Calendar, noGrouping: true },\n        ]}\n      />\n    </div>\n  );\n}\n"}}