⌘K
Search
Search pages, pieces and blocks.
Pricing/A Section header with a monthly or yearly switch, three plans as plain Cards, the popular one marked.
components/blocks/pricing.tsx
"use client"
import * as React from "react"
import { CheckIcon } from "@/components/icons"import { Badge } from "@/components/ui/badge"import { Button } from "@/components/ui/button"import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "@/components/ui/card"import { PageHeader, PageHeaderContent, PageHeaderDescription, PageHeaderRow, PageHeaderTitle,} from "@/components/ui/page-header"import { RollingCounter } from "@/components/ui/rolling-counter"import { SegmentedControl, SegmentedControlItem } from "@/components/ui/segmented-control"import { Text } from "@/components/ui/text"
// Pricing: a Section header with a Segmented Control for monthly or yearly// billing, then three plans as Cards in the plain look, the popular one// marked with a Badge on its title row. Each has its price on a Rolling// Counter, a short list and one action. Two states, monthly and yearly; the// switch moves between them and tells onStateChange.
type PricingState = "monthly" | "yearly"
const plans = [ { name: "Weekend", line: "Two lessons a month, Saturday or Sunday.", price: { monthly: 70, yearly: 58 }, points: ["2 group lessons a month", "Gear included", "Weather holds refunded"], }, { name: "Regular", line: "Six lessons a month, any day of the week.", price: { monthly: 180, yearly: 150 }, points: ["6 group lessons a month", "Move a lesson up to 2 hours before", "First pick of weekend slots"], popular: true, }, { name: "Every swell", line: "As many lessons as the sea allows.", price: { monthly: 260, yearly: 217 }, points: ["Unlimited group lessons", "1 private lesson a month", "Bring a friend twice a month"], },]
const euros = { style: "currency", currency: "EUR", maximumFractionDigits: 0 } satisfies Intl.NumberFormatOptions
function PricingBlock({ state, onStateChange,}: { state?: PricingState onStateChange?: (state: PricingState) => void}) { const [own, setOwn] = React.useState<PricingState>("monthly") const billing = state ?? own
return ( <section className="mx-auto flex w-full max-w-6xl flex-col gap-10 px-6 py-16 md:py-24"> <PageHeader align="center"> <PageHeaderRow> <PageHeaderContent className="max-w-xl"> <PageHeaderTitle level={2} size="heading">A plan for every swell</PageHeaderTitle> <PageHeaderDescription>Gear and weather holds in every plan. Yearly saves two months.</PageHeaderDescription> </PageHeaderContent> <SegmentedControl aria-label="Billing" value={billing} onValueChange={(value) => { if (value !== "monthly" && value !== "yearly") return setOwn(value) onStateChange?.(value) }} > <SegmentedControlItem value="monthly">Monthly</SegmentedControlItem> <SegmentedControlItem value="yearly">Yearly</SegmentedControlItem> </SegmentedControl> </PageHeaderRow> </PageHeader> <div className="grid gap-4 lg:grid-cols-3"> {plans.map((plan) => ( <Card key={plan.name} look="plain"> <CardHeader> <CardTitle className="flex items-center justify-between overflow-visible"> {plan.name} {plan.popular && <Badge>Popular</Badge>} </CardTitle> <CardDescription>{plan.line}</CardDescription> </CardHeader> <CardContent className="flex flex-col gap-6"> <div className="flex flex-col gap-1"> <Text variant="figure" size="display"> <RollingCounter value={plan.price[billing]} format={euros} /> </Text> <Text>{billing === "monthly" ? "a month" : "a month, billed yearly"}</Text> </div> <ul className="flex flex-col gap-2"> {plan.points.map((point) => ( <li key={point}> <Text className="flex items-center gap-2"> <CheckIcon className="size-3.5 shrink-0" /> {point} </Text> </li> ))} </ul> </CardContent> <CardFooter className="mt-auto"> <Button variant={plan.popular ? "default" : "outline"} className="w-full"> Choose {plan.name} </Button> </CardFooter> </Card> ))} </div> </section> )}
export { PricingBlock }export type { PricingState }