Usage Pricing
A complete usage pricing section, ready to adapt to your product.
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/usage-pricing.jsonUse it
Scroll horizontally for long lines
"use client";
import { UsagePricing } from "@/components/jez-ui/blocks/usage-pricing";
export default function Example() {
return (
<>
<UsagePricing />
</>
);
}
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 { UsagePricing, UsagePricingContent, UsagePricingTitle, UsagePricingItemTitle, UsagePricingItem } from "@/components/jez-ui/blocks/usage-pricing";Props & types
Scroll horizontally for long lines
export type UsagePricingOptions = {
seats?: number;
defaultSeats?: number;
onSeatsChange?: (seats: number) => void;
minSeats?: number;
maxSeats?: number;
plans?: {
name: string;
price: (seats: number) => number;
note: React.ReactNode;
}[];
formatPrice?: (amount: number) => React.ReactNode;
summary?: React.ReactNode;
className?: string;
title?: string;
onSelect?: (plan: string, seats: number) => void;
};
export type UsagePricingProps = Omit<
React.ComponentProps<"section">,
keyof UsagePricingOptions
> &
UsagePricingOptions;
UsagePricingPropsSource
View 4 source files
registry/blocks/usage-pricing.tsx
Scroll horizontally for long lines
"use client";
import * as React from "react";
import { useControllable } from "../ui/use-controllable";
import { cn } from "../ui/utils";
import { Button } from "../ui/button";
export type UsagePricingOptions = {
seats?: number;
defaultSeats?: number;
onSeatsChange?: (seats: number) => void;
minSeats?: number;
maxSeats?: number;
plans?: {
name: string;
price: (seats: number) => number;
note: React.ReactNode;
}[];
formatPrice?: (amount: number) => React.ReactNode;
summary?: React.ReactNode;
className?: string;
title?: string;
onSelect?: (plan: string, seats: number) => void;
};
export type UsagePricingProps = Omit<
React.ComponentProps<"section">,
keyof UsagePricingOptions
> &
UsagePricingOptions;
const defaultPlans = [
{
name: "Flexible",
price: (seats: number) => seats * 12,
note: "£12 per person / month",
},
{
name: "Workspace",
price: () => 240,
note: "£240 per workspace / month, up to 50 people",
},
];
export function UsagePricing({
seats: controlledSeats,
defaultSeats = 5,
onSeatsChange,
minSeats = 1,
maxSeats = 50,
plans = defaultPlans,
formatPrice = (amount) => `£${amount}`,
summary,
className,
title = "A plan that grows with your team.",
onSelect,
children,
...rootProps
}: UsagePricingProps) {
const [seats, setSeats] = useControllable(
controlledSeats,
defaultSeats,
onSeatsChange,
),
[message, setMessage] = React.useState("");
const id = React.useId();
return (
<section
{...rootProps}
className={cn(
"grid overflow-hidden rounded-xl border border-border md:grid-cols-2",
className,
)}
>
{children !== undefined ? (
children
) : (
<>
<UsagePricingContent>
<UsagePricingTitle>{title}</UsagePricingTitle>
<p className="mt-5 text-sm leading-relaxed text-muted-foreground">
Compare a flexible seat-based plan with a flat workspace price.
Illustrative GBP pricing, billed monthly.
</p>
<label htmlFor={id} className="mt-10 flex justify-between text-sm">
Team size <span className="tabular-nums">{seats} people</span>
</label>
<input
id={id}
type="range"
min={minSeats}
max={maxSeats}
value={seats}
onChange={(e) => setSeats(Number(e.target.value))}
className="mt-5 w-full accent-primary"
/>
<p className="mt-3 text-xs text-muted-foreground">
{minSeats}–{maxSeats} people · Adjust to compare monthly totals.
</p>
</UsagePricingContent>
<div className="bg-muted p-7 md:p-10">
{plans
.map((plan) => ({ ...plan, price: plan.price(seats) }))
.map((p) => (
<UsagePricingItem key={p.name}>
<div className="flex flex-wrap items-baseline justify-between gap-3">
<UsagePricingItemTitle>{p.name}</UsagePricingItemTitle>
<p className="text-3xl tabular-nums">
{formatPrice(p.price)}
<span className="text-xs"> / month</span>
</p>
</div>
<p className="my-3 text-xs text-muted-foreground">{p.note}</p>
<Button
variant="outline"
onClick={() =>
onSelect
? onSelect(p.name, seats)
: setMessage(
`${p.name} selected for ${seats} people. Demo only.`,
)
}
>
Choose {p.name}
</Button>
</UsagePricingItem>
))}
<p aria-live="polite" className="mt-5 text-sm">
{summary !== undefined
? summary
: plans === defaultPlans
? seats * 12 === 240
? "Both plans cost the same."
: `${seats * 12 < 240 ? "Flexible" : "Workspace"} saves £${Math.abs(240 - seats * 12)} per month.`
: null}
</p>
<p role="status" className="mt-3 text-sm">
{message}
</p>
</div>
</>
)}
</section>
);
}
export function UsagePricingContent({
className,
...props
}: React.ComponentProps<"div">) {
return (
<div
data-slot="usage-pricing-content"
className={cn("p-7 md:p-10", className)}
{...props}
/>
);
}
export function UsagePricingTitle({
className,
...props
}: React.ComponentProps<"h2">) {
return (
<h2
data-slot="usage-pricing-title"
className={cn("text-4xl leading-tight tracking-tight", className)}
{...props}
/>
);
}
export function UsagePricingItemTitle({
className,
...props
}: React.ComponentProps<"h3">) {
return (
<h3
data-slot="usage-pricing-itemtitle"
className={cn("text-xl", className)}
{...props}
/>
);
}
export function UsagePricingItem({
className,
...props
}: React.ComponentProps<"div">) {
return (
<div
data-slot="usage-pricing-item"
className={cn("border-b border-border py-6 first:pt-0", className)}
{...props}
/>
);
}
registry/ui/use-controllable.ts
Scroll horizontally for long lines
"use client";
import { useRef, useState, type SetStateAction } from "react";
/** Controlled or instance-local state. Functional updates also work before a rerender. */
export function useControllable<T>(
value: T | undefined,
initial: T,
onChange?: (value: T) => void,
) {
const [local, setLocal] = useState(initial);
const current = useRef(value === undefined ? local : value);
current.current = value === undefined ? local : value;
return [
current.current,
(action: SetStateAction<T>) => {
const next =
typeof action === "function"
? (action as (previous: T) => T)(current.current)
: action;
current.current = next;
if (value === undefined) setLocal(next);
onChange?.(next);
},
] as const;
}
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 →