# Pricing tiers with billing switch (带计费周期切换的价格方案)

Four plan cards for an email API: monthly or annual switch with computed annual prices, a ringed highlighted plan, volume and overage lines, and a feature list that differs per plan.

- Ref: `component/pricing-tiers` (component · pricing)
- Page: https://uifino.com/en/components/pricing/pricing-tiers
- Markdown: https://uifino.com/md/components/pricing-tiers.md
- Preview image: https://uifino.com/blocks/covers/pricing-tiers-dark.webp

## Install

- shadcn: `npx shadcn@latest add "https://uifino.com/r/blocks/pricing-tiers.json"`
- UIFino CLI: `npx uifino@latest add component/pricing-tiers`

## Dependencies

`lucide-react`

## shadcn/ui components it builds on

- `badge`, `button`, `separator`, `tabs`. The shadcn CLI installs them together with the block.

## Layout borrowed from

- https://resend.com/pricing: Centered large title, segmented switch, four equal bordered cards with plan name, big price, hairline, volume line and check list. Plans and copy are our own.

## Theme

The block reads the project's shadcn theme variables, so it follows whatever DESIGN.md the project uses and needs no options of its own.
To give the project the look of a UIFino brand or style, install its theme: `npx shadcn@latest add "https://uifino.com/r/themes/linear.json"`.

## Usage

The files under `examples/` show the block wired with content, including its loading, empty and error states where it has them.

## Files

| Path | Role | Size |
| :--- | :--- | ---: |
| components/blocks/pricing-tiers/examples/content.ts | demo | 4.3 KB |
| components/blocks/pricing-tiers/examples/default.tsx | demo | 210 B |
| components/blocks/pricing-tiers/examples/monthly.tsx | demo | 250 B |
| components/blocks/pricing-tiers/pricing-tiers.tsx | source | 5.5 KB |

### components/blocks/pricing-tiers/pricing-tiers.tsx

```tsx
"use client";

import { useState } from "react";
import { Check } from "lucide-react";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import { Separator } from "@/components/ui/separator";
import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs";
import { cn } from "@/lib/utils";

export type PricingBilling = "monthly" | "annual";

export interface PricingTier {
  readonly id: string;
  readonly name: string;
  readonly monthlyPrice: number | null;
  readonly annualMonthlyPrice?: number;
  readonly customPrice?: string;
  readonly volume: string;
  readonly volumeNote?: string;
  readonly hint?: string;
  readonly features: readonly string[];
  readonly cta: string;
  readonly highlighted?: boolean;
  readonly badge?: string;
}

export interface PricingTiersProps {
  readonly title: string;
  readonly description?: string;
  readonly tiers: readonly PricingTier[];
  readonly monthlyLabel: string;
  readonly annualLabel: string;
  readonly discountBadge: string;
  readonly defaultBilling?: PricingBilling;
  readonly perMonth: string;
  readonly billedAnnually: string;
  readonly billedMonthly: string;
  readonly onSelect?: (tierId: string, billing: PricingBilling) => void;
}

function formatPrice(value: number): string {
  return Number.isInteger(value) ? `$${value}` : `$${value.toFixed(2)}`;
}

export function PricingTiers({
  title,
  description,
  tiers,
  monthlyLabel,
  annualLabel,
  discountBadge,
  defaultBilling = "annual",
  perMonth,
  billedAnnually,
  billedMonthly,
  onSelect
}: PricingTiersProps) {
  const [billing, setBilling] = useState<PricingBilling>(defaultBilling);

  return (
    <section className="@container bg-background text-foreground">
      <div className="mx-auto flex max-w-6xl flex-col items-center gap-10 px-4 py-16 @3xl:px-8 @3xl:py-24">
        <div className="flex max-w-xl flex-col items-center gap-3 text-center">
          <h2 className="font-heading text-4xl font-semibold tracking-tight text-balance @3xl:text-5xl">{title}</h2>
          {description ? <p className="text-muted-foreground text-balance">{description}</p> : null}
        </div>

        <Tabs value={billing} onValueChange={(value) => setBilling(value as PricingBilling)}>
          <TabsList>
            <TabsTrigger value="monthly" className="px-4">
              {monthlyLabel}
            </TabsTrigger>
            <TabsTrigger value="annual" className="px-4">
              {annualLabel}
              <Badge variant="secondary" className="bg-chart-2/15 text-foreground">
                {discountBadge}
              </Badge>
            </TabsTrigger>
          </TabsList>
        </Tabs>

        <div className="grid w-full gap-4 @3xl:grid-cols-2 @6xl:grid-cols-4">
          {tiers.map((tier) => {
            const monthly = tier.monthlyPrice;
            const annual = tier.annualMonthlyPrice ?? monthly;
            const shown = monthly === null ? null : billing === "annual" ? annual : monthly;
            const hint =
              annual === null || monthly === 0
                ? tier.hint
                : billing === "annual"
                  ? billedAnnually.replace("{total}", formatPrice(annual * 12))
                  : billedMonthly;

            return (
              <div
                key={tier.id}
                className={cn(
                  "bg-card text-card-foreground flex min-w-0 flex-col gap-6 rounded-xl border p-6",
                  tier.highlighted && "border-primary ring-primary ring-1"
                )}
              >
                <div className="flex h-6 items-center justify-between gap-2">
                  <h3 className="truncate text-base font-medium">{tier.name}</h3>
                  {tier.badge ? <Badge>{tier.badge}</Badge> : null}
                </div>

                <div className="flex flex-col gap-1 @3xl:min-h-20">
                  {shown === null ? (
                    <p className="text-4xl font-semibold tracking-tight">{tier.customPrice}</p>
                  ) : (
                    <p className="flex items-baseline gap-1.5">
                      <span className="text-4xl font-semibold tracking-tight tabular-nums">{formatPrice(shown)}</span>
                      <span className="text-muted-foreground text-sm">{perMonth}</span>
                    </p>
                  )}
                  <p className="text-muted-foreground text-sm">{hint}</p>
                </div>

                <Button
                  variant={tier.highlighted ? "default" : "outline"}
                  className="w-full"
                  onClick={() => onSelect?.(tier.id, billing)}
                >
                  {tier.cta}
                </Button>

                <Separator />

                <div className="flex flex-col gap-1">
                  <p className="text-sm font-medium">{tier.volume}</p>
                  {tier.volumeNote ? <p className="text-muted-foreground text-pretty text-sm">{tier.volumeNote}</p> : null}
                </div>

                <ul className="flex flex-col gap-3 text-sm">
                  {tier.features.map((feature) => (
                    <li key={feature} className="flex items-start gap-2.5">
                      <Check className="text-chart-2 mt-0.5 size-4 shrink-0" />
                      <span className="text-muted-foreground min-w-0 text-pretty break-words">{feature}</span>
                    </li>
                  ))}
                </ul>
              </div>
            );
          })}
        </div>
      </div>
    </section>
  );
}
```

Not inlined (3 files, 4.7 KB). Full sources: https://uifino.com/r/blocks/pricing-tiers.json
