Theme provider
RequiredContext owner and document class/data-attribute synchronizer.
Theme & media
Application-level dark/light and accent state, persistence, reduced-motion configuration, and a ready-made switch action.
ThemeProvideruseThemeThemeToggleThemeAccentaccentNamesThemeContextValueThemeProviderPropsConfigure the production component, inspect it at responsive widths, copy synchronized JSX, and share the exact state from one workspace.
Document theme
The active theme is dark.
This JSX stays synchronized with the controls and uses only public package APIs.
'use client';
import { ThemeProvider, ThemeToggle } from '@ai-created/ui';
export function App() {
return (
<ThemeProvider>
<header>
<ThemeToggle />
</header>
<main>Your application</main>
</ThemeProvider>
);
}
import { ThemeProvider, ThemeToggle, useTheme } from '@ai-created/ui';Client boundary
'use client' to the file that owns this interactive state.Replace the version placeholder with the release tag your product has reviewed.
npm install --install-links "git+https://github.com/TheMarco/ai-created-ui.git#vX.Y.Z"@import '@ai-created/ui/styles/tokens.css';
@tailwind base;
@tailwind components;
@tailwind utilities;module.exports = {
presets: [require('@ai-created/ui/tailwind-preset')],
content: [
'./src/**/*.{js,ts,jsx,tsx,mdx}',
'./node_modules/@ai-created/ui/src/**/*.{js,ts,jsx,tsx}',
],
};Named regions define what belongs to the component, what remains optional, and where semantic responsibility lives.
Context owner and document class/data-attribute synchronizer.
Global reduced-motion policy set to user preference.
Optional 44px icon action that reads and changes context.
buttonDocument hook that activates dark/light semantic token overrides and native color-scheme.
html.lightDocument hook selecting the active accent scheme.
html[data-accent]The Figma-equivalent asset model, auto-layout, resizing, properties, slots, content bounds, localization, and governance contract.
Asset kind
provider
Design library name
Code-only asset
Maturity
stable
Last reviewed
2026-08-29
Canvas applicability
ThemeProvider and useTheme have no canvas geometry. Represent dark and light through Figma variable modes; document ThemeToggle separately as the visible consumer.
| Property | Type | Default | Code mapping | Options or notes |
|---|---|---|---|---|
| Theme mode | variant | dark | ThemeProvider context and the dark or light Figma variable mode | dark, light |
| Accent scheme | variant | red | ThemeProvider context and active data-accent selector | red, green, blue, orange, yellow, purple, teal, pink, magenta |
| Application subtreeRequired | slot | None | ThemeProvider children | No additional constraint |
Stores and exposes the active mode and accent scheme.
ThemeProvider and useThemeHonors the user reduced-motion preference.
MotionConfig inside ThemeProviderReady-made visible mode switch.
ThemeToggleOverflow: Remove nested ownership unless an isolated preview explicitly requires it.
Multiple competing global theme owners cause inconsistent persistence.
Translatable: ThemeToggle accessible label and title
No provider geometry; all descendants retain their own responsive contracts.
Not applicable to provider
Accountable owner
Design systems theming foundations owner
Canonical source: src/components/ThemeProvider.tsx
These measurements and semantic tokens define the supported visual contract. Local overrides should preserve the same hierarchy and interaction cues.
ThemeToggle target
44 × 44px
ThemeToggle icon
18 × 18px
Appearance transition
300ms colors / 500ms hero images
Toggle tap scale
0.85×
Toggle hover scale
1.1×
--color-bg / surface / surface2Theme foundations.
--color-text / text2 / text3Theme typography hierarchy.
--color-accent* / --color-action-primary* / --color-focus / --color-selectionRole-tuned active accent scheme colors.
--color-success / warning / info / error*Stable feedback semantics that never follow the accent.
--motion-base / --motion-slowTheme and image transitions.
A component is not complete until its passive, interactive, disabled, and exceptional states remain understandable in both themes.
Semantics, accessible naming, keyboard behavior, focus and announcements are implementation requirements, not optional documentation.
Use the public package API and preserve the controlled-state, native-attribute, and ref contracts described below.
import { ThemeProvider, ThemeToggle, useTheme } from '@ai-created/ui';Client Component required
<ThemeProvider defaultAccent="blue"><ThemeToggle /><App /></ThemeProvider>These props and helpers are compatibility contracts. Changes require migration guidance and release notes.
| Prop | Type | Default | Contract |
|---|---|---|---|
| ThemeProvider.children | ReactNode | required | Application subtree. |
| ThemeProvider.accent | Accent | undefined | Controlled, fixed accent; wins over storage and defaults. |
| ThemeProvider.defaultAccent | Accent | red | Uncontrolled fallback after storage and document accent. |
| ThemeProvider.onAccentChange | (accent: Accent) => void | undefined | Receives setAccent requests in either mode; controlled changes are not persisted. |
| useTheme().theme | dark | light | dark | Current theme. |
| useTheme().accent | Accent | red | Current accent scheme. |
| useTheme().setAccent | (accent: Accent) => void | undefined | Persists uncontrolled changes; controlled mode reports through the callback or is a no-op. |
| useTheme().toggleTheme | () => void | undefined | Switches and persists the theme. |
| ThemeToggle | component | undefined | Ready-made theme switch control. |
These rules keep the component recognizable across products without preventing deliberate composition.
The component should be verified as rendered UI, an interaction model, an accessibility surface, and a theme-aware visual artifact.