JavaScript API
Use the JavaScript API to dynamically change themes at runtime.
Import
import { setTheme, getTheme, themes, initTheme } from 'ospinajuanp-reset-css/api';Functions
| Name | Type | Default | Description |
|---|---|---|---|
| initTheme | (themeName?: ThemeName) => void | undefined | Initialize the theme. If no theme is provided, defaults to system preference. |
| setTheme | (themeName: ThemeName) => void | - | Set the current theme to one of the available themes. |
| getTheme | () => ThemeName | "simple" | - | Get the current active theme. Returns "simple" as default if no theme has been set. |
| themes | ThemeName[] | - | Array of all available theme names. |
Type Definitions
type ThemeName = 'simple' | 'dark' | 'pastel' | 'darkBluePastel' | 'lightBluePastel' | 'retro';Usage Example
import { setTheme, getTheme, themes, initTheme } from 'ospinajuanp-reset-css/api';
// Initialize with a specific theme
initTheme('dark');
// Or set theme later
setTheme('pastel');
// Get current theme
console.log(getTheme()); // 'pastel'
// Available themes
console.log(themes);
// ['simple', 'dark', 'pastel', 'darkBluePastel', 'lightBluePastel', 'retro']Use Cases
- User theme preference toggles
- Theme switchers in settings
- Dynamic theme loading based on user preference