# Light / dark theme (1.11.1) Theme logic from the plugin, the look in the project. The plugin provides: a pre-paint script (no flash of the light theme), an unstyled switcher, the `useTheme` hook, fields in Site Settings → Theme, and a Turnstile widget theme that matches the page. ## How it works - Pages are ISR/SSG — one HTML for everyone, so the theme does **not** go into the server HTML. - `` (an inline script, the first child of ``) sets `data-theme="light|dark"` and `color-scheme` on `` before the first paint. - Order: the visitor's choice from `localStorage` (key `ipal-theme`, only when "Allow theme toggle" is on) → Site Settings → Default theme → with `System`, the device setting (`prefers-color-scheme`). - `localStorage`, not a cookie: it is an interface preference, it does not track and needs no consent. - A change in one tab carries over to the others (the `storage` event). ## Site Settings → Theme | Field | Meaning | |---|---| | `defaultTheme` | `light` · `dark` · `system` (since 1.11.1) | | `allowThemeToggle` | show the switcher; the visitor's choice is remembered | | `themeToggleLabel` | the switcher name for screen readers, e.g. "Tryb ciemny" (localized, since 1.11.1) | `getSiteShell(locale).theme` → `{ defaultTheme, allowToggle, toggleLabel }` (`themeConfigFrom(settings)` from the root entry). ## Wiring ```tsx // src/app/(frontend)/[locale]/layout.tsx const shell = await getSiteShell(locale) return ( {/* theme → at the start */}
… ``` Without `SiteProviders`: `import { ThemeScript } from '@intecion/ipal-kit/rsc'` and `` as the first child of ``. `suppressHydrationWarning` on `` is needed — the attribute differs from the server HTML on purpose. ```tsx // switcher ('use client' or in an RSC — it is a client component itself) import { ThemeSwitcher } from '@intecion/ipal-kit/client' (t === 'light' ? : )} // default lucide Sun / Moon /> ``` `