Pricing Table

A flexible, accessible pricing table component for SaaS applications with monthly/yearly toggle and feature comparison.

Preview

Install Summary

This kit will add the following files and dependencies to your project. Download the bundle and extract it into your project root.

Component Files

FilePath
pricing-table.tsxcomponents/billing/pricing-table/pricing-table.tsx
pricing-card.tsxcomponents/billing/pricing-table/pricing-card.tsx
pricing-toggle.tsxcomponents/billing/pricing-table/pricing-toggle.tsx
pricing-feature.tsxcomponents/billing/pricing-table/pricing-feature.tsx
types.tscomponents/billing/pricing-table/types.ts
index.tscomponents/billing/pricing-table/index.ts

Utility Files

FilePath
format.tslib/format.ts
design-tokens.tslib/design-tokens.ts

Dependencies

Install these dependencies before using the component:

Terminal
bash
npx shadcn@latest add button
Terminal
bash
npm install @phosphor-icons/react

Installation

Download the complete bundle as a ZIP file, or copy the text bundle to your clipboard:

Component Files

The component consists of the following files:

1. pricing-table.tsx

pricing-table.tsx
tsx
"use client";

import { useState } from "react";
import { cn } from "@/lib/utils";
import { PricingCard } from "./pricing-card";

2. pricing-card.tsx

pricing-card.tsx
tsx
"use client";

import { cn } from "@/lib/utils";
import { formatPrice } from "@/lib/format";
import { badgeBase } from "@/lib/design-tokens";

3. pricing-toggle.tsx

pricing-toggle.tsx
tsx
"use client";

import { cn } from "@/lib/utils";
import { badgeBase, statusColors } from "@/lib/design-tokens";
import type { PricingToggleProps } from "./types";

4. pricing-feature.tsx

pricing-feature.tsx
tsx
"use client";

import { Check, Minus } from "@phosphor-icons/react";
import { cn } from "@/lib/utils";
import type { PricingFeatureItemProps } from "./types";

5. types.ts

types.ts
tsx
export type BillingInterval = "monthly" | "yearly";

export interface PricingFeature {
  id: string;
  name: string;

6. index.ts

index.ts
tsx
export { PricingTable } from "./pricing-table";
export { PricingCard } from "./pricing-card";
export { PricingToggle } from "./pricing-toggle";
export { PricingFeature } from "./pricing-feature";
export type * from "./types";

Shared Utilities

This component uses shared utility functions. These are included in the bundle above:

format.ts

format.ts
tsx
export function formatDate(date: Date): string {
  return date.toLocaleDateString("en-US", {
    month: "short",
    day: "numeric",
    year: "numeric",
  });
}

export function formatRelativeTime(date: Date, now: Date = new Date()): string {
  const diff = now.getTime() - date.getTime();
  const minutes = Math.floor(diff / 60000);

  if (minutes < 1) return "Just now";
  if (minutes < 60) return `${minutes}m ago`;

  const hours = Math.floor(minutes / 60);
  if (hours < 24) return `${hours}h ago`;

  const days = Math.floor(hours / 24);
  if (days < 7) return `${days}d ago`;

  return formatDate(date);
}

export function formatPrice(amount: number, currency = "USD"): string {
  return new Intl.NumberFormat("en-US", {
    style: "currency",
    currency,
    minimumFractionDigits: 0,
    maximumFractionDigits: 2,
  }).format(amount);
}

export function formatNumber(num: number): string {
  if (num >= 1_000_000) return `${(num / 1_000_000).toFixed(1)}M`;
  if (num >= 1_000) return `${(num / 1_000).toFixed(1)}K`;
  return num.toString();
}

design-tokens.ts

design-tokens.ts
tsx
// Border radius
export const radius = {
  card: "rounded-xl",
  badge: "rounded-full",
  button: "rounded-lg",

Usage

app/pricing/page.tsx
tsx
import { PricingTable } from "@/components/billing/pricing-table";

const tiers = [
  {
    id: "free",

Props

PropTypeDefault
tiersPricingTier[]Required
showTogglebooleantrue
yearlyDiscountnumber-
defaultInterval"monthly" | "yearly""monthly"
currencystring"USD"
onTierSelect(tier, interval) => void-
onIntervalChange(interval) => void-