Skip to content
Hazine

Monthly and Annual Billing Switch

A two option radio group, drawn as a segmented control with the annual saving written beside it, that reprices a grid of plans. Use on any page that sells two billing intervals.

How it differs. A two state interval choice built from native radios, not a toggle. Each plan pairs its monthly figure with a two row ledger of the yearly charge and the saving, so the sums reconcile.

Install

pnpm dlx shadcn@latest add @hazine/billing-switch-interval-radio

Adds 1 file, 1 shadcn primitive (button), 2 Hazine items (@hazine/heading, @hazine/use-controllable-state), and 1 package (lucide-react).

First time? Add the registry to components.json
{
  "registries": {
    "@hazine": "https://api.hazine.dev/r/{name}.json"
  }
}

Needed once per project. Items resolve each other through the @hazine namespace.

Props13

title
string = "Pay monthly, or once a year for less"
plans
BillingPlan[] = DEFAULT_PLANS
value
BillingInterval
defaultValue
BillingInterval = "annual"
onValueChange
(value: BillingInterval) => void
currency
string = "USD"
ISO 4217 code.
locale
string = "en-US"
disabled
boolean = false
Locks the interval choice. Pair it with `disabledReason`.
disabledReason
string
Sentence shown under the locked control.
loading
boolean = false
Prices are on their way: figures become skeletons and the actions wait.
contactHref
string = "#sales"
Target of the sales link under the plans and of the empty state action.
recommendedLabel
string = "Recommended"
Marker on the plan flagged `recommended`.
headingLevel
HeadingLevel = 2

Also accepts every prop of Omit<React.ComponentProps<"section">, "title" | "defaultValue" | "onChange">.

Accessibility

Pattern
Pricing structure, Radio Group (APG, opens in a new tab), Landmarks and headings
Keyboard
Keyboard support for Monthly and Annual Billing Switch
KeyEffect
TabMoves to the checked interval, then through each plan action and the sales link
Arrow Left, Arrow Right, Arrow Up, Arrow DownMoves to the other interval and selects it, which reprices every plan
SpaceSelects the focused interval
Enter on a plan actionFollows the checkout link for the selected interval
Screen reader

Section labelled by its heading. The interval is a fieldset of two native radios with a visible legend, each plan has its own heading, and the billing sentence is a status region that also reads out every new price. The region stays in the DOM when there are no plans.

  • Announces: Billed once a year. Each price is the monthly share of one yearly charge, {saving} below monthly billing. {plan} {price} per month
  • Announces: Billed every month. Switch to annual and pay {saving} less over the year. {plan} {price} per month
  • Announces: Billed once a year. Prices are loading.
Reduced motion
No motion apart from the loading skeleton pulse, which is switched off. Colour transitions only.
Checked
Not checked yet. Automated results appear here once CI has run.

Dependencies4

  • button
  • @hazine/heading
  • @hazine/use-controllable-state
  • lucide-react

Filled chips are registry items the CLI adds for you. Outlined chips are npm packages.

Tokens shipped0

None. The item is styled by the tokens your theme already has.

More in Pricing