Interfaces
CookieOptions
Defined in: react/src/static/types.ts:49
Cookie security options for theme persistence
Properties
maxAge?
readonlyoptionalmaxAge:number
Defined in: react/src/static/types.ts:55
Max age in seconds. Default: 31536000 (1 year)
path?
readonlyoptionalpath:string
Defined in: react/src/static/types.ts:57
Cookie path. Default: ’/‘
sameSite?
readonlyoptionalsameSite:"Strict"|"Lax"|"None"
Defined in: react/src/static/types.ts:51
SameSite attribute for CSRF protection. Default: ‘Lax’
secure?
readonlyoptionalsecure:boolean
Defined in: react/src/static/types.ts:53
Force Secure flag. Default: auto-detect from protocol (true on HTTPS)
CreateDynamicThemeProviderOptions
Defined in: react/src/types/index.ts:28
Options for createDynamicThemeProvider factory function
Type Parameters
T
T extends SchemaDefinition
Properties
schema
readonlyschema:Schema<T>
Defined in: react/src/types/index.ts:30
The schema defining the theme structure
CreateStaticThemeProviderOptions
Defined in: react/src/static/types.ts:14
Options for createStaticThemeProvider factory function
Type Parameters
TThemes
TThemes extends readonly string[]
Properties
defaultTheme
readonlydefaultTheme:TThemes[number]
Defined in: react/src/static/types.ts:20
Default theme to use as fallback
themes
readonlythemes:TThemes
Defined in: react/src/static/types.ts:18
Array of available theme names (use as const for type inference)
CssVariableOptions
Defined in: core/dist/index.d.ts:175
Options for CSS variable generation
Properties
prefix?
readonlyoptionalprefix:string
Defined in: core/dist/index.d.ts:177
Prefix for CSS variable names (default: none)
separator?
readonlyoptionalseparator:string
Defined in: core/dist/index.d.ts:179
Separator between path segments (default: ’-‘)
transformName()?
readonlyoptionaltransformName: (path) =>string
Defined in: core/dist/index.d.ts:181
Transform function for variable names
Parameters
path
string
Returns
string
DynamicThemeContextValue
Defined in: react/src/types/index.ts:104
Context value provided by DynamicThemeProvider
Type Parameters
T
T extends SchemaDefinition
Properties
cssVariables
readonlycssVariables:Record<string,string>
Defined in: react/src/types/index.ts:112
CSS variables as key-value object (empty if not ready)
error
readonlyerror:Error|null
Defined in: react/src/types/index.ts:128
The error if state.status === ‘error’, otherwise null
isError
readonlyisError:boolean
Defined in: react/src/types/index.ts:126
state.status === ‘error’
isIdle
readonlyisIdle:boolean
Defined in: react/src/types/index.ts:120
state.status === ‘idle’
isLoading
readonlyisLoading:boolean
Defined in: react/src/types/index.ts:122
state.status === ‘loading’
isReady
readonlyisReady:boolean
Defined in: react/src/types/index.ts:124
state.status === ‘ready’
refresh()
readonlyrefresh: () =>Promise<void>
Defined in: react/src/types/index.ts:114
Function to manually refresh the theme
Returns
Promise<void>
setThemeId()
readonlysetThemeId: (themeId) =>void
Defined in: react/src/types/index.ts:110
Function to change theme ID (triggers fetch)
Parameters
themeId
string
Returns
void
state
readonlystate:ThemeState<T>
Defined in: react/src/types/index.ts:106
Current theme state (discriminated union)
theme
readonlytheme:InferTheme<T> |null
Defined in: react/src/types/index.ts:118
The resolved theme (null if not ready)
themeId
readonlythemeId:string
Defined in: react/src/types/index.ts:108
Current theme identifier
DynamicThemeProviderExports
Defined in: react/src/types/index.ts:134
Return type of createDynamicThemeProvider factory
Type Parameters
T
T extends SchemaDefinition
Properties
DynamicThemeProvider
readonlyDynamicThemeProvider:FC<DynamicThemeProviderProps<T>>
Defined in: react/src/types/index.ts:136
React context provider component
ThemeContext
readonlyThemeContext:Context<DynamicThemeContextValue<T> |null>
Defined in: react/src/types/index.ts:144
The underlying React context (for advanced use)
useTheme()
readonlyuseTheme: () =>DynamicThemeContextValue<T>
Defined in: react/src/types/index.ts:138
Hook to access full theme and metadata
Returns
useThemeReady()
readonlyuseThemeReady: () =>boolean
Defined in: react/src/types/index.ts:142
Hook to check if theme is ready
Returns
boolean
useThemeValue()
readonlyuseThemeValue: <P>(path) =>PathValue<T,P>
Defined in: react/src/types/index.ts:140
Hook to access a single theme value by path
Type Parameters
P
P
Parameters
path
P
Returns
PathValue<T, P>
DynamicThemeProviderProps
Defined in: react/src/types/index.ts:55
Props for the DynamicThemeProvider component
Type Parameters
T
T extends SchemaDefinition
Properties
children
readonlychildren:ReactNode
Defined in: react/src/types/index.ts:79
Children
cookieOptions?
readonlyoptionalcookieOptions:CookieOptions
Defined in: react/src/types/index.ts:75
Cookie security options (only used when persist=‘cookie’)
cssOptions?
readonlyoptionalcssOptions:CssVariableOptions
Defined in: react/src/types/index.ts:69
CSS variable options (prefix, separator, etc.)
fallback?
readonlyoptionalfallback:ReactNode
Defined in: react/src/types/index.ts:63
Fallback UI while loading
initialTheme?
readonlyoptionalinitialTheme:InferTheme<T>
Defined in: react/src/types/index.ts:61
Pre-resolved theme for SSR (avoids hydration mismatch)
initialThemeId
readonlyinitialThemeId:string
Defined in: react/src/types/index.ts:57
Initial theme identifier - use setThemeId from useTheme() to change
injection?
readonlyoptionalinjection:InjectionMode
Defined in: react/src/types/index.ts:67
CSS injection strategy (default: ‘style-tag’)
nonce?
readonlyoptionalnonce:string
Defined in: react/src/types/index.ts:77
CSP nonce for style injection (for strict Content Security Policies)
onError()?
readonlyoptionalonError: (error) =>void
Defined in: react/src/types/index.ts:65
Error callback
Parameters
error
Error
Returns
void
persist?
readonlyoptionalpersist:PersistMode
Defined in: react/src/types/index.ts:71
Where to persist theme preference on change (default: ‘none’)
resolver
readonlyresolver:ThemeResolver<T>
Defined in: react/src/types/index.ts:59
Theme resolver from @livery/core
storageKey?
readonlyoptionalstorageKey:string
Defined in: react/src/types/index.ts:73
Storage key name (default: ‘theme’)
Schema
Defined in: core/dist/index.d.ts:96
A validated schema created by createSchema()
Type Parameters
T
T extends SchemaDefinition = SchemaDefinition
Properties
[SCHEMA_BRAND]
readonly[SCHEMA_BRAND]:true
Defined in: core/dist/index.d.ts:97
definition
readonlydefinition:T
Defined in: core/dist/index.d.ts:98
StaticThemeContextValue
Defined in: react/src/static/types.ts:87
Context value provided by StaticThemeProvider
Type Parameters
TThemes
TThemes extends readonly string[]
Properties
setTheme()
readonlysetTheme: (theme) =>void
Defined in: react/src/static/types.ts:91
Function to change theme
Parameters
theme
TThemes[number]
Returns
void
theme
readonlytheme:TThemes[number]
Defined in: react/src/static/types.ts:89
Current theme name
themes
readonlythemes:TThemes
Defined in: react/src/static/types.ts:93
Array of available theme names
StaticThemeProviderExports
Defined in: react/src/static/types.ts:26
Return type of createStaticThemeProvider factory
Type Parameters
TThemes
TThemes extends readonly string[]
Properties
StaticThemeProvider
readonlyStaticThemeProvider:FC<StaticThemeProviderProps<TThemes>>
Defined in: react/src/static/types.ts:30
React context provider component
ThemeContext
readonlyThemeContext:Context<StaticThemeContextValue<TThemes> |null>
Defined in: react/src/static/types.ts:34
The underlying React context (for advanced use)
useTheme()
readonlyuseTheme: () =>StaticThemeContextValue<TThemes>
Defined in: react/src/static/types.ts:32
Hook to access theme and setTheme
Returns
StaticThemeContextValue<TThemes>
StaticThemeProviderProps
Defined in: react/src/static/types.ts:63
Props for the StaticThemeProvider component
Type Parameters
TThemes
TThemes extends readonly string[]
Properties
attribute?
readonlyoptionalattribute:string
Defined in: react/src/static/types.ts:73
DOM attribute to sync (default: ‘data-theme’)
children
readonlychildren:ReactNode
Defined in: react/src/static/types.ts:65
Children
cookieOptions?
readonlyoptionalcookieOptions:CookieOptions
Defined in: react/src/static/types.ts:75
Cookie security options (only used when persist=‘cookie’)
initialTheme?
readonlyoptionalinitialTheme:TThemes[number]
Defined in: react/src/static/types.ts:67
Initial theme for SSR (skips DOM detection)
nonce?
readonlyoptionalnonce:string
Defined in: react/src/static/types.ts:77
CSP nonce for style injection (for strict Content Security Policies)
persist?
readonlyoptionalpersist:PersistMode
Defined in: react/src/static/types.ts:69
Where to persist theme preference on change (default: ‘localStorage’)
storageKey?
readonlyoptionalstorageKey:string
Defined in: react/src/static/types.ts:71
Storage key name (default: ‘theme’)
ThemeResolver
Defined in: core/dist/index.d.ts:155
A theme resolver instance
Type Parameters
T
T extends SchemaDefinition
Methods
clearCache()
clearCache():
void
Defined in: core/dist/index.d.ts:165
Clear all cached themes
Returns
void
get()
get<
P>(params):Promise<PathValue<T,P>>
Defined in: core/dist/index.d.ts:167
Get a value at a specific path
Type Parameters
P
P
Parameters
params
path
P
themeId
string
Returns
Promise<PathValue<T, P>>
invalidate()
invalidate(
params):void
Defined in: core/dist/index.d.ts:161
Invalidate cached theme for a theme ID
Parameters
params
themeId
string
Returns
void
resolve()
resolve(
params):Promise<InferTheme<T>>
Defined in: core/dist/index.d.ts:157
Resolve theme for a theme ID, using cache if available
Parameters
params
themeId
string
Returns
Promise<InferTheme<T>>
ThemeStoreState
Defined in: react/src/types/index.ts:155
Internal state shape for the theme store. Uses ThemeState discriminated union for type-safe state management.
Type Parameters
T
T extends SchemaDefinition
Properties
cssVariables
readonlycssVariables:Record<string,string>
Defined in: react/src/types/index.ts:158
state
readonlystate:ThemeState<T>
Defined in: react/src/types/index.ts:156
themeId
readonlythemeId:string|null
Defined in: react/src/types/index.ts:157
Type Aliases
InferTheme
InferTheme<
T> =\{ [K in keyof T]: T[K] extends TokenDefinition ? TokenTypeToValue<T[K]> : T[K] extends SchemaDefinition ? InferTheme<T[K]> : never \}
Defined in: core/dist/index.d.ts:108
Infers the theme type from a schema definition Recursively processes nested groups
Type Parameters
T
T extends SchemaDefinition
InjectionMode
InjectionMode =
"style-tag"|"inline"|"none"
Defined in: react/src/types/index.ts:23
CSS injection strategy for the DynamicThemeProvider
PathValue
PathValue<
T,P> =Pextends`$\{infer Head\}.$\{infer Tail\}`?Headextends keyofT?T[Head] extendsSchemaDefinition?PathValue<T[Head],Tail> :never:never:Pextends keyofT?T[P] extendsTokenDefinition?TokenTypeToValue<T[P]> :T[P] extendsSchemaDefinition?InferTheme<T[P]> :never:never
Defined in: core/dist/index.d.ts:117
Gets the value type at a specific path in the theme
Type Parameters
T
T extends SchemaDefinition
P
P extends string
PersistMode
PersistMode =
"localStorage"|"cookie"|"none"
Defined in: react/src/static/types.ts:44
Persistence strategy for theme preference
SchemaDefinition
SchemaDefinition =
object
Defined in: core/dist/index.d.ts:86
A schema definition can contain tokens or nested groups
Index Signature
[key: string]: SchemaDefinition | TokenDefinition
ThemePath
ThemePath<
T,Prefix> =\{ [K in keyof T & string]: T[K] extends TokenDefinition ? Prefix extends "" ? K : `$\{Prefix\}.$\{K\}` : T[K] extends SchemaDefinition ? ThemePath<T[K], Prefix extends "" ? K : `$\{Prefix\}.$\{K\}`> : never \}[keyofT&string]
Defined in: core/dist/index.d.ts:113
Helper to extract all valid paths from a schema Returns dot-notation paths like “colors.primary” or “spacing.md”
Type Parameters
T
T extends SchemaDefinition
Prefix
Prefix extends string = ""
ThemeState
ThemeState<
T> = {status:"idle"; } | {status:"loading"; } | {status:"ready";theme:InferTheme<T>; } | {error:Error;status:"error"; }
Defined in: react/src/types/index.ts:95
Theme state machine - discriminated union ensuring only valid states exist.
Valid states:
- idle: No theme loaded yet, no fetch in progress
- loading: Theme fetch in progress
- ready: Theme successfully loaded
- error: Theme fetch failed
Type Parameters
T
T extends SchemaDefinition
Functions
createDynamicThemeProvider()
createDynamicThemeProvider<
T>(options):DynamicThemeProviderExports<T>
Defined in: react/src/provider/create-provider.ts:80
Creates a fully-typed dynamic theme provider and hooks for a schema.
Use this for themes fetched at runtime from an API or database (e.g., multi-tenant SaaS). The provider handles async fetching, loading states, caching, and error handling.
For static bundled themes (light/dark mode), use createStaticThemeProvider instead.
Type Parameters
T
T extends SchemaDefinition
Parameters
options
CreateDynamicThemeProviderOptions<T>
Options containing the schema
Returns
DynamicThemeProviderExports<T>
Object with DynamicThemeProvider, useTheme, useThemeValue, useThemeReady, and ThemeContext
Example
import { createSchema, t, createResolver } from '@livery/core';
import { createDynamicThemeProvider } from '@livery/react';
// Define your schema
const schema = createSchema({
definition: {
brand: {
primary: t.color().default('#3b82f6'),
secondary: t.color().default('#64748b'),
},
spacing: {
md: t.dimension().default('16px'),
},
},
});
// Create resolver to fetch themes
const resolver = createResolver({
schema,
fetcher: async (themeId) => {
const res = await fetch(`/api/themes/${themeId}`);
return res.json();
},
cache: { ttl: 60000 },
});
// Create typed provider and hooks
const { DynamicThemeProvider, useTheme, useThemeValue } = createDynamicThemeProvider({ schema });
// Use in your app
function App() {
return (
<DynamicThemeProvider initialThemeId="acme" resolver={resolver}>
<MyComponent />
</DynamicThemeProvider>
);
}
function MyComponent() {
// Full type inference!
const primary = useThemeValue('brand.primary'); // string
const { theme, isLoading, setThemeId } = useTheme();
if (isLoading) return <Spinner />;
return <div style={{ color: primary }}>Hello</div>;
}createStaticThemeProvider()
createStaticThemeProvider<
TThemes>(options):StaticThemeProviderExports<TThemes>
Defined in: react/src/static/create-static-provider.ts:57
Creates a typed StaticThemeProvider and useTheme hook for static themes.
Use this for bundled themes (light/dark mode) where all theme CSS is
generated upfront with toCssStringAll(). Theme switching is instant
since it just changes the data-theme attribute.
For dynamic themes fetched from an API or database, use createDynamicThemeProvider instead.
Type Parameters
TThemes
TThemes extends readonly string[]
Parameters
options
CreateStaticThemeProviderOptions<TThemes>
Returns
StaticThemeProviderExports<TThemes>
Example
import { toCssStringAll } from '@livery/core';
import { createStaticThemeProvider, getThemeInitScript } from '@livery/react';
// 1. Generate CSS (include in <head>)
export const css = toCssStringAll({ schema, themes, defaultTheme: 'light' });
// 2. Generate init script (include in <head>)
export const initScript = getThemeInitScript({
themes: ['light', 'dark'],
defaultTheme: 'light',
});
// 3. Create provider and hook
export const { StaticThemeProvider, useTheme } = createStaticThemeProvider({
themes: ['light', 'dark'] as const,
defaultTheme: 'light',
});
// In your layout:
// <head>
// <style dangerouslySetInnerHTML={{ __html: css }} />
// <script dangerouslySetInnerHTML={{ __html: initScript }} />
// </head>
// <body>
// <StaticThemeProvider>{children}</StaticThemeProvider>
// </body>