@jimka/typescript-ui / core / ThemeManager
Class: ThemeManager
Defined in: src/typescript/lib/core/Theme.ts:766
Singleton manager that applies a theme by writing CSS custom properties and inline styles onto the document root and body elements.
Example
import { ThemeManager, DefaultTheme, DarkTheme } from '@jimka/typescript-ui/core';
ThemeManager.setTheme(DefaultTheme); // light
ThemeManager.setTheme(DarkTheme); // darkConstructors
new ThemeManager()
new ThemeManager(): ThemeManagerReturns
Methods
getTheme()
static getTheme(): ThemeDefined in: src/typescript/lib/core/Theme.ts:818
Returns the currently active theme.
Returns
The Theme object that was last passed to setTheme, defaulting to DefaultTheme.
onThemeChange()
static onThemeChange(listener: () => void): () => voidDefined in: src/typescript/lib/core/Theme.ts:776
Subscribes a listener that is called whenever the active theme changes.
Parameters
listener
() => void
Called after CSS variables have been updated, so getComputedStyle returns new values.
Returns
Function
A cleanup function that removes the listener when called.
Returns
void
setTheme()
static setTheme(theme: Theme): voidDefined in: src/typescript/lib/core/Theme.ts:795
Applies a theme by writing CSS variables onto :root and updating body/html styles.
Parameters
theme
The theme object to activate.
Returns
void
Remarks
Sets document.documentElement.style.colorScheme, color, fontFamily, fontSize, and document.body.style.backgroundColor / color in addition to the CSS custom properties, so both CSS-variable consumers and direct inline-style consumers are updated. <html> is targeted (in addition to <body>) because Window components are appended to document.documentElement, so text in floating windows must inherit from <html>.