theme
Install the required plugin:
tynd add themeimport { theme } from "@tynd/plugin-theme/client";Wraps prefers-color-scheme with explicit user overrides (light / dark / system) and a palette mapper that writes CSS variables on every change.
API surface
Section titled “API surface”theme.configure(opts: ConfigureOptions): void— registerlight+darkpalettes (CSS-variable maps); the resolver writes them to:rootwhenever the effective theme changes.theme.preference(): ThemePreference— read the user’s current"light" | "dark" | "system"preference.theme.setPreference(pref): void— persist the user’s choice.theme.current(): EffectiveTheme— the actual theme being applied right now ("light" | "dark").theme.toggle(): void— flip between light and dark (resolves"system"to its effective value first).theme.onChange(handler)— fires every time the effective theme flips (system-driven or user-driven).theme.dispose(): void— tear down the resolver and detach all listeners.theme.systemPreferences(): Promise<SystemPreferences>— OS appearance snapshot (below).theme.onSystemPreferencesChange(handler): Promise<{ dispose() }>— fires with a fresh snapshot whenever any field changes (the OS is polled once a second). Rejects when the host watcher cannot start.
setPreference("light" | "dark") forces the page theme app-wide (CSS color-scheme and the palette); native window chrome follows tyndWindow.setTheme.
System preferences
Section titled “System preferences”const prefs = await theme.systemPreferences();document.documentElement.style.setProperty("--accent", prefs.accentColor ?? "#0a84ff");
const sub = await theme.onSystemPreferencesChange((next) => { document.body.classList.toggle("reduce-motion", next.reducedMotion === true);});sub.dispose();| Field | Type | Windows | macOS | Linux |
|---|---|---|---|---|
mode |
"light" | "dark" | "unspecified" |
yes | yes | portal / GTK |
accentColor |
"#rrggbb" | null |
accent color (DWM) | controlAccentColor |
null |
highContrast |
boolean | null |
high-contrast theme | “Increase contrast” | null |
reducedMotion |
boolean | null |
“Animation effects” off | “Reduce motion” | null |
reducedTransparency |
boolean | null |
“Transparency effects” off | “Reduce transparency” | null |
null means the OS exposes no desktop-neutral source for the field.