From 2bd9d6082227bfcf25a28f0d31173b84797b7d0e Mon Sep 17 00:00:00 2001 From: rasm-its Date: Sat, 17 Oct 2026 03:20:11 +0200 Subject: [PATCH] Cookie banner layout options; keep admin UI out of /client CookieBanner: order, settings="modal", controls="switch", settingsActions, icon and a class slot for every element. Cookie Settings gains eyebrow, title, settingsDescription, alwaysActiveLabel and buttons.close. MaskedField, TestEmailButton and IntegrationStatusBanner import @payloadcms/ui and moved from /client to /admin; with sideEffects in package.json the site bundle no longer ships ~235 KB gz of admin code. A test walks the /client import graph to keep it that way. Co-Authored-By: Claude Opus 5.5 --- docs/CHANGELOG.md | 20 + docs/consent.md | 48 ++- docs/email.md | 2 +- package.json | 3 + src/exports/admin.ts | 11 +- src/exports/client.ts | 5 +- src/globals/CookieSettings/fields.ts | 38 ++ src/globals/SiteIntegrations/fields/smtp.ts | 4 +- .../SiteIntegrations/fields/turnstile.ts | 2 +- src/modules/consent/CookieBanner.tsx | 353 ++++++++++++++---- src/modules/consent/client.ts | 2 +- src/modules/consent/getConsentTexts.ts | 11 + src/modules/consent/texts.ts | 10 + src/modules/integrations/status.ts | 2 +- test/exports.test.ts | 26 ++ test/integration.test.ts | 35 +- 16 files changed, 473 insertions(+), 99 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 8606292..14738a1 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -8,6 +8,26 @@ wersji naraz przejdź po kolei wszystkie sekcje „Wymaga zmian w projekcie” o wersji, którą masz. Nowe wydanie = nowa sekcja na górze; najstarsze usuwamy dopiero powyżej 20. +## 1.10.0 + +### Nowe +- **Baner cookies pod projekt** — `CookieBanner`: `order` (kolejność przycisków), `settings="modal"` (ustawienia + w oknie na środku: ✕, Escape, klik w tło), `controls="switch"` (przełączniki `role="switch"`), + `settingsActions` (np. Zapisz / Tylko niezbędne / Akceptuj), `icon={false}`; `classNames` ma slot dla każdego + elementu (tekst, każdy przycisk, modal, karta kategorii, przełącznik, znacznik). Cookie Settings: `eyebrow`, + `title`, `settingsDescription`, `alwaysActiveLabel`, `buttons.close`. Opis: consent.md → „Układ”. + +### Poprawki +- **`/client` nie wciąga panelu admina do strony.** `MaskedField`, `TestEmailButton`, `IntegrationStatusBanner` + (importują `@payloadcms/ui`) są teraz w `/admin`; `sideEffects` w package.json. Każda strona importująca + cokolwiek z `/client` (CookieBanner, LanguageSwitcher…) ładowała ~235 KB gz kodu panelu. Test pilnuje regresji. + +### Wymaga zmian w projekcie +- `pnpm payload generate:importmap` (ścieżki komponentów panelu: `/client#…` → `/admin#…`), `rm -rf .next`. +- Import `MaskedField` / `TestEmailButton` / `IntegrationStatusBanner` z `@intecion/ipal-kit/client` → + `@intecion/ipal-kit/admin`. +- Nowe pola Cookie Settings: Postgres/SQLite → `pnpm payload migrate:create`; MongoDB bez zmian. + ## 1.9.9 ### Nowe diff --git a/docs/consent.md b/docs/consent.md index 4618e14..b371c1b 100644 --- a/docs/consent.md +++ b/docs/consent.md @@ -168,15 +168,55 @@ zmienna po zmiennej. Na większe zmiany są `classNames`: ``` -Sloty: `root`, `primaryButton`, `secondaryButton`. Podany className zastępuje -domyślny (nie dokleja się). +Podany className zastępuje domyślny (nie dokleja się). Każdy element ma swój slot (1.10.0): + +| Slot | Element | +|---|---| +| `root`, `body`, `content` | pasek, wewnętrzna szerokość, rząd tekst + przyciski | +| `text`, `icon`, `eyebrow`, `title`, `message`, `link` | blok tekstu banera | +| `actions` | rząd przycisków banera | +| `primaryButton`, `secondaryButton` | dwa style przycisków (domyślne dla wszystkich) | +| `acceptButton`, `rejectButton`, `settingsButton`, `saveButton`, `backButton` | pojedyncze przyciski — puste → `primaryButton` / `secondaryButton` | +| `overlay`, `dialog`, `closeButton` | modal ustawień (`settings="modal"`) | +| `settingsTitle`, `settingsDescription`, `categories`, `category`, `categoryTitle`, `categoryDescription` | widok ustawień | +| `control`, `controlThumb`, `badge` | checkbox / przełącznik, kciuk przełącznika, znacznik „Zawsze aktywne” | +| `settingsActions` | rząd przycisków pod kategoriami | + +### Układ: kolejność przycisków, modal, przełączniki (1.10.0) + +```tsx + +``` + +Domyślnie (bez tych propsów) baner wygląda i działa jak przed 1.10.0. + +Teksty z panelu (**Cookie Settings**, per język) — puste pole = element się nie pokazuje: + +| Pole | Gdzie | +|---|---| +| `eyebrow` | mały napis nad tytułem banera („Prywatność i cookies”) | +| `title` | tytuł banera („Szanujemy Twoją prywatność”) | +| `settingsDescription` | opis pod tytułem ustawień | +| `alwaysActiveLabel` | znacznik przy „Niezbędne” zamiast wyłączonego przełącznika | +| `buttons.close` | etykieta przycisku ✕ dla czytników ekranu (puste → „Close”) | + +Nowe pola w globalu = migracja w projektach na Postgres/SQLite (`payload migrate:create`); MongoDB bez zmian. Elementy mają też stabilne uchwyty `data-ipal` do CSS i testów e2e (używa ich `ipal-consent-check`): `banner`, `cookie-button` oraz przyciski `settings`, `reject`, -`accept`, `back`, `save`. +`accept`, `back`, `save`; w trybie modal także `consent-overlay`, `consent-dialog`, `close`. Dostępność: dialog banera i `CookieButton` mają `aria-label` z **Cookie Settings → -settingsTitle** (per język) — bez tekstów na sztywno w komponentach. +title** albo **settingsTitle** (per język) — bez tekstów na sztywno w komponentach. Modal ma +`aria-modal`, fokus na ✕ po otwarciu i zamyka się Escape; przełączniki mają `role="switch"` i `aria-checked`. ## Locale jako cookie functional (wbudowane) diff --git a/docs/email.md b/docs/email.md index bec799e..53919d9 100644 --- a/docs/email.md +++ b/docs/email.md @@ -88,7 +88,7 @@ przyciskiem Reveal/Hide. To maskowanie UI, NIE hashowanie ani szyfrowanie: wartość w bazie jest plaintext (musi być odzyskiwalna do autentykacji SMTP/R2). Chroni przed patrzeniem przez ramię i przypadkowym pokazaniem panelu. -Podpięte przez `admin.components.Field: '@intecion/ipal-kit/client#MaskedField'`. +Podpięte przez `admin.components.Field: '@intecion/ipal-kit/admin#MaskedField'`. Działa na dowolnym polu `text`. Po wpięciu w projekcie może być konieczne `payload generate:importmap`, żeby panel rozpoznał komponent. diff --git a/package.json b/package.json index 50beeb0..88b40c8 100644 --- a/package.json +++ b/package.json @@ -57,6 +57,9 @@ "docs", "bin" ], + "sideEffects": [ + "**/*.css" + ], "scripts": { "build": "pnpm copyfiles && pnpm build:types && pnpm build:swc", "build:swc": "swc ./src -d ./dist --config-file .swcrc --strip-leading-paths", diff --git a/src/exports/admin.ts b/src/exports/admin.ts index c04efe3..56604ac 100644 --- a/src/exports/admin.ts +++ b/src/exports/admin.ts @@ -1,10 +1,13 @@ -export { RowLabel } from '../modules/admin-ui/RowLabelComponent.js' /** * Entry point: @intecion/ipal-kit/admin * - * Admin-panel UI components (white-label branding, array row labels). Separate export so Payload's - * importMap can resolve them by a stable path when ipalKit injects - * admin.components.graphics.Logo/Icon. + * Admin-panel UI components (white-label branding, array row labels, integration fields and + * banners). Separate export so Payload's importMap can resolve them by a stable path, and so + * nothing importing @payloadcms/ui ends up in /client — that entry ships to every site visitor. */ +export { MaskedField } from '../globals/SiteIntegrations/components/MaskedField.js' +export { TestEmailButton } from '../globals/SiteIntegrations/components/TestEmailButton.js' +export { RowLabel } from '../modules/admin-ui/RowLabelComponent.js' export { AdminIcon, AdminLogo, IntecionCredit } from '../modules/branding/index.js' export { IntegrationAlerts } from '../modules/integrations/IntegrationAlerts.js' +export { IntegrationStatusBanner } from '../modules/integrations/IntegrationStatusBanner.js' diff --git a/src/exports/client.ts b/src/exports/client.ts index 3947f42..c6263fd 100644 --- a/src/exports/client.ts +++ b/src/exports/client.ts @@ -1,6 +1,4 @@ 'use client' -export { MaskedField } from '../globals/SiteIntegrations/components/MaskedField.js' -export { TestEmailButton } from '../globals/SiteIntegrations/components/TestEmailButton.js' export { AccessibilityProvider, AccessibilityWidget, useAccessibility } from '../modules/accessibility/client.js' export type { A11yClassNames, A11yState, A11yTexts } from '../modules/accessibility/client.js' export { Analytics } from '../modules/analytics/client.js' @@ -23,7 +21,7 @@ export { useConsent, useConsentContext, } from '../modules/consent/client.js' -export type { CookieBannerClassNames } from '../modules/consent/client.js' +export type { CookieBannerAction, CookieBannerClassNames, CookieSettingsAction } from '../modules/consent/client.js' export { ConstructionNotice } from '../modules/construction/ConstructionNotice.js' export type { ConstructionNoticeClassNames } from '../modules/construction/ConstructionNotice.js' export type { ConstructionMode } from '../modules/construction/types.js' @@ -77,7 +75,6 @@ export { useSetAlternateLinks, } from '../modules/i18n/index.js' export type { AlternateLinks, LanguageSwitcherClassNames } from '../modules/i18n/index.js' -export { IntegrationStatusBanner } from '../modules/integrations/IntegrationStatusBanner.js' export { LocaleView } from '../modules/pages/LocaleView.js' export { YouTubeEmbed } from '../modules/storage/YouTubeEmbed.js' export { Turnstile } from '../modules/turnstile/client.js' diff --git a/src/globals/CookieSettings/fields.ts b/src/globals/CookieSettings/fields.ts index 8c39e70..2c28aa2 100644 --- a/src/globals/CookieSettings/fields.ts +++ b/src/globals/CookieSettings/fields.ts @@ -22,6 +22,22 @@ export const cookieSettingsFields: Field[] = [ min: 1, required: true, }, + { + name: 'eyebrow', + type: 'text', + admin: { + description: 'Small label above the banner title, e.g. "Privacy & cookies". Empty → not shown.', + }, + localized: true, + }, + { + name: 'title', + type: 'text', + admin: { + description: 'Banner heading, e.g. "We respect your privacy". Empty → not shown.', + }, + localized: true, + }, { name: 'message', type: 'textarea', @@ -38,6 +54,22 @@ export const cookieSettingsFields: Field[] = [ }, localized: true, }, + { + name: 'settingsDescription', + type: 'textarea', + admin: { + description: 'Intro under the settings heading — what cookies are for and that the choice can be changed later.', + }, + localized: true, + }, + { + name: 'alwaysActiveLabel', + type: 'text', + admin: { + description: 'Badge next to the Necessary category, e.g. "Always active". Empty → a disabled switch/checkbox is shown instead.', + }, + localized: true, + }, { name: 'privacyLinkLabel', type: 'text', @@ -59,6 +91,12 @@ export const cookieSettingsFields: Field[] = [ { name: 'settings', type: 'text', localized: true }, { name: 'save', type: 'text', localized: true }, { name: 'back', type: 'text', localized: true }, + { + name: 'close', + type: 'text', + admin: { description: 'Screen-reader label of the ✕ button in the settings dialog.' }, + localized: true, + }, ], }, { diff --git a/src/globals/SiteIntegrations/fields/smtp.ts b/src/globals/SiteIntegrations/fields/smtp.ts index e12b9cc..dc4b1e1 100644 --- a/src/globals/SiteIntegrations/fields/smtp.ts +++ b/src/globals/SiteIntegrations/fields/smtp.ts @@ -64,7 +64,7 @@ export const smtpFields: Field[] = [ description: 'SMTP account password.', // Masked in the UI (••••) — stored plaintext, readable for SMTP auth. components: { - Field: '@intecion/ipal-kit/client#MaskedField', + Field: '@intecion/ipal-kit/admin#MaskedField', }, }, }, @@ -87,7 +87,7 @@ export const smtpFields: Field[] = [ type: 'ui', admin: { components: { - Field: '@intecion/ipal-kit/client#TestEmailButton', + Field: '@intecion/ipal-kit/admin#TestEmailButton', }, }, }, diff --git a/src/globals/SiteIntegrations/fields/turnstile.ts b/src/globals/SiteIntegrations/fields/turnstile.ts index 0fd084f..a753213 100644 --- a/src/globals/SiteIntegrations/fields/turnstile.ts +++ b/src/globals/SiteIntegrations/fields/turnstile.ts @@ -27,7 +27,7 @@ export const turnstileFields: Field[] = [ description: 'Secret key used for server-side verification.', // Masked in the UI (••••) — stored plaintext, readable for verification. components: { - Field: '@intecion/ipal-kit/client#MaskedField', + Field: '@intecion/ipal-kit/admin#MaskedField', }, }, }, diff --git a/src/modules/consent/CookieBanner.tsx b/src/modules/consent/CookieBanner.tsx index efec62f..7822b9f 100644 --- a/src/modules/consent/CookieBanner.tsx +++ b/src/modules/consent/CookieBanner.tsx @@ -1,19 +1,76 @@ 'use client' import { Cookie } from 'lucide-react' -import { useEffect, useState } from 'react' +import { useEffect, useRef, useState } from 'react' import { CONSENT_CATEGORIES, type ConsentCategory } from './categories.js' import { useConsentContext } from './ConsentContext.js' import { useIsMounted } from './useIsMounted.js' +/** A button on the banner (first level). */ +export type CookieBannerAction = 'accept' | 'reject' | 'settings' +/** A button under the category list (settings view). */ +export type CookieSettingsAction = 'accept' | 'back' | 'reject' | 'save' + /** * Optional class overrides — for when tokens aren't enough, e.g. turning the - * bottom bar into a centred modal. Replaces the slot's classes outright. + * bottom bar into a centred modal. Each slot replaces its default classes + * outright. Per-button slots (acceptButton, rejectButton…) fall back to + * primaryButton / secondaryButton, so styling those two still restyles all. */ export type CookieBannerClassNames = { + /** Button "Accept all" — falls back to primaryButton. */ + acceptButton?: string + /** Button row on the banner. */ + actions?: string + /** Settings view: button "Back" (closes the dialog in modal mode) — falls back to secondaryButton. */ + backButton?: string + /** Settings view: badge next to Necessary (CookieSettings → alwaysActiveLabel). */ + badge?: string + /** Banner inner wrapper (width / centring). */ + body?: string + /** Settings view: list of categories. */ + categories?: string + /** Settings view: one category row/card. */ + category?: string + categoryDescription?: string + categoryTitle?: string + /** Settings dialog (modal mode): the ✕ button. */ + closeButton?: string + /** Banner: text + buttons row. */ + content?: string + /** Settings view: the switch track or the checkbox. */ + control?: string + /** Settings view: the switch knob (controls="switch"). */ + controlThumb?: string + /** Settings dialog box (modal mode). */ + dialog?: string + /** Small label above the banner title (CookieSettings → eyebrow). */ + eyebrow?: string + /** Cookie icon next to the banner text and the settings title. */ + icon?: string + /** Privacy-policy link inside the message. */ + link?: string + message?: string + /** Backdrop behind the settings dialog (modal mode). */ + overlay?: string primaryButton?: string + /** Button "Reject" — falls back to primaryButton with equalChoice, else secondaryButton. */ + rejectButton?: string root?: string + /** Settings view: button "Save preferences" — falls back to primaryButton. */ + saveButton?: string secondaryButton?: string + /** Settings view: button row under the categories. */ + settingsActions?: string + /** Button "Settings" on the banner — falls back to secondaryButton. */ + settingsButton?: string + /** Settings view: intro under the title (CookieSettings → settingsDescription). */ + settingsDescription?: string + settingsTitle?: string + /** Banner: block with eyebrow, title and message. */ + text?: string + /** Banner heading (CookieSettings → title). */ + title?: string } /** @@ -35,131 +92,267 @@ export type CookieBannerClassNames = { * * Layout stays in Tailwind: spacing and flow aren't things a brand changes, and * exposing them as tokens would mean re-inventing CSS one variable at a time. + * For a different layout use classNames (every element has a slot). */ const surface = 'bg-[var(--ipal-surface,#fff)] dark:bg-[var(--ipal-surface-dark,#171717)]' const border = 'border-[var(--ipal-border,#e5e5e5)] dark:border-[var(--ipal-border-dark,#262626)]' const radius = 'rounded-[var(--ipal-radius,0.375rem)]' const accent = 'text-[var(--ipal-primary,#2563eb)]' +const bodyText = 'text-[var(--ipal-text,#404040)] dark:text-[var(--ipal-text-dark,#d4d4d4)]' +const strongText = 'text-[var(--ipal-text-strong,#171717)] dark:text-[var(--ipal-text-strong-dark,#f5f5f5)]' +const mutedText = 'text-[var(--ipal-text-muted,#737373)] dark:text-[var(--ipal-text-muted-dark,#a3a3a3)]' +const primaryBg = 'bg-[var(--ipal-primary,#2563eb)]' -const defaults = { - primaryButton: `${radius} px-3 py-1.5 text-sm font-medium bg-[var(--ipal-primary,#2563eb)] text-[var(--ipal-primary-text,#fff)] hover:bg-[var(--ipal-primary-hover,#1d4ed8)]`, +const defaults: Required = { + acceptButton: '', + actions: 'flex shrink-0 gap-2', + backButton: '', + badge: `shrink-0 rounded-full border px-2 py-0.5 text-xs font-medium ${border} ${accent}`, + body: 'mx-auto max-w-4xl', + categories: 'flex flex-col gap-3', + category: 'flex items-start justify-between gap-4', + categoryDescription: `text-xs ${mutedText}`, + categoryTitle: `text-sm font-medium ${strongText}`, + closeButton: `shrink-0 ${radius} p-1 ${mutedText} hover:bg-[var(--ipal-hover,#f5f5f5)] dark:hover:bg-[var(--ipal-hover-dark,#262626)]`, + content: 'flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between', + control: 'mt-1 h-4 w-4 shrink-0 accent-[var(--ipal-primary,#2563eb)]', + controlThumb: 'pointer-events-none inline-block size-5 rounded-full bg-white shadow transition-transform translate-x-0.5 data-[checked=true]:translate-x-[1.375rem]', + dialog: `relative max-h-[90vh] w-full max-w-2xl overflow-y-auto ${radius} border p-6 shadow-2xl ${surface} ${border}`, + eyebrow: `mb-1 text-xs font-semibold uppercase tracking-wider ${accent}`, + icon: `h-6 w-6 shrink-0 ${accent}`, + link: `${accent} underline hover:no-underline`, + message: `text-justify text-sm ${bodyText}`, + overlay: 'fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4', + primaryButton: `${radius} px-3 py-1.5 text-sm font-medium ${primaryBg} text-[var(--ipal-primary-text,#fff)] hover:bg-[var(--ipal-primary-hover,#1d4ed8)]`, + rejectButton: '', root: `fixed inset-x-0 bottom-0 z-50 border-t p-4 shadow-lg ${surface} ${border}`, + saveButton: '', secondaryButton: `${radius} px-3 py-1.5 text-sm font-medium text-[var(--ipal-text,#404040)] hover:bg-[var(--ipal-hover,#f5f5f5)] dark:text-[var(--ipal-text-dark,#e5e5e5)] dark:hover:bg-[var(--ipal-hover-dark,#262626)]`, + settingsActions: 'flex justify-end gap-2', + settingsButton: '', + settingsDescription: `text-sm ${bodyText}`, + settingsTitle: `flex items-center gap-2 text-base font-semibold ${strongText}`, + text: 'flex items-start gap-3', + title: `mb-1 text-base font-semibold ${strongText}`, } -const bodyText = 'text-[var(--ipal-text,#404040)] dark:text-[var(--ipal-text-dark,#d4d4d4)]' -const strongText = - 'text-[var(--ipal-text-strong,#171717)] dark:text-[var(--ipal-text-strong-dark,#f5f5f5)]' -const mutedText = - 'text-[var(--ipal-text-muted,#737373)] dark:text-[var(--ipal-text-muted-dark,#a3a3a3)]' +/** Default switch track (controls="switch") — the checkbox default doesn't fit a + ) + const toggle = (cat: ConsentCategory) => { if (cat === 'necessary') {return} setChoices((prev) => ({ ...prev, [cat]: !prev[cat] })) } - const rootClass = classNames?.root ?? defaults.root - const primaryClass = classNames?.primaryButton ?? defaults.primaryButton - const secondaryClass = classNames?.secondaryButton ?? defaults.secondaryButton + const control = (cat: ConsentCategory) => { + const checked = cat === 'necessary' ? true : choices[cat] + if (cat === 'necessary' && texts.alwaysActiveLabel) { + return {texts.alwaysActiveLabel} + } + if (controls === 'switch') { + return ( + + ) + } + return ( + toggle(cat)} + type="checkbox" + /> + ) + } - return ( -
-
- {!showSettings ? ( -
-
-