UI

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

$19$24per month, billed yearly
Loading interactive preview…

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.

ArgumentType / defaultDescription
labelstringDefault: "Billing period"Accessible name of the group, e.g. "Billing period". It is announced, not shown.
optionsBillingToggleOption[]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.
defaultValuestring—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.
sizemd | lgDefault: "md"Per-option height: 36 pixels (md) or 44 pixels (lg).
tonesuccess | accent | neutralDefault: "success"The tint the savings note takes once its option is chosen: success (Arc default), the theme accent, or neutral ink.
disabledbooleanDefault: falseThe whole control is unavailable and leaves the tab order.
namestring—Hidden input name, so a native form submit reports the chosen value.
recipestudio | softDefault: "studio"Visual treatment. Both recipes use the same interaction behavior.
themeBillingToggleTheme—Color mode, accent, and tokens, including the savings note accent. See Theming.
motionnone | subtle | expressiveDefault: "subtle"Thumb and savings note animation preset. System reduced-motion preferences take precedence.
motionOptionsBillingToggleMotionOptions—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).
dirltr | rtl—Reading direction; the first option sits at the inline start. Omit it to inherit the page direction.

React integration

PropPurpose
value, onValueChangeControlled option value (string). onValueChange fires in both modes.
refRef to the root role="radiogroup" <div> element.
presetApplication defaults (size, tone, recipe, theme, motion).
tokensCSS custom properties (--ui-*) applied after the typed theme.
className, styleApplied to the root <div>, which carries the resolved theme and motion.
Native attributesForwarded 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.

PropTypeDefaultPurpose
amountnumber—Current numeric price rendered with rolling odometer digits.
wasnumber—Previous price; shown inside <del> only when was > amount.
currencystring'$'Currency symbol shown before the rolling amount and <del> price.
periodstring—Billing cadence label after the price; swaps in place when it varies.
decimalsnumber0Fixed fraction digits passed to Intl.NumberFormat.
localestring'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.
themeBillingToggleTheme—Color mode, accent, and semantic design token overrides.
tokensCssTokens—CSS custom properties (--ui-*) applied after the typed theme.
refRef<HTMLSpanElement>—Ref to the root <span> element.
className, stylestring, CssTokens—Applied to the root <span> after resolved theme tokens.
Native attributesHTMLAttributes<HTMLSpanElement>—Forwarded to the root <span> (id, aria-*, data-*).

Keyboard & accessibility

KeyInteraction
TabMoves focus into or out of the group on the currently selected radio button.
ArrowRight, ArrowLeftSelects and focuses the next or previous option with wrap; mirrors in rtl.
ArrowDown, ArrowUpSelects and focuses the next or previous option with wrap.
Home, EndSelects 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 ResizeObserver and glides on the critically damped smooth spring (0.4s, bounce 0). Override motionOptions.glide with a custom spring or millisecond tween.
  • Badge and period swap: changing badge or period text rises 0.45em through a 2px blur over 240ms (enter curve) while leaving text exits -0.45em over 160ms (standard curve). Override motionOptions.swap for badge transitions.
  • Rolling price and <del> width: BillingPrice spins 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: reduce removes thumb travel, digit wheel travel, blur, width animation, and active press scale (0.97), keeping 120ms opacity crossfades. Setting motion="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": []
}

On this page