Billing
A billing period switch with a gliding thumb, a self-rewriting savings badge, and a companion rolling price display.
import { BillingToggle } from '@uthereal/ui/billing-toggle'Billing toggle playground
Overview
BillingToggle renders a pill radiogroup for switching between billing periods. A single measured thumb glides to the chosen option on a critically damped spring, and any savings badge on that option tints and rewrites its label in place without shifting neighboring options.
Pair BillingToggle with the companion BillingPrice export to animate pricing changes. BillingPrice rolls each digit on an odometer wheel, slides in a struck-through previous price (<del>) when was exceeds amount, and eases the period label width as copy changes. Use BillingToggle for pricing cadences and promotional savings notes. Use Tabs for switching views in place or Radio for general mutually exclusive options.
Usage
'use client'
import { useState } from 'react'
import { BillingPrice, BillingToggle } from '@uthereal/ui/billing-toggle'
const options = [
{ value: 'monthly', label: 'Monthly' },
{
value: 'yearly',
label: 'Yearly',
badge: 'Save 20%',
activeBadge: 'You save 20%',
},
]
export function PlanBilling() {
const [period, setPeriod] = useState('yearly')
const yearly = period === 'yearly'
return (
<div>
<BillingToggle
label="Billing period"
options={options}
value={period}
onValueChange={setPeriod}
/>
<BillingPrice
amount={yearly ? 19 : 24}
was={yearly ? 24 : undefined}
period={yearly ? 'per month, billed yearly' : 'per month'}
/>
</div>
)
}Omit value for an uncontrolled switch initialized from defaultValue (or the first option when omitted). Pass name to render a synchronized <input type="hidden"> for native form submission.
Examples
Multi-tier options and rewriting badges
Each option accepts a resting badge and an optional activeBadge. All badge variants for an option share one grid cell so the pill reserves the widest label and never resizes on selection. Configure two to six options for multi-tier cadences such as monthly, yearly, and lifetime plans, and set tone to success, accent, or neutral to control the active badge tint.
API reference
These serializable arguments and defaults come directly from the component schema.
| Argument | Type / default | Description |
|---|---|---|
label | stringDefault: "Billing period" | Accessible name of the group, e.g. "Billing period". It is announced, not shown. |
options | BillingToggleOption[]Default: [{"value":"monthly","label":"Monthly"},{"value":"yearly","label":"Yearly","badge":"Save 20%"}] | The billing periods, in order: value (unique, reported when chosen), label, and optional badge and activeBadge savings notes. Two to six. |
defaultValue | string— | Value of the initially chosen period. Omit it to choose the first option. Later argument edits do not reset an existing instance; use value and onValueChange to control it. |
size | md | lgDefault: "md" | Per-option height: 36 pixels (md) or 44 pixels (lg). |
tone | success | accent | neutralDefault: "success" | The tint the savings note takes once its option is chosen: success (Arc default), the theme accent, or neutral ink. |
disabled | booleanDefault: false | The whole control is unavailable and leaves the tab order. |
name | string— | Hidden input name, so a native form submit reports the chosen value. |
recipe | studio | softDefault: "studio" | Visual treatment. Both recipes use the same interaction behavior. |
theme | BillingToggleTheme— | Color mode, accent, and tokens, including the savings note accent. See Theming. |
motion | none | subtle | expressiveDefault: "subtle" | Thumb and savings note animation preset. System reduced-motion preferences take precedence. |
motionOptions | BillingToggleMotionOptions— | The thumb's glide and the savings note rewrite, by pointer or arrow key: Arc's smooth spring and standard word swap by default, or a spring or a tween with a duration (ms). |
dir | ltr | rtl— | Reading direction; the first option sits at the inline start. Omit it to inherit the page direction. |
React integration
| Prop | Purpose |
|---|---|
value, onValueChange | Controlled option value (string). onValueChange fires in both modes. |
ref | Ref to the root role="radiogroup" <div> element. |
preset | Application defaults (size, tone, recipe, theme, motion). |
tokens | CSS custom properties (--ui-*) applied after the typed theme. |
className, style | Applied to the root <div>, which carries the resolved theme and motion. |
| Native attributes | Forwarded to the root <div> (id, aria-labelledby, data-*, handlers). |
BillingPrice props
BillingPrice is a standalone React component exported from @uthereal/ui/billing-toggle. It emits its own --ui-* theme tokens and inherits theme, recipe, motion, and locale from UtherealProvider when omitted.
| Prop | Type | Default | Purpose |
|---|---|---|---|
amount | number | — | Current numeric price rendered with rolling odometer digits. |
was | number | — | Previous price; shown inside <del> only when was > amount. |
currency | string | '$' | Currency symbol shown before the rolling amount and <del> price. |
period | string | — | Billing cadence label after the price; swaps in place when it varies. |
decimals | number | 0 | Fixed fraction digits passed to Intl.NumberFormat. |
locale | string | 'en-US' | BCP 47 locale for grouping and decimal marks; inherits provider. |
motion | 'subtle' | 'expressive' | 'none' | 'subtle' | Animation preset; system reduced motion takes precedence. |
recipe | 'studio' | 'soft' | 'studio' | Visual recipe; inherits provider when omitted. |
theme | BillingToggleTheme | — | Color mode, accent, and semantic design token overrides. |
tokens | CssTokens | — | CSS custom properties (--ui-*) applied after the typed theme. |
ref | Ref<HTMLSpanElement> | — | Ref to the root <span> element. |
className, style | string, CssTokens | — | Applied to the root <span> after resolved theme tokens. |
| Native attributes | HTMLAttributes<HTMLSpanElement> | — | Forwarded to the root <span> (id, aria-*, data-*). |
Keyboard & accessibility
| Key | Interaction |
|---|---|
Tab | Moves focus into or out of the group on the currently selected radio button. |
ArrowRight, ArrowLeft | Selects and focuses the next or previous option with wrap; mirrors in rtl. |
ArrowDown, ArrowUp | Selects and focuses the next or previous option with wrap. |
Home, End | Selects and focuses the first or last option. |
BillingToggle exposes role="radiogroup" named by label (or a caller-supplied aria-labelledby), with native <button type="button" role="radio"> items, aria-checked, and roving tabIndex (0 on the selected item, -1 on others). Setting disabled sets aria-disabled="true" on the group, disables every radio button, removes them from the tab order, and disables any hidden form input.
In BillingPrice, the animated digit wheels are hidden from assistive technology (aria-hidden="true"), and a visually hidden text node exposes the formatted amount directly. When was > amount, the previous price renders in a semantic <del> element. All layout properties use logical CSS for dir="rtl", the measured thumb anchors from the inline-start edge in both directions, and forced-colors: active maps the track, thumb, focus outline, disabled text, and badge to system colors.
Motion and theming
- Thumb glide: the raised thumb measures the selected button with
ResizeObserverand glides on the critically damped smooth spring (0.4s, bounce0). OverridemotionOptions.glidewith a custom spring or millisecond tween. - Badge and period swap: changing badge or period text rises
0.45emthrough a2pxblur over240ms(entercurve) while leaving text exits-0.45emover160ms(standardcurve). OverridemotionOptions.swapfor badge transitions. - Rolling price and
<del>width:BillingPricespins changed digits on odometer wheels and opens or closes the<del>and period slots on the smooth spring so adjacent layout never jumps. - Reduced motion:
prefers-reduced-motion: reduceremoves thumb travel, digit wheel travel, blur, width animation, and active press scale (0.97), keeping120msopacity crossfades. Settingmotion="none"makes all state and text updates immediate (0ms).
theme accepts the core and control token groups, plus surfaceSunken, borderSubtle, success, shadowResting, shortcutSize, fontFamilyDisplay, and the component token accent (--ui-billing-toggle-accent) for the active savings tint. Override --ui-billing-toggle-price-size via tokens or style on BillingPrice to change the display amount size (default 30px).
Composition
BillingToggle is a leaf component. Its selected option value is host state at /fields/instance-<id>/value, reconciled against options on configuration edits. See Building with agents.
{
"type": "BillingToggle",
"props": {
"label": "Billing period",
"defaultValue": "yearly",
"options": [
{ "value": "monthly", "label": "Monthly" },
{
"value": "yearly",
"label": "Yearly",
"badge": "Save 20%",
"activeBadge": "You save 20%"
}
]
},
"children": []
}