{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "toggle-price-counter",
  "title": "Toggle Price Counter",
  "description": "A monthly / yearly billing switch whose price rolls to the new amount digit by digit like an odometer, with a saving badge that pops when yearly is picked and a line that spells out what's billed and saved.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/toggle-price-counter/toggle-price-counter.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { motion, AnimatePresence, useReducedMotion } 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\n/** Rolls each digit of a formatted string like an odometer; other characters stay put. */\nexport function RollingNumber({ value, className, style }: { value: string; className?: string; style?: React.CSSProperties }) {\n  const reduce = Boolean(useReducedMotion());\n  const chars = value.split(\"\");\n  return (\n    <span className={cn(\"inline-flex tabular-nums\", className)} style={{ lineHeight: 1, ...style }}>\n      <span className=\"sr-only\">{value}</span>\n      {chars.map((c, i) => {\n        // Key from the right so digits keep their column when the length changes.\n        const key = chars.length - i;\n        if (!/\\d/.test(c)) {\n          return (\n            <span key={`s${key}`} aria-hidden=\"true\">\n              {c}\n            </span>\n          );\n        }\n        const d = Number(c);\n        return (\n          <span key={`d${key}`} aria-hidden=\"true\" className=\"relative inline-block overflow-hidden\" style={{ height: \"1em\", width: \"0.62em\" }}>\n            <motion.span className=\"absolute top-0 left-0 flex flex-col\" initial={false} animate={{ y: `${-d}em` }} transition={reduce ? { duration: 0 } : { type: \"spring\", stiffness: 180, damping: 22, delay: (chars.length - i) * 0.03 }}>\n              {Array.from({ length: 10 }, (_, n) => (\n                <span key={n} className=\"block text-center\" style={{ height: \"1em\", width: \"0.62em\" }}>\n                  {n}\n                </span>\n              ))}\n            </motion.span>\n          </span>\n        );\n      })}\n    </span>\n  );\n}\n\nexport interface TogglePriceCounterProps {\n  /** Price per month on monthly billing. */\n  monthly?: number;\n  /** Price per month on yearly billing. */\n  yearly?: number;\n  currency?: string;\n  locale?: string;\n  defaultPeriod?: \"monthly\" | \"yearly\";\n  period?: \"monthly\" | \"yearly\";\n  onPeriodChange?: (period: \"monthly\" | \"yearly\") => void;\n  /** Badge next to Yearly. Leave out to show the computed saving. */\n  discountLabel?: string;\n  theme?: \"dark\" | \"light\";\n  className?: string;\n}\n\nconst PALETTES = {\n  dark: { text: \"#F5F4F1\", muted: \"rgba(245,244,241,0.55)\", seg: \"rgba(255,255,255,0.06)\", border: \"rgba(255,255,255,0.12)\", pill: \"#F5F4F1\", pillText: \"#0A0A0A\", badge: \"#3FBF7F\", badgeText: \"#0A0A0A\", focus: \"rgba(245,244,241,0.85)\" },\n  light: { text: \"#0A0A0A\", muted: \"rgba(10,10,10,0.55)\", seg: \"rgba(10,10,10,0.05)\", border: \"rgba(10,10,10,0.12)\", pill: \"#0A0A0A\", pillText: \"#FFFFFF\", badge: \"#1F9D5C\", badgeText: \"#FFFFFF\", focus: \"rgba(10,10,10,0.85)\" },\n};\n\nexport function TogglePriceCounter({ monthly = 24, yearly = 19, currency = \"USD\", locale = \"en-US\", defaultPeriod = \"monthly\", period, onPeriodChange, discountLabel, theme = \"dark\", className }: TogglePriceCounterProps) {\n  const p = PALETTES[theme];\n  const uid = React.useId();\n  const reduce = Boolean(useReducedMotion());\n  const [internal, setInternal] = React.useState(defaultPeriod);\n  const current = period ?? internal;\n  const yearlyOn = current === \"yearly\";\n  const set = (v: \"monthly\" | \"yearly\") => {\n    if (period === undefined) setInternal(v);\n    onPeriodChange?.(v);\n  };\n\n  const fmt = new Intl.NumberFormat(locale, { style: \"currency\", currency, maximumFractionDigits: 0 });\n  const price = fmt.format(yearlyOn ? yearly : monthly);\n  const saving = discountLabel ?? `Save ${Math.round((1 - yearly / monthly) * 100)}%`;\n\n  return (\n    <div className={cn(\"flex flex-col items-center\", className)} style={{ gap: 22, fontFamily: \"Inter, sans-serif\", color: p.text }}>\n      <div role=\"radiogroup\" aria-label=\"Billing period\" className=\"relative flex items-center rounded-full\" style={{ padding: 4, gap: 2, background: p.seg, border: `1px solid ${p.border}` }}>\n        {([\"monthly\", \"yearly\"] as const).map((v) => {\n          const on = current === v;\n          return (\n            <button\n              key={v}\n              type=\"button\"\n              role=\"radio\"\n              aria-checked={on}\n              onClick={() => set(v)}\n              className=\"relative flex cursor-pointer items-center rounded-full border-none bg-transparent text-[14px] font-semibold outline-none focus-visible:ring-2\"\n              style={{ gap: 8, height: 38, padding: \"0 18px\", color: on ? p.pillText : p.muted, transition: \"color 0.2s ease\", [\"--tw-ring-color\" as string]: p.focus }}\n            >\n              {on && <motion.span layoutId={`${uid}-pill`} className=\"absolute inset-0 rounded-full\" style={{ background: p.pill }} transition={reduce ? { duration: 0 } : { type: \"spring\", stiffness: 500, damping: 36 }} />}\n              <span className=\"relative\">{v === \"monthly\" ? \"Monthly\" : \"Yearly\"}</span>\n              {v === \"yearly\" && (\n                <motion.span className=\"relative rounded-full text-[11px] font-bold\" style={{ padding: \"2px 7px\", background: p.badge, color: p.badgeText }} initial={false} animate={{ scale: yearlyOn && !reduce ? [1, 1.18, 1] : 1 }} transition={{ duration: 0.35 }}>\n                  {saving}\n                </motion.span>\n              )}\n            </button>\n          );\n        })}\n      </div>\n\n      <div className=\"flex flex-col items-center\" style={{ gap: 8 }}>\n        <div className=\"flex items-end\" style={{ gap: 8 }} aria-live=\"polite\">\n          <RollingNumber value={price} className=\"font-semibold tracking-[-0.04em]\" style={{ fontSize: 64 }} />\n          <span className=\"pb-2 text-[15px]\" style={{ color: p.muted }}>\n            / month\n          </span>\n        </div>\n        <AnimatePresence mode=\"wait\" initial={false}>\n          <motion.span key={current} className=\"text-[13px]\" style={{ color: p.muted }} initial={{ opacity: 0, y: 6 }} animate={{ opacity: 1, y: 0 }} exit={{ opacity: 0, y: -6 }} transition={{ duration: reduce ? 0 : 0.18 }}>\n            {yearlyOn ? `Billed ${fmt.format(yearly * 12)} yearly · you save ${fmt.format((monthly - yearly) * 12)}` : \"Billed monthly · cancel anytime\"}\n          </motion.span>\n        </AnimatePresence>\n      </div>\n    </div>\n  );\n}\n\nexport default TogglePriceCounter;\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}