Theme key 'theme', storage keys in the cookie scanner, type in the cookie list
- Theme choice in localStorage under 'theme' (next-themes' key and values)
instead of 'ipal-theme'. ThemeScript moves an old choice before the first
paint and removes the old key; useTheme / ThemeSwitcher do the same
without the script. ipalKit({ theme: { storageKey } }) sets an own key,
which reaches ThemeScript through getSiteShell().theme and <html
data-theme-storage>.
- The cookie scanner declares the theme key (Theme choice: local storage,
necessary, until changed or site data is cleared) when the theme switch
is on, so Scan cookies finds it without a crawl.
- Cookies -> Cookie list rows get a Type (cookie / local storage / session
storage, default cookie, shared by every language), filled by scan, review
and approval. The detailed settings window and <CookieTable> show it with
English and Polish defaults; the approval page marks storage entries.
- Migration: adds cookie_settings_cookies.storage (DEFAULT 'cookie') and
cookie_settings_locales.detail_labels_storage, nothing else.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
6998b44431
commit
b5368cdc61
+21
-7
@@ -9,11 +9,23 @@ widget theme that matches the page.
|
||||
- Pages are ISR/SSG — one HTML for everyone, so the theme does **not** go into the server HTML.
|
||||
- `<ThemeScript>` (an inline script, the first child of `<body>`) sets `data-theme="light|dark"` and
|
||||
`color-scheme` on `<html>` before the first paint.
|
||||
- Order: the visitor's choice from `localStorage` (key `ipal-theme`, only when "Allow theme toggle" is on)
|
||||
- Order: the visitor's choice from `localStorage` (key `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.
|
||||
- `localStorage`, not a cookie: it is an interface preference the visitor chose themselves, it does not
|
||||
track and needs no separate consent (CNIL treats such a preference as strictly necessary). The cookie
|
||||
scanner declares it as **necessary**, local storage — an editor can change that on review.
|
||||
- A change in one tab carries over to the others (the `storage` event).
|
||||
|
||||
## The storage key (`theme`)
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
| Default key | `theme`, values `light` / `dark` — the key and values next-themes uses (`THEME_STORAGE_KEY`) |
|
||||
| Own key | `ipalKit({ theme: { storageKey: 'acme-theme' } })` → `getSiteShell(locale).theme.storageKey` → `<ThemeScript>` uses it and puts it on `<html data-theme-storage>`, so `useTheme` / `<ThemeSwitcher>` use the same key with no extra prop (`<ThemeSwitcher storageKey>` / `useTheme({ storageKey })` to set it by hand) |
|
||||
| Old key | before this change the key was `ipal-theme` (`LEGACY_THEME_STORAGE_KEY`). When the current key is empty and `ipal-theme` holds `light` / `dark`, `<ThemeScript>` moves it **before the first paint** (no flash) and removes `ipal-theme`; `useTheme` / `<ThemeSwitcher>` do the same on pages without the script (`migrateThemeStorage(key)`). A choice already under the current key wins; the old key is removed anyway |
|
||||
| next-themes | a project that also runs next-themes shares the key `theme` with it — one choice for both. To keep them apart, give the plugin its own key (`theme.storageKey`) |
|
||||
| CSP | the inline script runs with the CSP nonce (`<ThemeScript nonce>`, `SiteProviders` passes it); no script hash to update |
|
||||
|
||||
## Site settings → Theme
|
||||
|
||||
| Field | Meaning |
|
||||
@@ -22,7 +34,7 @@ widget theme that matches the page.
|
||||
| `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).
|
||||
`getSiteShell(locale).theme` → `{ defaultTheme, allowToggle, toggleLabel, storageKey? }` (`themeConfigFrom(settings, storageKey?)` from the root entry; `storageKey` only when it is not the default).
|
||||
|
||||
## Wiring
|
||||
|
||||
@@ -60,10 +72,12 @@ import { ThemeSwitcher } from '@intecion/ipal-kit/client'
|
||||
from the attribute on `<html>` (`dark:`), not React state — nothing jumps after hydration.
|
||||
Hooks for styling: `data-ipal="theme-switch"`, `data-ipal-theme-icon="light|dark"`.
|
||||
|
||||
Custom switcher: `useTheme()` → `{ theme, setTheme, toggle }` (`theme` = `null` on the server);
|
||||
`applyTheme(theme, { persist, transitionMs })`, `readDocumentTheme()`, the constants `THEME_ATTRIBUTE`,
|
||||
`THEME_STORAGE_KEY`, `THEME_SWITCHING_ATTRIBUTE`, `isTheme` from `/client`. From the root entry also
|
||||
`isThemeSetting` and `themeScript({ allowToggle, defaultTheme })` (the script text only).
|
||||
Custom switcher: `useTheme({ storageKey? })` → `{ theme, setTheme, toggle }` (`theme` = `null` on the server);
|
||||
`applyTheme(theme, { persist, storageKey, transitionMs })`, `readDocumentTheme()`, `documentThemeStorageKey()`,
|
||||
`migrateThemeStorage(key)`, the constants `THEME_ATTRIBUTE`, `THEME_STORAGE_KEY`, `LEGACY_THEME_STORAGE_KEY`,
|
||||
`THEME_STORAGE_ATTRIBUTE`, `THEME_SWITCHING_ATTRIBUTE`, `isTheme` from `/client`. From the root entry also
|
||||
`isThemeSetting` and `themeScript({ allowToggle, defaultTheme, storageKey })` (the script text only), and the
|
||||
type `ThemeOptions` (`ipalKit({ theme })`).
|
||||
|
||||
## CSS (Tailwind 4)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user