UNPKG

polen

Version:

A framework for delightful GraphQL developer portals

68 lines 1.71 kB
/** * Theme management utilities using CSS-first approach with cookie persistence. * * Strategy: * - CSS `prefers-color-scheme` handles initial theme (no JS needed) * - User toggle sets cookie + updates DOM immediately * - Server reads cookie on next visit for SSR hydration match */ export interface ThemeManager { /** * Read theme preference from cookie */ readCookie(cookieString?: string): Theme | null; /** * Write theme preference to cookie */ writeCookie(theme: Theme): string; /** * Apply theme to DOM (sets class on document element) */ applyToDOM(theme: Theme): void; /** * Get current theme from DOM */ getCurrentFromDOM(): Theme | null; /** * Toggle theme and persist to cookie * Returns the new theme */ toggle(): Theme; /** * Set specific theme and persist to cookie */ set(theme: Theme): void; /** * Get CSS string for SSR injection * Includes prefers-color-scheme fallback and cookie-based override */ getCSS(): string; } export type Theme = `light` | `dark` | `system`; export interface ThemeOptions { /** * Cookie name for theme persistence * @default 'theme' */ cookieName?: string; /** * CSS class prefix for theme classes * @default '' */ classPrefix?: string; /** * Cookie max age in seconds * @default 31536000 (1 year) */ maxAge?: number; /** * Cookie path * @default '/' */ path?: string; } /** * Create a theme manager instance */ export declare const createThemeManager: (options?: ThemeOptions) => ThemeManager; //# sourceMappingURL=theme.d.ts.map