- buildRevalidateHook skips outside Next (no NEXT_RUNTIME) and with context.disableRevalidate - BuilderForm focuses only on a real step change (no scroll to the form on remount) - mediaImageProps: placeholder colour only for JPEG (placeholderColor); hook stores no colour for transparent images - buildLinkField: interface name per shape (CmsLink, CmsLinkPlain, CmsLinkNoLabel) + interfaceName option - Cookie Settings: buttons.save -> buttons.savePreferences (Mongoose reserved name) - ThemeScript, ThemeSwitcher, useTheme; Site Settings defaultTheme 'system' + themeToggleLabel; Turnstile follows page theme - extractHeadings, RenderRichText headingIds, TableOfContents, buildTableOfContentsField - createPageRoute onMissing: 'redirectHome' - Form builder: localized placeholder on text/email/textarea/number, new time field - ipal-audit: no false positive for object keys between JSX elements; /md route not reported as dynamic Co-Authored-By: Claude Opus 5.5 <[email protected]>
3.8 KiB
Motyw jasny / ciemny (1.11.1)
Logika motywu z pluginu, wygląd w projekcie. Plugin daje: skrypt przed malowaniem (bez mignięcia
jasnego motywu), przełącznik bez stylów, hook useTheme, pola w Site Settings → Theme i motyw
widżetu Turnstile zgodny ze stroną.
Jak to działa
- Strony są ISR/SSG — jeden HTML dla wszystkich, więc motyw nie trafia do HTML z serwera.
<ThemeScript>(skrypt inline, pierwsze dziecko<body>) ustawiadata-theme="light|dark"icolor-schemena<html>przed pierwszym malowaniem.- Kolejność: wybór odwiedzającego z
localStorage(kluczipal-theme, tylko gdy „Allow theme toggle”) → Site Settings → Default theme → przySystemustawienie urządzenia (prefers-color-scheme). localStorage, nie cookie: to preferencja interfejsu, nie śledzi i nie wymaga zgody.- Zmiana w jednej karcie przechodzi do pozostałych (zdarzenie
storage).
Site Settings → Theme
| Pole | Znaczenie |
|---|---|
defaultTheme |
light · dark · system (od 1.11.1) |
allowThemeToggle |
pokazuj przełącznik; wybór odwiedzającego jest pamiętany |
themeToggleLabel |
nazwa przełącznika dla czytników ekranu, np. „Tryb ciemny” (localized, od 1.11.1) |
getSiteShell(locale).theme → { defaultTheme, allowToggle, toggleLabel } (themeConfigFrom(settings) z roota).
Podpięcie
// src/app/(frontend)/[locale]/layout.tsx
const shell = await getSiteShell(locale)
return (
<html lang={locale} suppressHydrationWarning>
<body>
<SiteProviders shell={shell} theme> {/* theme → <ThemeScript> na początku */}
<Header themeLabel={shell.theme.allowToggle ? shell.theme.toggleLabel : null} … />
…
Bez SiteProviders: import { ThemeScript } from '@intecion/ipal-kit/rsc' i <ThemeScript {...shell.theme} />
jako pierwsze dziecko <body>. suppressHydrationWarning na <html> jest potrzebne — atrybut różni się
od HTML z serwera celowo.
// przełącznik ('use client' albo w RSC — sam jest komponentem klienckim)
import { ThemeSwitcher } from '@intecion/ipal-kit/client'
<ThemeSwitcher
label={themeLabel}
classNames={{
root: 'inline-flex rounded-full border p-0.5',
light: 'rounded-full p-2 bg-white dark:bg-transparent',
dark: 'rounded-full p-2 dark:bg-surface-raised',
}}
// renderIcon={(t) => (t === 'light' ? <SunIcon /> : <MoonIcon />)} // domyślnie lucide Sun / Moon
/>
<button role="switch" aria-checked> (zaznaczony = ciemny). Który przycisk wygląda na aktywny, ustala CSS
z atrybutu na <html> (dark:), nie stan Reacta — po hydratacji nic nie przeskakuje.
Haki: data-ipal="theme-switch", data-ipal-theme-icon="light|dark".
Własny przełącznik: useTheme() → { theme, setTheme, toggle } (theme = null na serwerze);
applyTheme(theme, { persist, transitionMs }), readDocumentTheme(), stałe THEME_ATTRIBUTE,
THEME_STORAGE_KEY, THEME_SWITCHING_ATTRIBUTE, isTheme z /client. Z roota także
isThemeSetting i themeScript({ allowToggle, defaultTheme }) (sam tekst skryptu).
CSS (Tailwind 4)
@custom-variant dark (&:where([data-theme=dark], [data-theme=dark] *));
/* płynne przejście kolorów tylko w chwili przełączenia (applyTheme: data-theme-switching, 300 ms) */
[data-theme-switching] *, [data-theme-switching] *::before, [data-theme-switching] *::after {
transition: background-color 0.3s, border-color 0.3s, color 0.3s, fill 0.3s !important;
}
Tokeny ciemnego motywu (surface, fg…) zostają w styles.css projektu.
Turnstile
BuilderForm / RenderForm → turnstileTheme domyślnie 'page': widżet bierze motyw strony
(data-theme); bez motywu strony — 'auto' (motyw urządzenia), jak przed 1.11.1. Zmiana motywu
rysuje widżet od nowa (token trzeba zdobyć ponownie). Stały motyw: turnstileTheme="light".