Skip to content
Blocks

Plan Comparison

A complete plan comparison section, ready to adapt to your product.

Open ↗

Make it yours.

Install the editable source and its dependencies into your React + Tailwind project.

Scroll horizontally for long lines
pnpm dlx shadcn@4.0.8 add http://localhost:3000/r/plan-comparison.json

Use it

Scroll horizontally for long lines
"use client";
import { PlanComparison } from "@/components/jez-ui/blocks/plan-comparison";

export default function Example() {
  return (
    <>
      <PlanComparison />
    </>
  );
}

Compose your own

These styled parts are included in the same install. Use children to build your layout; add className only when you want an override.

Scroll horizontally for long lines
import { PlanComparison, PlanComparisonHeader, PlanComparisonTitle, PlanComparisonDescription, PlanComparisonContent, PlanComparisonItemTitle, PlanComparisonItem } from "@/components/jez-ui/blocks/plan-comparison";
Read the composition guide →

Props & types

Scroll horizontally for long lines
export type ComparisonPlan = {
  name: string;
  monthly: number;
  annual: number;
  features: string[];
};

export type PlanComparisonOptions = {
  className?: string;
  title?: string;
  plans?: ComparisonPlan[];
  onSelect?: (plan: string, billing: "monthly" | "annual") => void;
  billingPeriods?: typeof PlanComparisonDefaultBillingPeriods;
};

export type PlanComparisonProps = Omit<
  React.ComponentProps<"section">,
  keyof PlanComparisonOptions
> &
  PlanComparisonOptions;

PlanComparisonProps

Source

View 3 source files

registry/blocks/plan-comparison.tsx

Scroll horizontally for long lines
"use client";
import * as React from "react";
import { cn } from "../ui/utils";
import { Button } from "../ui/button";
export type ComparisonPlan = {
  name: string;
  monthly: number;
  annual: number;
  features: string[];
};
const defaults: ComparisonPlan[] = [
  {
    name: "Personal",
    monthly: 8,
    annual: 80,
    features: ["3 projects", "1 collaborator", "7-day history"],
  },
  {
    name: "Team",
    monthly: 18,
    annual: 180,
    features: ["Unlimited projects", "10 collaborators", "90-day history"],
  },
  {
    name: "Studio",
    monthly: 32,
    annual: 320,
    features: [
      "Unlimited projects",
      "Unlimited collaborators",
      "Unlimited history",
    ],
  },
];
export type PlanComparisonOptions = {
  className?: string;
  title?: string;
  plans?: ComparisonPlan[];
  onSelect?: (plan: string, billing: "monthly" | "annual") => void;
  billingPeriods?: typeof PlanComparisonDefaultBillingPeriods;
};
export type PlanComparisonProps = Omit<
  React.ComponentProps<"section">,
  keyof PlanComparisonOptions
> &
  PlanComparisonOptions;
const PlanComparisonDefaultBillingPeriods = [false, true];
export function PlanComparison({
  billingPeriods = PlanComparisonDefaultBillingPeriods,
  className,
  title = "Room for your next chapter.",
  plans = defaults,
  onSelect,
  children,
  ...rootProps
}: PlanComparisonProps) {
  const [annual, setAnnual] = React.useState(false),
    [message, setMessage] = React.useState("");
  return (
    <section {...rootProps} className={cn("py-8", className)}>
      {children !== undefined ? (
        children
      ) : (
        <>
          <PlanComparisonHeader>
            <PlanComparisonTitle>{title}</PlanComparisonTitle>
            <div aria-label="Billing period" className="flex gap-2">
              {billingPeriods.map((v) => (
                <Button
                  key={String(v)}
                  variant={annual === v ? "primary" : "outline"}
                  aria-pressed={annual === v}
                  onClick={() => setAnnual(v)}
                >
                  {v ? "Annual" : "Monthly"}
                </Button>
              ))}
            </div>
          </PlanComparisonHeader>
          <PlanComparisonDescription>
            Illustrative prices in GBP, per workspace.{" "}
            {annual ? "Billed annually." : "Billed monthly."}
          </PlanComparisonDescription>
          <PlanComparisonContent>
            {plans.map((p, i) => (
              <PlanComparisonItem
                key={p.name}
                className={cn(
                  i === 1 ? "bg-primary text-primary-foreground" : "bg-muted",
                )}
              >
                <PlanComparisonItemTitle>{p.name}</PlanComparisonItemTitle>
                <p className="mt-6 text-4xl tabular-nums">
                  £{annual ? p.annual : p.monthly}
                  <span className="text-sm">
                    {" "}
                    / {annual ? "year" : "month"}
                  </span>
                </p>
                <ul className="my-8 flex-1 space-y-4 text-sm">
                  {p.features.map((f) => (
                    <li key={f}>{f}</li>
                  ))}
                </ul>
                <Button
                  variant="outline"
                  className="bg-background text-foreground"
                  onClick={() =>
                    onSelect
                      ? onSelect(p.name, annual ? "annual" : "monthly")
                      : setMessage(
                          `${p.name} selected. Demo only; no purchase made.`,
                        )
                  }
                >
                  Choose {p.name}
                </Button>
              </PlanComparisonItem>
            ))}
          </PlanComparisonContent>
          <p role="status" className="mt-4 text-sm">
            {message}
          </p>
        </>
      )}
    </section>
  );
}

export function PlanComparisonHeader({
  className,
  ...props
}: React.ComponentProps<"div">) {
  return (
    <div
      data-slot="plan-comparison-header"
      className={cn(
        "flex flex-wrap billingPeriods-end justify-between gap-6",
        className,
      )}
      {...props}
    />
  );
}
export function PlanComparisonTitle({
  className,
  ...props
}: React.ComponentProps<"h2">) {
  return (
    <h2
      data-slot="plan-comparison-title"
      className={cn("max-w-lg text-4xl tracking-tight", className)}
      {...props}
    />
  );
}
export function PlanComparisonDescription({
  className,
  ...props
}: React.ComponentProps<"p">) {
  return (
    <p
      data-slot="plan-comparison-description"
      className={cn("mt-5 text-sm text-muted-foreground", className)}
      {...props}
    />
  );
}
export function PlanComparisonContent({
  className,
  ...props
}: React.ComponentProps<"div">) {
  return (
    <div
      data-slot="plan-comparison-content"
      className={cn("mt-8 grid gap-5 md:grid-cols-3", className)}
      {...props}
    />
  );
}
export function PlanComparisonItemTitle({
  className,
  ...props
}: React.ComponentProps<"h3">) {
  return (
    <h3
      data-slot="plan-comparison-itemtitle"
      className={cn("text-xl", className)}
      {...props}
    />
  );
}

export function PlanComparisonItem({
  className,
  ...props
}: React.ComponentProps<"article">) {
  return (
    <article
      data-slot="plan-comparison-item"
      className={cn("flex flex-col rounded-xl p-6", className)}
      {...props}
    />
  );
}

registry/ui/utils.ts

Scroll horizontally for long lines
import { clsx, type ClassValue } from "clsx";
import { twMerge } from "tailwind-merge";
export function cn(...values: ClassValue[]) {
  return twMerge(clsx(values));
}

registry/ui/button.tsx

Scroll horizontally for long lines
"use client";
import * as React from "react";
import { Slot } from "radix-ui";
import { LoaderCircle } from "lucide-react";
import { cn } from "./utils";
export type ButtonProps = React.ComponentProps<"button"> & {
  variant?: "primary" | "secondary" | "outline" | "ghost" | "danger";
  size?: "sm" | "md" | "lg";
  loading?: boolean;
  asChild?: boolean;
};
export function Button({
  variant = "primary",
  size = "md",
  loading,
  asChild,
  className,
  children,
  disabled,
  ...props
}: ButtonProps) {
  const Comp = asChild ? Slot.Root : "button";
  return (
    <Comp
      type={asChild ? undefined : "button"}
      disabled={asChild ? undefined : disabled || loading}
      aria-disabled={disabled || loading || undefined}
      aria-busy={loading || undefined}
      className={cn(
        "relative inline-flex shrink-0 items-center justify-center gap-2 whitespace-nowrap rounded-lg border border-transparent text-sm font-medium leading-none transition-[background-color,border-color,box-shadow,transform] duration-150 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary active:scale-[.98] disabled:pointer-events-none disabled:opacity-45 aria-disabled:pointer-events-none [&_svg]:shrink-0",
        {
          "bg-primary text-primary-foreground shadow-[inset_0_1px_0_#ffffff26,0_1px_2px_#00000012] hover:bg-primary/90":
            variant === "primary",
          "border-border/60 bg-muted text-foreground hover:bg-muted/70":
            variant === "secondary",
          "border-border bg-background text-foreground shadow-sm hover:bg-muted/60":
            variant === "outline",
          "text-muted-foreground hover:bg-muted hover:text-foreground":
            variant === "ghost",
          "bg-danger text-danger-foreground hover:bg-danger/90":
            variant === "danger",
        },
        {
          "h-8 px-3 text-xs": size === "sm",
          "h-10 px-4": size === "md",
          "h-12 px-6": size === "lg",
        },
        className,
      )}
      {...props}
    >
      {asChild ? (
        children
      ) : (
        <>
          <span
            className={cn(
              "inline-flex min-w-0 flex-1 items-center justify-center gap-2",
              loading && "invisible",
            )}
          >
            {children}
          </span>
          {loading && (
            <LoaderCircle
              aria-hidden="true"
              className="absolute size-4 animate-spin motion-reduce:animate-none"
            />
          )}
        </>
      )}
    </Comp>
  );
}

Dependencies

clsx@2.1.1 · tailwind-merge@3.5.0 · radix-ui@1.6.7 · lucide-react@0.577.0

Accessibility & behaviour

Provide meaningful labels and preserve keyboard focus styles. Check contrast when customising theme colours.

Read the accessibility and performance guide →