Skip to main content
Available in Uniwind 1.4.0+

Overview

ScopedTheme lets you apply a theme to a specific subtree without changing the global app theme. This is useful for previews, isolated surfaces (cards, modals, panels), and mixed-theme layouts where multiple themes need to exist on screen at the same time. The nearest ScopedTheme wins, so nested scopes work naturally.
ScopedTheme is a runtime theme boundary. Components, hooks, and withUniwind wrapped components inside the boundary resolve styles against the scoped theme.

Usage

Basic Example

Common Patterns

Side-by-Side Theme Previews

Nested Scoped Themes

Nested scopes are great for documentation previews and component galleries where you want to compare variants without changing global theme state.

Hooks and withUniwind in a Scoped Theme

Hooks and HOCs resolve against the closest ScopedTheme boundary.
  • useUniwind() returns the scoped theme name
  • useResolveClassNames() resolves class names using scoped theme variables
  • useCSSVariable() reads CSS variables from the scoped theme
  • withUniwind() mappings use values resolved from the scoped theme

Example

API Reference

Component Signature

Props

theme
string
required
Theme name to apply to this subtree. The theme must exist in your configured Uniwind theme definitions (for example, light, dark, or a custom theme like coffee).
children
React.ReactNode
required
React children rendered inside the scoped theme boundary.

Behavior Notes

  • ScopedTheme affects only its descendants
  • It does not change the global app theme
  • Nested scopes override parent scopes for their own subtree
  • Multiple scopes can render side by side on the same screen

Theming Basics

Learn how to set up themes in Uniwind

Custom Themes

Define custom themes like coffee

useUniwind

Read the current theme and adaptive theme state

useCSSVariable

Read theme variables directly in JavaScript

useResolveClassNames

Resolve class names into style objects at runtime

withUniwind

Add className support to third-party components