Generic Theme Manager
Manages theme state, persistence, and change notifications. Applications can register themes and switch between them.
// Define your theme interfaceinterface MyTheme extends BaseTheme { background: number; text: number; accent: number;}// Create theme managerconst themeManager = new ThemeManager<MyTheme>('my-app-theme');// Register themesthemeManager.registerTheme({ name: 'Dark', variant: 'dark', theme: { background: 0x1e1e1e, text: 0xffffff, accent: 0x4a90e2 }});// Set themethemeManager.setTheme('Dark');// Get current themeconst theme = themeManager.getTheme(); Copy
// Define your theme interfaceinterface MyTheme extends BaseTheme { background: number; text: number; accent: number;}// Create theme managerconst themeManager = new ThemeManager<MyTheme>('my-app-theme');// Register themesthemeManager.registerTheme({ name: 'Dark', variant: 'dark', theme: { background: 0x1e1e1e, text: 0xffffff, accent: 0x4a90e2 }});// Set themethemeManager.setTheme('Dark');// Get current themeconst theme = themeManager.getTheme();
Key for localStorage persistence (e.g., 'my-app-theme')
Optional
Default theme name to use if none is set
Add a theme change listener
Clear persisted theme
Get all registered themes
Get the current theme
Get the current theme info
Get themes by variant
Register a theme
Register multiple themes at once
Remove a theme change listener
Set theme by name
Set theme by ThemeInfo
Generic Theme Manager
Manages theme state, persistence, and change notifications. Applications can register themes and switch between them.
Example