Skip to Content

Pricing Toggle

Billing period switch for pricing pages: a monthly and yearly (annual) segmented control built on the Tabs list. A controlled client component that takes a typed value and a change handler to swap plan prices.

Installation

pnpm dlx shadcn@latest add @01orbital/pricing-toggle

Usage

"use client"

import { useState } from "react"

import {
  PricingToggle,
  PricingToggleItem,
} from "@/components/pricing/pricing-toggle"

const COPY = {
  label: "Billing period",
  monthly: "Monthly",
  annual: "Yearly",
} as const

export default function PricingToggleDemo() {
  const [period, setPeriod] = useState<"monthly" | "annual">("monthly")
  return (
    <PricingToggle
      aria-label={COPY.label}
      value={period}
      onValueChange={setPeriod}
    >
      <PricingToggleItem value="monthly">{COPY.monthly}</PricingToggleItem>
      <PricingToggleItem value="annual">{COPY.annual}</PricingToggleItem>
    </PricingToggle>
  )
}

This example installs with everything it uses:

pnpm dlx shadcn@latest add @01orbital/pricing-toggle-demo

Anatomy

Pricing Toggle is built from 2 parts. In the example they nest like this:

PricingToggle
└─ PricingToggleItem
  • PricingToggle: The switch between billing periods, such as monthly and annual, above a set of pricing plans. Put a PricingToggleItem inside for each period. It is a controlled tab list: keep the chosen period in state, pass it as value and update it in onValueChange.
  • PricingToggleItem: One billing period inside PricingToggle, such as "Monthly". Give it a value; PricingToggle reports that value when it is picked.

API reference

PricingToggle

The switch between billing periods, such as monthly and annual, above a set of pricing plans. Put a PricingToggleItem inside for each period. It is a controlled tab list: keep the chosen period in state, pass it as value and update it in onValueChange.

className, aria-label and other props land on the tab list. The toggle centers itself (self-center) in a flex or grid parent.

Prop

Type

It also accepts the props of the Base UI part it wraps, and the HTML attributes of the element it renders.

PricingToggleItem

One billing period inside PricingToggle, such as "Monthly". Give it a value; PricingToggle reports that value when it is picked.

It accepts the props of the Base UI part it wraps, and the HTML attributes of the element it renders.

Dependencies

npm: cn. The CLI installs it for you.

Requires these pieces. The CLI adds each one that is missing and won't replace a file you already have unless you choose to:

The shadcn parts here are their Base UI versions, and this piece uses Base UI's API. A Radix version you already have won't work with it.

Used in blocks

3 blocks are built with Pricing Toggle:

Last updated on