Plan Upgrade Card
A plan picker card with monthly or yearly toggle, perks and an upgrade button.
"use client"
import { useState } from "react"
import { CheckIcon } from "@phosphor-icons/react"
import { Button } from "@/components/ui/button"
import {
Card,
CardAction,
CardContent,
CardDescription,
CardFooter,
CardHeader,
CardTitle,
} from "@/components/ui/card"
const COPY = {
title: "Your plan",
description: "Pick the seats your team needs.",
current: "Current plan",
switchTo: (name: string) => `Switch to ${name}`,
switched: (name: string) => `${name} plan active`,
monthly: "Monthly",
yearly: "Yearly (save 20%)",
} as const
const PLANS = [
{
id: "starter",
name: "Starter",
monthly: 12,
perks: ["3 projects", "Community support"],
},
{
id: "team",
name: "Team",
monthly: 29,
perks: ["Unlimited projects", "Priority support", "Audit log"],
},
] as const
export default function PlanUpgrade() {
const [yearly, setYearly] = useState(false)
// The plan you pay for, and the card you are looking at: picking a card
// compares; the button is what changes the plan.
const [current, setCurrent] = useState<string>("starter")
const [plan, setPlan] = useState<string>("starter")
const team = PLANS[1]
const price = yearly ? Math.round(team.monthly * 0.8) : team.monthly
return (
<Card className="mx-auto w-full max-w-md">
<CardHeader>
<CardTitle>{COPY.title}</CardTitle>
<CardDescription>{COPY.description}</CardDescription>
<CardAction>
<div className="flex rounded-full bg-muted p-0.5 text-xs">
{[false, true].map((value) => (
<button
key={String(value)}
type="button"
aria-pressed={yearly === value}
onClick={() => setYearly(value)}
className="rounded-full px-3 py-1 aria-pressed:bg-background aria-pressed:shadow-sm"
>
{value ? "Yearly" : COPY.monthly}
</button>
))}
</div>
</CardAction>
</CardHeader>
<CardContent className="flex flex-col gap-3">
{PLANS.map((item) => {
const active = plan === item.id
return (
<button
key={item.id}
type="button"
aria-pressed={active}
onClick={() => setPlan(item.id)}
className="flex flex-col gap-2 rounded-2xl border p-4 text-left aria-pressed:border-primary aria-pressed:bg-primary/5"
>
<span className="flex items-center justify-between">
<span className="font-medium">
{item.name}
{item.id === current && (
<span className="ml-2 text-xs font-normal text-muted-foreground">
{COPY.current}
</span>
)}
</span>
<span className="text-sm tabular-nums">
${item.id === "team" ? price : item.monthly}
<span className="text-muted-foreground"> /seat/mo</span>
</span>
</span>
<span className="flex flex-wrap gap-x-4 gap-y-1 text-xs text-muted-foreground">
{item.perks.map((perk) => (
<span key={perk} className="flex items-center gap-1">
<CheckIcon className="size-3" />
{perk}
</span>
))}
</span>
</button>
)
})}
</CardContent>
<CardFooter className="flex-col items-stretch gap-2">
<Button disabled={plan === current} onClick={() => setCurrent(plan)}>
{plan === current
? COPY.switched(PLANS.find((p) => p.id === current)?.name ?? "")
: COPY.switchTo(PLANS.find((p) => p.id === plan)?.name ?? "")}
</Button>
<p className="text-center text-xs text-muted-foreground">
{yearly ? COPY.yearly : COPY.monthly}
</p>
</CardFooter>
</Card>
)
}
Installation
pnpm dlx shadcn@latest add @01orbital/plan-upgrade-01npx shadcn@latest add @01orbital/plan-upgrade-01yarn dlx shadcn@latest add @01orbital/plan-upgrade-01bunx --bun shadcn@latest add @01orbital/plan-upgrade-01Make it yours
- Its words are in
COPYat the top ofcomponents/blocks/billing/plan-upgrade-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