How it works
One registered number, --_plan-t, goes from 0 (first plan) to 1 (second) and everything on the track is worked out from it in CSS. The ball travels 207px, which is 3π × its 22px radius, and turns 540deg on the way, so it rolls without sliding and its arrow ends up pointing back the way it came. The light on the ball (a hot spot and a horizon reflection) does not turn; only the face does. The flood is a full-width gradient of --ds-secondary, --ds-accent and --ds-tertiary that slides in behind the ball, and the plan's name inside it is moved by the opposite amount so it holds still while the flood uncovers it. The press curve, cubic-bezier(0.6, 0, 0.25, 1.22), starts slowly like a heavy object and runs a little past the end; the ball's position stops at the end while that extra squashes it against the end of the track. A drag writes --_plan-t directly and, on release, rolls on past halfway or back. On the card, every digit is a 0–9 strip behind a window; the digits start rolling a third of the way into the ball's journey, the features change over one by one and the gradient edge fades in when the ball arrives.
Use it for
- A pricing section with two tiers, where the switch to the better plan deserves a moment.
- Inside an upgrade dialog or a settings page, where the price and what changes should be read at a glance.
- Any two-state choice with a strong second state, such as a pro mode.
Look elsewhere when
- Ordinary on and off settings: use the elastic switch, which is smaller and quieter.
- Three or more plans: show them side by side so they can be compared.
Usage
import { useState } from 'react'
import { PlanToggle } from './PlanToggle.jsx'
const plans = [
{ name: 'Basic', price: 19, period: '/mo', note: 'billed monthly', features: ['8 classes a month', 'Open gym'] },
{ name: 'Unlimited', price: 34, period: '/mo', note: 'billed monthly', features: ['Every class', 'Sauna and recovery'] },
]
export function Membership() {
const [unlimited, setUnlimited] = useState(false)
return (
<PlanToggle
label="Unlimited plan"
offLabel="Go unlimited"
onLabel="Unlimited"
checked={unlimited}
onCheckedChange={setUnlimited}
plans={plans}
/>
)
}Props
| Prop | Type | Default | What it does |
|---|---|---|---|
checked / defaultChecked / onCheckedChange | boolean / boolean / (checked) => void | - / false / - | Whether the second plan is chosen, controlled or uncontrolled. |
label | string | 'Upgrade plan' | Accessible name of the switch, read with its on or off state. |
offLabel / onLabel | ReactNode / ReactNode | 'Upgrade' / 'Premium' | offLabel invites the switch on the empty track; onLabel is the plan's name, uncovered by the flood. |
plans | [{ name, price, period?, note?, features? }, { … }] | — | The first and second plan. When given, a price card follows the switch: the price rolls, features change over and the edge lights up for the second plan. Without it only the switch renders. |
formatPrice | (price, plan) => string | (price) => `$${price}` | Turns a price into text. Its digits roll; every other character stays still. |
footer | ReactNode | (plan, checked) => ReactNode | — | Content at the bottom of the card, such as a button that names the chosen plan. |
disabled | boolean | false | Fades the switch and ignores presses and drags. |
...rest | HTMLAttributes | — | Other attributes go to the root <div>. |
Accessibility
- The track is a button with role="switch" and aria-checked, named by label; the words and the ball on it are hidden from assistive tech.
- Space and Enter toggle it, Right chooses the second plan and Left the first; focus shows a ring around the track.
- The card has a polite live region that reads the plan's name and price after a change; the rolling digits themselves are hidden.
- Touch: drag the ball sideways or tap anywhere on the track. A drag only starts once the finger moves sideways, so a vertical scroll that starts on the track still scrolls the page.
- Reduced motion moves the ball, the flood and the price straight to the new plan, with no rolling or stagger.
Motion
Ball and flood: --ds-duration-slower on cubic-bezier(0.6, 0, 0.25, 1.22), a slow start and a short overshoot that squashes the ball. Press: the ball shrinks to 95%. Price digits: --ds-duration-slower on --ds-ease-reveal, starting at 30% of the ball's run, the ones first and the tens 60ms later. Features and the plan name: rise 6px and fade in over --ds-duration-slow, --ds-stagger apart. Card edge: fades in over --ds-duration-slow once the ball is nearly there.
Add it to your project
Pro members copy a prompt and their coding agent installs the source, the same way as the free components.
PlanToggle.jsxplan-toggle.csstokens.cssREADME.md
Both files install together. The stylesheet reads the design tokens in tokens.css and carries fallbacks, so it also works alone.







