ui-kit0.0

Signature

Theme switch

Smooth light and dark transitions.

When to use

  • App and docs headers where the user should choose between light, dark and following the system.
  • If you only need a two-state toggle, call useTheme().toggle() from your own button.

Sizes and instant swap

size="sm" makes the options 24px; reveal={false} swaps instantly with no transition.

API

ThemeSwitch

PropTypeDefaultDescription
revealbooleantrueCircular reveal from the clicked option via the View Transitions API. Falls back to an instant swap.
size'sm' | 'md''md'Options are 24 / 28px (36px on touch screens).
labelstring'Theme'Accessible name of the group.
...propsHTMLAttributes<HTMLDivElement>—Forwarded to the group, including ref and className.

It reads and writes the same state as useTheme() (stored in localStorage and applied by the theme script), so it stays in sync with any other control.

Keyboard

KeyAction
TabMoves into and out of the group (one stop: the selected option).
← → ↑ ↓Selects the previous / next option.
Home / EndSelects the first / last option.
Space / EnterSelects the focused option.

Accessibility

  • A radio group: role="radiogroup" with three role="radio" options, aria-checked and a roving tabindex. Selection follows focus.
  • Each icon-only option has an accessible name (Light, Dark, System) and a tooltip title.
  • The pill is decorative (aria-hidden). Keyboard focus shows the 3px ring.

Motion

  • Pill: one element measured by useIndicator and moved with transform on --ui-spring-morph (550ms). The first placement is never animated.
  • Reveal: document.startViewTransition() swaps the theme; the new snapshot is clipped by circle(0 → farthest corner) centred on the click point, 520ms, cubic-bezier(0.22, 1, 0.36, 1). While it runs, <html data-ui-reveal> turns off the browser’s default cross-fade.
  • Keyboard activation reveals from the centre of the focused option.
  • Reduced motion: no transition at all — the theme swaps instantly and the pill jumps. Browsers without View Transitions behave the same.