Skip to main content

Theming

PrismUI ships with a protocol-based theming system. Every component reads colors from the current PrismTheme via the SwiftUI environment, so switching themes updates your entire UI in one line.

PrismTheme Protocol

All themes conform to PrismTheme, which resolves semantic ColorToken values to concrete SwiftUI Color instances:
PrismTheme Protocol

Built-in Themes

PrismUI includes four themes out of the box:
Using a Built-in Theme

Custom Themes

Create your own theme by conforming to PrismTheme:
Custom Theme
Fall back to DefaultTheme().color(token) in your default case so you only need to override the tokens you care about.

PrismAutoTheme

PrismAutoTheme automatically switches between a light and dark theme based on the system appearance:
Auto Theme Switching

PrismThemeStore

PrismThemeStore is an @Observable class that manages theme state. Use it to let users switch themes at runtime:
Runtime Theme Switching

Reading Theme in Components

Access the current theme from the environment in any view:
Reading the Theme
All PrismUI components read from @Environment(\.prismTheme) automatically. You only need to access the environment directly when building custom components.