{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "pricing-table",
  "type": "registry:block",
  "title": "Pricing Table",
  "description": "Three plans side by side with a monthly or yearly toggle that rolls each price into place, and a full feature table that folds out underneath.",
  "categories": [
    "block",
    "Marketing"
  ],
  "dependencies": [
    "lucide-react",
    "motion"
  ],
  "registryDependencies": [
    "utils",
    "https://coss.com/ui/r/button.json",
    "https://coss.com/ui/r/collapsible.json"
  ],
  "files": [
    {
      "path": "registry/devl/pricing-table.tsx",
      "type": "registry:component",
      "content": "\"use client\";\n\nimport { CheckIcon, ChevronDownIcon, MinusIcon, type LucideIcon } from \"lucide-react\";\nimport { motion, AnimatePresence, useReducedMotion } from \"motion/react\";\nimport { type KeyboardEvent, useRef, useState } from \"react\";\nimport { Button } from \"@/components/ui/button\";\nimport { Collapsible, CollapsiblePanel, CollapsibleTrigger } from \"@/components/ui/collapsible\";\nimport { cn } from \"@/lib/utils\";\n\nexport type Billing = \"monthly\" | \"yearly\";\n\nexport interface PricingPlan {\n  id: string;\n  name: string;\n  description: string;\n  monthly: number;\n  yearly: number;\n  cta: string;\n  icon?: LucideIcon;\n  highlights: string[];\n  featured?: boolean;\n  badge?: string;\n}\n\nexport interface PricingFeatureGroup {\n  name: string;\n  rows: { label: string; values: Record<string, boolean | string> }[];\n}\n\nexport interface PricingTableProps {\n  plans: PricingPlan[];\n  features?: PricingFeatureGroup[];\n  eyebrow?: string;\n  title?: string;\n  subtitle?: string;\n  currency?: string;\n  yearlyBadge?: string;\n  defaultBilling?: Billing;\n  onSelect?: (plan: PricingPlan, billing: Billing) => void;\n  className?: string;\n}\n\nconst springy = { type: \"spring\", stiffness: 420, damping: 40 } as const;\nconst glide = { type: \"spring\", stiffness: 520, damping: 44 } as const;\nconst press =\n  \"transition-[box-shadow,background-color,transform] duration-150 ease-out active:scale-[0.97] motion-reduce:active:scale-100\";\n\nfunction RollingDigit({ digit }: { digit: number }) {\n  const reduce = useReducedMotion();\n  return (\n    <span aria-hidden className=\"relative inline-block h-[1.1em] w-[1ch] overflow-hidden\">\n      <motion.span\n        animate={{ y: `${-digit * 1.1}em` }}\n        className=\"absolute inset-x-0 top-0 flex flex-col\"\n        initial={false}\n        transition={reduce ? { duration: 0 } : { type: \"spring\", stiffness: 300, damping: 34 }}\n      >\n        {Array.from({ length: 10 }, (_, n) => (\n          <span className=\"block h-[1.1em] leading-[1.1em]\" key={n}>\n            {n}\n          </span>\n        ))}\n      </motion.span>\n    </span>\n  );\n}\n\nfunction RollingNumber({ value, className }: { value: number; className?: string }) {\n  const text = value.toLocaleString(\"en-US\");\n  const chars = text.split(\"\");\n  return (\n    <span className={cn(\"inline-flex tabular-nums leading-[1.1em]\", className)}>\n      <span className=\"sr-only\">{text}</span>\n      {chars.map((char, i) => {\n        const key = chars.length - i;\n        return /\\d/.test(char) ? (\n          <RollingDigit digit={Number(char)} key={`d${key}`} />\n        ) : (\n          <span aria-hidden key={`s${key}`}>\n            {char}\n          </span>\n        );\n      })}\n    </span>\n  );\n}\n\nfunction BillingSwitch({\n  value,\n  onChange,\n  yearlyBadge,\n}: {\n  value: Billing;\n  onChange: (value: Billing) => void;\n  yearlyBadge?: string;\n}) {\n  const reduce = useReducedMotion();\n  const refs = useRef<(HTMLButtonElement | null)[]>([]);\n  const options: { value: Billing; label: string }[] = [\n    { value: \"monthly\", label: \"Monthly\" },\n    { value: \"yearly\", label: \"Yearly\" },\n  ];\n  const index = options.findIndex((o) => o.value === value);\n\n  const onKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {\n    if (![\"ArrowLeft\", \"ArrowRight\", \"ArrowUp\", \"ArrowDown\"].includes(event.key)) return;\n    event.preventDefault();\n    const next = index === 0 ? 1 : 0;\n    onChange(options[next].value);\n    refs.current[next]?.focus();\n  };\n\n  return (\n    <div\n      aria-label=\"Billing period\"\n      className=\"relative isolate inline-grid grid-cols-2 rounded-full border bg-muted p-1\"\n      onKeyDown={onKeyDown}\n      role=\"radiogroup\"\n    >\n      <div aria-hidden className=\"absolute inset-1 -z-10\">\n        <motion.span\n          animate={{ x: index === 0 ? \"0%\" : \"100%\" }}\n          className=\"absolute inset-y-0 left-0 w-1/2 rounded-full bg-primary shadow-xs/5\"\n          initial={false}\n          transition={reduce ? { duration: 0 } : glide}\n        />\n      </div>\n      {options.map((option, i) => {\n        const checked = option.value === value;\n        return (\n          <button\n            aria-checked={checked}\n            className={cn(\n              \"relative inline-flex h-9 cursor-pointer items-center justify-center gap-1.5 rounded-full px-5 font-medium text-sm outline-none transition-[color,transform] duration-200 ease-out focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-background\",\n              checked ? \"text-primary-foreground\" : \"text-muted-foreground hover:text-foreground\",\n              \"active:scale-[0.97] motion-reduce:active:scale-100\",\n            )}\n            key={option.value}\n            onClick={() => onChange(option.value)}\n            ref={(el) => {\n              refs.current[i] = el;\n            }}\n            role=\"radio\"\n            tabIndex={checked ? 0 : -1}\n            type=\"button\"\n          >\n            {option.label}\n            {option.value === \"yearly\" && yearlyBadge && (\n              <span\n                className={cn(\n                  \"rounded-full px-1.5 py-px font-medium text-[0.6875rem] tabular-nums transition-colors duration-200\",\n                  checked ? \"bg-primary-foreground/16 text-primary-foreground\" : \"bg-success/8 text-success-foreground\",\n                )}\n              >\n                {yearlyBadge}\n              </span>\n            )}\n          </button>\n        );\n      })}\n    </div>\n  );\n}\n\nfunction PlanCard({\n  plan,\n  billing,\n  currency,\n  featured,\n  onSelect,\n}: {\n  plan: PricingPlan;\n  billing: Billing;\n  currency: string;\n  featured: boolean;\n  onSelect?: (plan: PricingPlan, billing: Billing) => void;\n}) {\n  const reduce = useReducedMotion();\n  const price = billing === \"yearly\" ? plan.yearly : plan.monthly;\n  const saving = plan.monthly - plan.yearly;\n  const Icon = plan.icon;\n\n  return (\n    <article\n      className={cn(\n        \"relative isolate flex flex-col overflow-hidden rounded-2xl border p-6 shadow-xs/5\",\n        featured ? \"border-primary bg-primary text-primary-foreground md:-my-3 md:py-9\" : \"bg-card text-card-foreground\",\n      )}\n    >\n      {featured && (\n        <>\n          <span\n            aria-hidden\n            className=\"absolute -top-28 -right-20 -z-10 size-72 rounded-full bg-primary-foreground/16 blur-3xl\"\n          />\n          <span\n            aria-hidden\n            className=\"absolute -bottom-28 -left-20 -z-10 size-64 rounded-full bg-primary-foreground/10 blur-3xl\"\n          />\n        </>\n      )}\n      <div className=\"flex items-center gap-2.5\">\n        {Icon && (\n          <span\n            className={cn(\n              \"flex size-8 items-center justify-center rounded-lg\",\n              featured ? \"bg-primary-foreground/12\" : \"bg-muted\",\n            )}\n          >\n            <Icon className=\"size-4\" />\n          </span>\n        )}\n        <h3 className=\"font-medium text-base\">{plan.name}</h3>\n        {(plan.badge || featured) && (\n          <span\n            className={cn(\n              \"ms-auto rounded-full px-2 py-0.5 font-medium text-xs\",\n              featured ? \"bg-primary-foreground text-primary\" : \"bg-muted text-muted-foreground\",\n            )}\n          >\n            {plan.badge ?? \"Most popular\"}\n          </span>\n        )}\n      </div>\n      <p className={cn(\"mt-2 text-sm md:min-h-10\", featured ? \"text-primary-foreground/70\" : \"text-muted-foreground\")}>\n        {plan.description}\n      </p>\n\n      <div className=\"mt-6 flex items-end gap-1.5\">\n        <span className=\"flex items-start font-semibold text-4xl tracking-tight\">\n          <span className=\"me-0.5 mt-1 text-xl\">{currency}</span>\n          <RollingNumber value={price} />\n        </span>\n        <span className={cn(\"mb-1 text-sm\", featured ? \"text-primary-foreground/70\" : \"text-muted-foreground\")}>\n          /mo\n        </span>\n        <AnimatePresence initial={false}>\n          {billing === \"yearly\" && saving > 0 && (\n            <motion.span\n              animate={{ opacity: 1, scale: 1, x: 0 }}\n              className={cn(\n                \"mb-1.5 ms-1 text-sm tabular-nums line-through\",\n                featured ? \"text-primary-foreground/50\" : \"text-muted-foreground/70\",\n              )}\n              exit={{ opacity: 0, scale: 0.95, x: -4 }}\n              initial={{ opacity: 0, scale: 0.95, x: -4 }}\n              transition={springy}\n            >\n              {currency}\n              {plan.monthly}\n            </motion.span>\n          )}\n        </AnimatePresence>\n      </div>\n      <div\n        className={cn(\n          \"relative mt-1 h-4 overflow-hidden text-xs\",\n          featured ? \"text-primary-foreground/70\" : \"text-muted-foreground\",\n        )}\n      >\n        <AnimatePresence initial={false} mode=\"popLayout\">\n          <motion.p\n            animate={{ y: 0, opacity: 1 }}\n            exit={{ y: reduce ? 0 : billing === \"yearly\" ? -14 : 14, opacity: 0 }}\n            initial={{ y: reduce ? 0 : billing === \"yearly\" ? 14 : -14, opacity: 0 }}\n            key={billing}\n            transition={springy}\n          >\n            {billing === \"yearly\"\n              ? `${currency}${(plan.yearly * 12).toLocaleString(\"en-US\")} billed yearly`\n              : \"Billed monthly, cancel anytime\"}\n          </motion.p>\n        </AnimatePresence>\n      </div>\n\n      <Button\n        className={cn(\n          \"mt-6 w-full\",\n          press,\n          featured &&\n            \"border-primary-foreground bg-primary-foreground text-primary shadow-none hover:bg-primary-foreground/90\",\n        )}\n        onClick={() => onSelect?.(plan, billing)}\n        size=\"lg\"\n        variant={featured ? \"default\" : \"outline\"}\n      >\n        {plan.cta}\n      </Button>\n\n      <ul className=\"mt-6 space-y-2.5 text-sm\">\n        {plan.highlights.map((item) => (\n          <li className=\"flex gap-2.5\" key={item}>\n            <span\n              className={cn(\n                \"mt-0.5 flex size-4 shrink-0 items-center justify-center rounded-full\",\n                featured ? \"bg-primary-foreground/16\" : \"bg-success/8 text-success-foreground\",\n              )}\n            >\n              <CheckIcon className=\"size-3\" strokeWidth={3} />\n            </span>\n            <span className={featured ? \"text-primary-foreground/90\" : undefined}>{item}</span>\n          </li>\n        ))}\n      </ul>\n    </article>\n  );\n}\n\nfunction FeatureValue({ value }: { value: boolean | string | undefined }) {\n  if (value === true) {\n    return (\n      <span className=\"inline-flex size-5 items-center justify-center rounded-full bg-success/12 text-success-foreground\">\n        <CheckIcon aria-label=\"Included\" className=\"size-3\" strokeWidth={3} />\n      </span>\n    );\n  }\n  if (!value) return <MinusIcon aria-label=\"Not included\" className=\"size-4 text-muted-foreground/50\" />;\n  return <span className=\"font-medium text-xs tabular-nums\">{value}</span>;\n}\n\nexport function PricingTable({\n  plans,\n  features,\n  eyebrow = \"Pricing\",\n  title = \"Simple plans that grow with you\",\n  subtitle = \"Start free for 14 days. Switch or cancel whenever you like.\",\n  currency = \"$\",\n  yearlyBadge = \"−20%\",\n  defaultBilling = \"monthly\",\n  onSelect,\n  className,\n}: PricingTableProps) {\n  const [billing, setBilling] = useState<Billing>(defaultBilling);\n  const featuredIndex = plans.some((p) => p.featured)\n    ? plans.findIndex((p) => p.featured)\n    : Math.floor((plans.length - 1) / 2);\n\n  return (\n    <section className={cn(\"mx-auto w-full max-w-[1100px]\", className)}>\n      <header className=\"mx-auto flex max-w-xl flex-col items-center text-center\">\n        {eyebrow && <p className=\"font-medium text-muted-foreground text-xs uppercase tracking-widest\">{eyebrow}</p>}\n        <h2 className=\"mt-2 text-balance font-semibold text-3xl tracking-tight sm:text-4xl\">{title}</h2>\n        {subtitle && <p className=\"mt-3 text-balance text-muted-foreground text-sm sm:text-base\">{subtitle}</p>}\n        <div className=\"mt-7\">\n          <BillingSwitch onChange={setBilling} value={billing} yearlyBadge={yearlyBadge} />\n        </div>\n      </header>\n\n      <div className=\"mt-10 grid gap-4 md:grid-cols-3 md:gap-5\">\n        {plans.map((plan, i) => (\n          <PlanCard\n            billing={billing}\n            currency={currency}\n            featured={i === featuredIndex}\n            key={plan.id}\n            onSelect={onSelect}\n            plan={plan}\n          />\n        ))}\n      </div>\n\n      {features && features.length > 0 && (\n        <Collapsible className=\"mt-10\">\n          <div className=\"flex justify-center\">\n            <CollapsibleTrigger render={<Button className={cn(\"group rounded-full\", press)} variant=\"outline\" />}>\n              Compare all features\n              <ChevronDownIcon className=\"transition-transform duration-200 ease-out group-data-[panel-open]:rotate-180\" />\n            </CollapsibleTrigger>\n          </div>\n          <CollapsiblePanel className=\"duration-250 ease-[cubic-bezier(0.23,1,0.32,1)]\">\n            <div className=\"mt-6 overflow-x-auto rounded-2xl border bg-card\">\n              <table className=\"w-full min-w-[340px] border-collapse text-sm\">\n                <thead>\n                  <tr>\n                    <th className=\"px-3 py-3 text-start font-medium text-muted-foreground text-xs sm:px-4\" scope=\"col\">\n                      Features\n                    </th>\n                    {plans.map((plan, i) => (\n                      <th\n                        className={cn(\n                          \"w-[4.5rem] px-1 py-3 text-center font-medium text-sm sm:w-36 sm:px-2\",\n                          i === featuredIndex && \"bg-muted\",\n                        )}\n                        key={plan.id}\n                        scope=\"col\"\n                      >\n                        {plan.name}\n                      </th>\n                    ))}\n                  </tr>\n                </thead>\n                {features.map((group) => (\n                  <tbody key={group.name}>\n                    <tr>\n                      <th\n                        className=\"border-t bg-muted/50 px-3 pt-4 sm:px-4 pb-2 text-start font-medium text-muted-foreground text-xs uppercase tracking-wider\"\n                        colSpan={plans.length + 1}\n                        scope=\"colgroup\"\n                      >\n                        {group.name}\n                      </th>\n                    </tr>\n                    {group.rows.map((row) => (\n                      <tr className=\"border-t\" key={row.label}>\n                        <th className=\"px-3 py-2.5 text-start font-normal sm:px-4\" scope=\"row\">\n                          {row.label}\n                        </th>\n                        {plans.map((plan, i) => (\n                          <td\n                            className={cn(\"px-1 py-2.5 text-center sm:px-2\", i === featuredIndex && \"bg-muted\")}\n                            key={plan.id}\n                          >\n                            <span className=\"flex h-5 items-center justify-center\">\n                              <FeatureValue value={row.values[plan.id]} />\n                            </span>\n                          </td>\n                        ))}\n                      </tr>\n                    ))}\n                  </tbody>\n                ))}\n              </table>\n            </div>\n          </CollapsiblePanel>\n        </Collapsible>\n      )}\n    </section>\n  );\n}\n"
    }
  ]
}