- AGENT.md, skills, PROGRAMISTA, vibe, README and module pages checked against src/ and package.json; every mismatch fixed (consent/analytics loading, revalidation scope, generateStaticParams, construction gating, Turnstile fail modes, email/Graph, MCP, i18n, links, slug, hooks, ...) - New pages: frontend.md, media.md, integrations.md; docs/README.md now indexes every page - Main rule (plugin helps, never limits) at the top of AGENT.md, PROGRAMISTA.md, docs/README.md, README and the setup/plugin-gap skills; module pages gain a "Wyłączenie, nadpisanie, rozszerzenie" section - README/PROGRAMISTA: stop telling projects to install packages ipal-kit already depends on; peer table; publish flow matches prepublishOnly - ipal-skills: refuse --dest without a value or pointing at the project root (previously could delete ipal-* folders in cwd) - docsConsistency: option keys, IPAL_* env names, relative links, README index, AGENT.md section refs, skill frontmatter, frontend.md helper keys, no `pnpm add` of own dependencies Co-Authored-By: Claude Opus 5.5 <[email protected]>
98 lines
4.6 KiB
Markdown
98 lines
4.6 KiB
Markdown
# 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>`) ustawia `data-theme="light|dark"` i
|
|
`color-scheme` na `<html>` przed pierwszym malowaniem.
|
|
- Kolejność: wybór odwiedzającego z `localStorage` (klucz `ipal-theme`, tylko gdy „Allow theme toggle”)
|
|
→ Site Settings → Default theme → przy `System` ustawienie 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
|
|
|
|
```tsx
|
|
// 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.
|
|
|
|
```tsx
|
|
// 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)
|
|
|
|
```css
|
|
@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"`.
|
|
|
|
## Wyłączenie, nadpisanie, rozszerzenie
|
|
|
|
- **Wyłączenie:** bez `SiteProviders theme` / `<ThemeScript>` motyw nie jest ustawiany (bazowy CSS);
|
|
`allowThemeToggle` wyłączony = wybór odwiedzającego ignorowany. Zakładka *Theme* w Site Settings jest
|
|
obecnie zawsze dodawana.
|
|
- **Nadpisanie:** `ThemeScript` przyjmuje `allowToggle` / `defaultTheme` wprost (nie musi czytać z panelu);
|
|
`ThemeSwitcher` — `classNames`, `label`, `renderIcon`; `applyTheme(..., { persist, transitionMs })`.
|
|
- **Rozszerzenie:** własny przełącznik na `useTheme()`; `themeScript()` jako tekst skryptu do własnego
|
|
tagu; `themeConfigFrom(settings)` do odczytu ustawień.
|
|
Własne pola w Site Settings (np. dodatkowe tokeny) — `ipalKit({ siteSettingsFields })`, trafiają do
|
|
zakładki *Custom*.
|