Prepared Docs

Prepared Docs

⌘K

    Loading navigation…

User

  1. Primitives
  2. Theme
  3. Usage

Theme

Usage

Overview

ThemeProvider applies Prepared’s Radix-based theme tokens to descendant ui-core components. Correct placement prevents token mismatch flashes, ensures server and client agree on initial theme, and avoids double-wrapping that confuses debugging.

When to use

  • Application roots (dispatch, docs, Storybook preview) where the majority tree should share tokens.
  • Isolated previews (component playground) that must render with a specific theme for screenshots.

When not to use

  • Embedded widgets that cannot control global Radix settings—scope via container classes per integration constraints instead of nested providers fighting the host app.
  • Short-lived portals that should inherit the parent theme—avoid redundant providers unless isolation is explicit.

Variants

Light/dark/system preference should follow user settings; persist choice per account when product requirements demand continuity across devices.

Anatomy

Provider wrapping the React subtree; Theme toggle components read/write preference stores as implemented per app.

Content guidelines

User-facing theme labels (“Dark”, “Light”, “System”) use formatMessage.

Behavior and states

  • Prevent flash of incorrect theme on load via inline critical script, SSR hints, or cookie agreement—match app architecture.
  • Avoid mounting multiple competing providers in one tree unless testing isolation.

Best practices

  • Do nest only one provider per production tree unless a deliberate sandbox requires otherwise.
  • Do test high-contrast focus rings and charts in both themes.
  • Don’t toggle theme rapidly in response to noisy system events—debounce.
  • Don’t store secrets or PII in theme persistence mechanisms.

Accessibility

  • Ensure theme switches are keyboard operable and state is announced politely.
  • Verify color tokens still meet contrast requirements in both themes for text, icons, and charts.

Related Components

  • Engineering docs on app bootstrap and Radix configuration.
  • Typography and Text for token-driven type ramps.

Previous

Text / Accessibility

Next

Theme / API and Development

On this page

Overview
When to use
When not to use
Variants
Anatomy
Content guidelines
Behavior and states
Best practices
Accessibility
Related Components