Plan Comparison
Three selectable plan cards with perks and a footer that computes a prorated charge or credit for the switch.
"use client"
import { useState } from "react"
import { CheckIcon } from "@phosphor-icons/react"
import { Badge } from "@/components/ui/badge"
import { Button } from "@/components/ui/button"
import {
Card,
CardContent,
CardFooter,
CardHeader,
CardTitle,
} from "@/components/ui/card"
const COPY = {
title: "Change your plan",
current: "Current plan",
proration: "Prorated for the 18 days left in this cycle",
confirm: "Confirm change",
note: "You can switch back any time. Credit carries over.",
} as const
const PLANS = [
{
id: "starter",
name: "Starter",
price: 19,
seats: "3 seats",
perks: ["5 projects", "Email support"],
},
{
id: "pro",
name: "Pro",
price: 99,
seats: "15 seats",
perks: ["Unlimited projects", "Priority support", "SSO"],
},
{
id: "scale",
name: "Scale",
price: 249,
seats: "50 seats",
perks: ["Audit log", "99.99% uptime SLA", "Named manager"],
},
] as const
export default function BillingPlanCompare() {
const [currentId, setCurrentId] = useState<string>("pro")
const [picked, setPicked] = useState<string>("scale")
const target = PLANS.find((p) => p.id === picked)!
const current = PLANS.find((p) => p.id === currentId)!
const delta = Math.round(((target.price - current.price) * 18) / 30)
return (
<Card className="mx-auto w-full max-w-4xl">
<CardHeader>
<CardTitle>{COPY.title}</CardTitle>
</CardHeader>
<CardContent className="grid gap-3 md:grid-cols-3">
{PLANS.map((plan) => {
const active = picked === plan.id
return (
<button
key={plan.id}
type="button"
aria-pressed={active}
onClick={() => setPicked(plan.id)}
className="flex flex-col gap-4 rounded-2xl border p-5 text-left transition-colors aria-pressed:border-primary aria-pressed:bg-primary/5"
>
<span className="flex items-center justify-between text-sm font-medium">
{plan.name}
{plan.id === currentId && (
<Badge variant="secondary">{COPY.current}</Badge>
)}
</span>
<span className="flex items-baseline gap-1">
<span className="text-3xl font-semibold tabular-nums">
${plan.price}
</span>
<span className="text-sm text-muted-foreground">/mo</span>
</span>
<span className="text-sm text-muted-foreground">
{plan.seats}
</span>
<ul className="flex flex-col gap-2 text-sm">
{plan.perks.map((perk) => (
<li key={perk} className="flex items-center gap-2">
<CheckIcon className="size-4 text-muted-foreground" />
{perk}
</li>
))}
</ul>
</button>
)
})}
</CardContent>
<CardFooter className="flex-col items-stretch gap-3 sm:flex-row sm:items-center sm:justify-between">
<div className="flex flex-col text-sm">
<span className="font-medium">
{target.id === currentId
? "No change"
: `${delta > 0 ? "Charge" : "Credit"} $${Math.abs(delta)} today`}
</span>
<span className="text-muted-foreground">
{target.id === currentId ? COPY.note : COPY.proration}
</span>
</div>
<Button
disabled={target.id === currentId}
onClick={() => setCurrentId(target.id)}
>
{COPY.confirm}
</Button>
</CardFooter>
</Card>
)
}
Installation
pnpm dlx shadcn@latest add @01orbital/plan-compare-01npx shadcn@latest add @01orbital/plan-compare-01yarn dlx shadcn@latest add @01orbital/plan-compare-01bunx --bun shadcn@latest add @01orbital/plan-compare-01Make it yours
- Its words are in
COPYat the top ofcomponents/blocks/billing/plan-compare-01/index.tsx: change them there, not in the markup. PLANS, also at the top of the file, holds its lists and settings.
Built from
npm: @phosphor-icons/react. The CLI installs it for you.
Built from these parts. The CLI adds each one that is missing and won't replace a file you already have unless you choose to:
The shadcn parts here are their Base UI versions, and this piece uses Base UI's API. A Radix version you already have won't work with it.
Last updated on