@trycourier/courier-ui-core
Version:
The core UI kit for Courier Web Components
77 lines (76 loc) • 2.45 kB
TypeScript
import { CourierComponentThemeMode, SystemThemeMode } from '../utils/system-theme-mode';
export interface CourierThemeSubscription<TTheme> {
manager: CourierThemeManager<TTheme>;
unsubscribe: () => void;
}
/**
* Abstract base class for theme management in Courier UI packages.
*
* This class provides:
* - Light/dark theme switching
* - System theme detection and auto-switching
* - Theme subscription/notification system
* - User mode override (light, dark, or system)
*
* Subclasses must implement:
* - getDefaultLightTheme(): return the default light theme
* - getDefaultDarkTheme(): return the default dark theme
* - mergeTheme(): merge user theme with defaults
*/
export declare abstract class CourierThemeManager<TTheme> {
protected abstract readonly THEME_CHANGE_EVENT: string;
protected abstract getDefaultLightTheme(): TTheme;
protected abstract getDefaultDarkTheme(): TTheme;
protected abstract mergeTheme(mode: SystemThemeMode, theme: TTheme): TTheme;
protected _theme: TTheme;
protected _lightTheme: TTheme;
protected _darkTheme: TTheme;
protected _target: EventTarget;
protected _subscriptions: CourierThemeSubscription<TTheme>[];
protected _userMode: CourierComponentThemeMode;
protected _systemMode: SystemThemeMode;
protected _systemThemeCleanup: (() => void) | undefined;
constructor(initialTheme: TTheme);
/**
* Set the light theme
*/
setLightTheme(theme: TTheme): void;
/**
* Set the dark theme
*/
setDarkTheme(theme: TTheme): void;
/**
* Get the current system theme
*/
get currentSystemTheme(): SystemThemeMode;
/**
* Get the current theme
*/
getTheme(): TTheme;
/**
* Update the theme based on current mode
*/
protected updateTheme(): void;
/**
* Set the theme and notify all listeners
*/
private setTheme;
/**
* Set the mode and notify all listeners
*/
setMode(mode: CourierComponentThemeMode): void;
/**
* Get the current mode
*/
get mode(): CourierComponentThemeMode;
/**
* Subscribe to theme changes
* @param callback - Function to run when the theme changes
* @returns - Object with unsubscribe method to stop listening
*/
subscribe(callback: (theme: TTheme) => void): CourierThemeSubscription<TTheme>;
/**
* Clean up event listeners
*/
cleanup(): void;
}