GitHub

Theme Provider

Context provider for theme management (light/dark mode)

Basic Usage

Loading...

Installation

pnpm add @corew500/ui

Usage

import { ThemeProvider } from "@corew500/ui/theme-provider"

<ThemeProvider>Content</ThemeProvider>

API Reference

Props

PropTypeDefaultDescription
themesstring[]List of all available theme names
forcedThemestringForced theme name for the current page
enableSystemenumtrueWhether to switch between dark and light themes based on prefers-color-scheme
disableTransitionOnChangeenumtrueDisable all CSS transitions when switching themes
enableColorSchemeenumWhether to indicate to browsers which color scheme is used (dark or light) for built-in UI like inputs and buttons
storageKeystringKey used to store theme setting in localStorage
defaultThemestringsystemDefault theme name (for v0.0.12 and lower the default was light). If `enableSystem` is false, the default theme is light
attributeenumclassHTML attribute modified based on the active theme. Accepts `class`, `data-*` (meaning any data attribute, `data-mode`, `data-color`, etc.), or an array which could include both
valueValueObjectMapping of theme name to HTML attribute value. Object where key is the theme name and value is the attribute value
noncestringNonce string to pass to the inline script and style elements for CSP headers
scriptPropsScriptPropsProps to pass the inline script

Accessibility

Additional

  • - Theme preference persists across sessions via localStorage
  • Respects user's system-level color scheme preference by default
  • No flash of incorrect theme on page load (next-themes handles this)

Localization

Translatable Content

  • - No translatable strings; theme names are internal ("light", "dark", "system")

Related

Related Components