Detailed cookie settings window (CookieBanner settings="detailed")

A third settings mode next to 'inline' and 'modal': a large dialog where every consent
category is a card with its on/off control, description and an expandable list of the
cookies it covers (name, provider, purpose, duration), taken from Cookie Settings → Cookies
— the same rows as <CookieTable>. The developer picks the mode with one prop; the
component default stays 'inline', so existing sites are unchanged.

Cookie Settings gets a localized detailLabels group (list labels, English fallback);
getConsentTexts passes texts.cookies and texts.details, sharing the row mapping with
getCookieTable. New classNames slots and data-ipal handles for the cards and lists.

Docs for devs and agents: consent.md (modes compared, which to pick — new projects default
to 'detailed' when the cookie list is filled), AGENT.md, PROGRAMISTA §2.8/§2.11/§6, skills
ipal-setup, ipal-site, ipal-upgrade, ipal-locale-add, ipal-consent-check. Postgres/SQLite
projects need migrate:create for the new fields.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-10-21 18:16:30 +02:00
co-authored by Claude Opus 5.5
parent 1413e96731
commit 6b4336f961
17 changed files with 278 additions and 54 deletions
+105 -20
View File
@@ -32,6 +32,8 @@ export type CookieBannerClassNames = {
categories?: string
/** Settings view: one category row/card. */
category?: string
/** Detailed window: the card around one category (row + cookie list). */
categoryCard?: string
categoryDescription?: string
categoryTitle?: string
/** Settings dialog (modal mode): the ✕ button. */
@@ -42,7 +44,19 @@ export type CookieBannerClassNames = {
control?: string
/** Settings view: the switch knob (controls="switch"). */
controlThumb?: string
/** Settings dialog box (modal mode). */
/** Detailed window: one cookie in a category's list. */
cookie?: string
/** Detailed window: list of cookies under a category. */
cookieList?: string
/** Detailed window: provider / purpose / duration grid of one cookie. */
cookieMeta?: string
/** Detailed window: cookie name. */
cookieName?: string
/** Detailed window: <details> wrapping a category's cookie list. */
cookies?: string
/** Detailed window: the <summary> that expands the cookie list. */
cookiesToggle?: string
/** Settings dialog box (modal mode; detailed mode uses a wider default). */
dialog?: string
/** Small label above the banner title (CookieSettings → eyebrow). */
eyebrow?: string
@@ -111,12 +125,19 @@ const defaults: Required<CookieBannerClassNames> = {
body: 'mx-auto max-w-4xl',
categories: 'flex flex-col gap-3',
category: 'flex items-start justify-between gap-4',
categoryCard: `flex flex-col gap-3 ${radius} border p-4 ${border}`,
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]',
cookie: `flex flex-col gap-1 border-t pt-2 first:border-t-0 first:pt-0 ${border}`,
cookieList: 'mt-3 flex flex-col gap-2',
cookieMeta: `grid grid-cols-[auto_1fr] gap-x-3 gap-y-0.5 text-xs ${mutedText}`,
cookieName: `font-mono text-xs font-semibold ${strongText}`,
cookies: 'group',
cookiesToggle: `inline-flex cursor-pointer select-none items-center gap-1 text-xs font-medium ${accent} hover:underline [&::-webkit-details-marker]:hidden`,
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}`,
@@ -137,6 +158,9 @@ const defaults: Required<CookieBannerClassNames> = {
}
/** Default switch track (controls="switch") — the checkbox default doesn't fit a <button>. */
/** Default dialog for settings="detailed" — wider and taller than the modal one. */
const DETAILED_DIALOG = `relative max-h-[90vh] w-full max-w-4xl overflow-y-auto ${radius} border p-6 shadow-2xl sm:p-8 ${surface} ${border}`
const SWITCH_TRACK =
'relative inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full bg-[var(--ipal-border,#d4d4d4)] transition-colors data-[checked=true]:bg-[var(--ipal-primary,#2563eb)] disabled:cursor-default disabled:opacity-60 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[var(--ipal-primary,#2563eb)]'
@@ -155,10 +179,14 @@ type CookieBannerProps = {
/** Banner buttons, in this order. Default ['settings', 'reject', 'accept']. */
order?: CookieBannerAction[]
/**
* Where category settings open: in the banner itself (default) or in a centred
* dialog over a dimmed page ('modal' — closes with ✕, Escape or a click outside).
* Where category settings open:
* - 'inline' (default) — in the banner itself;
* - 'modal' — a centred dialog over a dimmed page (closes with ✕, Escape or a click outside);
* - 'detailed' — like 'modal', but a large window: each category is a card with its
* on/off control, description and an expandable list of its cookies (name, provider,
* purpose, duration) from Cookie Settings → Cookies.
*/
settings?: 'inline' | 'modal'
settings?: 'detailed' | 'inline' | 'modal'
/** Buttons under the categories, in this order. Default ['back', 'save']. */
settingsActions?: CookieSettingsAction[]
}
@@ -180,7 +208,8 @@ export function CookieBanner({
const [showSettings, setShowSettings] = useState(false)
const [choices, setChoices] = useState<Record<ConsentCategory, boolean>>(state)
const closeRef = useRef<HTMLButtonElement>(null)
const modal = settings === 'modal'
const modal = settings !== 'inline'
const detailed = settings === 'detailed'
useEffect(() => {
setChoices(state)
@@ -273,11 +302,68 @@ export function CookieBanner({
)
}
const cookieList = (cat: ConsentCategory) => {
const rows = texts.cookies?.filter((row) => row.category === cat) ?? []
const labels = texts.details
if (!labels || rows.length === 0) {return null}
return (
<details className={cn('cookies')} data-ipal="cookies">
<summary className={cn('cookiesToggle')}>
<svg aria-hidden="true" className="transition-transform group-open:rotate-90" fill="none" height="14" stroke="currentColor" strokeLinecap="round" strokeWidth="2" viewBox="0 0 24 24" width="14">
<path d="m9 18 6-6-6-6" />
</svg>
{labels.cookies} ({rows.length})
</summary>
<ul className={cn('cookieList')}>
{rows.map((row) => (
<li className={cn('cookie')} key={row.name}>
<code className={cn('cookieName')}>{row.name}</code>
<dl className={cn('cookieMeta')}>
{row.provider && (
<>
<dt>{labels.provider}</dt>
<dd>{row.provider}</dd>
</>
)}
{row.purpose && (
<>
<dt>{labels.purpose}</dt>
<dd>{row.purpose}</dd>
</>
)}
{row.duration && (
<>
<dt>{labels.duration}</dt>
<dd>{row.duration}</dd>
</>
)}
</dl>
</li>
))}
</ul>
</details>
)
}
const categoryRow = (cat: ConsentCategory) => (
<>
<div>
<p className={cn('categoryTitle')} id={`ipal-consent-${cat}`}>
{texts.categories[cat].title}
</p>
<p className={cn('categoryDescription')} id={`ipal-consent-${cat}-desc`}>
{texts.categories[cat].description}
</p>
</div>
{control(cat)}
</>
)
const settingsView = (
<div className="flex flex-col gap-4">
<div className="flex items-start justify-between gap-4">
<h2 className={cn('settingsTitle')} id="ipal-consent-title">
{icon && !modal && <Cookie aria-hidden="true" className={cn('icon')} />}
{icon && (!modal || detailed) && <Cookie aria-hidden="true" className={cn('icon')} />}
{texts.settingsTitle}
</h2>
{modal && (
@@ -290,19 +376,18 @@ export function CookieBanner({
</div>
{texts.settingsDescription && <p className={cn('settingsDescription')}>{texts.settingsDescription}</p>}
<ul className={cn('categories')}>
{CONSENT_CATEGORIES.map((cat) => (
<li className={cn('category')} key={cat}>
<div>
<p className={cn('categoryTitle')} id={`ipal-consent-${cat}`}>
{texts.categories[cat].title}
</p>
<p className={cn('categoryDescription')} id={`ipal-consent-${cat}-desc`}>
{texts.categories[cat].description}
</p>
</div>
{control(cat)}
</li>
))}
{CONSENT_CATEGORIES.map((cat) =>
detailed ? (
<li className={cn('categoryCard')} data-ipal={`category-${cat}`} key={cat}>
<div className={cn('category')}>{categoryRow(cat)}</div>
{cookieList(cat)}
</li>
) : (
<li className={cn('category')} key={cat}>
{categoryRow(cat)}
</li>
),
)}
</ul>
<div className={cn('settingsActions')}>{settingsActions.map(button)}</div>
</div>
@@ -321,7 +406,7 @@ export function CookieBanner({
// klik w tło zamyka dialog; klawiatura: Escape (listener wyżej) i przycisk ✕
role="presentation"
>
<div aria-labelledby="ipal-consent-title" aria-modal="true" className={cn('dialog')} data-ipal="consent-dialog" role="dialog">
<div aria-labelledby="ipal-consent-title" aria-modal="true" className={classNames?.dialog ?? (detailed ? DETAILED_DIALOG : defaults.dialog)} data-ipal="consent-dialog" role="dialog">
{settingsView}
</div>
</div>
+24 -16
View File
@@ -1,7 +1,7 @@
import type { BasePayload } from 'payload'
import type { I18nConfig } from '../i18n/index.js'
import type { ConsentTexts } from './texts.js'
import type { ConsentTexts, CookieTableRow } from './texts.js'
import { resolveLocalized } from '../i18n/resolveLocalized.js'
import { getSystemPagePath } from '../pages/index.js'
@@ -28,6 +28,7 @@ const FALLBACK: ConsentTexts = {
title: 'Necessary',
},
},
details: { cookies: 'Cookies used', duration: 'Duration', provider: 'Provider', purpose: 'Purpose' },
message:
'We use cookies to run the site, analyze traffic, and improve your experience. You can accept all, reject non-essential, or choose which to allow.',
privacyLink: null,
@@ -49,6 +50,7 @@ type CookieSettingsData = {
} & Partial<Omit<ConsentTexts['buttons'], 'save'>>) | null
categories?: Array<{ description?: null | string; key: string; title?: null | string }> | null
cookies?: Array<{ category?: null | string; duration?: null | string; name?: null | string; provider?: null | string; purpose?: null | string }> | null
detailLabels?: null | Partial<Record<keyof NonNullable<ConsentTexts['details']>, null | string>>
eyebrow?: null | string
message?: null | string
policyVersion?: null | number
@@ -153,6 +155,13 @@ export async function getConsentTexts({
settings: g.buttons?.settings || FALLBACK.buttons.settings,
},
categories,
cookies: toCookieRows(g.cookies),
details: {
cookies: g.detailLabels?.cookies?.trim() || FALLBACK.details!.cookies,
duration: g.detailLabels?.duration?.trim() || FALLBACK.details!.duration,
provider: g.detailLabels?.provider?.trim() || FALLBACK.details!.provider,
purpose: g.detailLabels?.purpose?.trim() || FALLBACK.details!.purpose,
},
message: g.message || FALLBACK.message,
privacyLink,
settingsTitle: g.settingsTitle || FALLBACK.settingsTitle,
@@ -165,12 +174,19 @@ export async function getConsentTexts({
}
}
export type CookieTableRow = {
category: ConsentCategory
duration?: string
name: string
provider?: string
purpose?: string
export type { CookieTableRow } from './texts.js'
/** Named rows only; an unknown category falls back to necessary. */
function toCookieRows(cookies: CookieSettingsData['cookies']): CookieTableRow[] {
return (cookies ?? [])
.filter((c) => typeof c.name === 'string' && c.name.trim())
.map((c) => ({
name: c.name!.trim(),
category: (CONSENT_CATEGORIES as readonly string[]).includes(c.category ?? '') ? (c.category as ConsentCategory) : 'necessary',
...(c.provider?.trim() ? { provider: c.provider.trim() } : {}),
...(c.purpose?.trim() ? { purpose: c.purpose.trim() } : {}),
...(c.duration?.trim() ? { duration: c.duration.trim() } : {}),
}))
}
/**
@@ -180,15 +196,7 @@ export type CookieTableRow = {
export async function getCookieTable({ locale, payload }: { locale?: string; payload: BasePayload }): Promise<CookieTableRow[]> {
try {
const g = await getGlobal<CookieSettingsData>(payload, 'cookie-settings', { locale })
return (g.cookies ?? [])
.filter((c) => typeof c.name === 'string' && c.name.trim())
.map((c) => ({
name: c.name!.trim(),
category: (CONSENT_CATEGORIES as readonly string[]).includes(c.category ?? '') ? (c.category as ConsentCategory) : 'necessary',
...(c.provider?.trim() ? { provider: c.provider.trim() } : {}),
...(c.purpose?.trim() ? { purpose: c.purpose.trim() } : {}),
...(c.duration?.trim() ? { duration: c.duration.trim() } : {}),
}))
return toCookieRows(g.cookies)
} catch {
return []
}
+23
View File
@@ -13,6 +13,20 @@ export type ConsentTexts = {
settings: string
}
categories: Record<ConsentCategory, { description: string; title: string }>
/**
* Cookie Settings → Cookies in this language — listed per category in the
* detailed settings window (<CookieBanner settings="detailed">). Optional so
* hand-built texts keep compiling; getConsentTexts always fills it.
*/
cookies?: CookieTableRow[]
/** Labels of the cookie list in the detailed settings window. No labels = no list. */
details?: {
/** Expander per category, e.g. "Cookies used" — the count is appended. */
cookies: string
duration: string
provider: string
purpose: string
}
/** Small label above the banner title (e.g. "Privacy & cookies"). Empty = not shown. */
eyebrow?: string
message: string
@@ -26,3 +40,12 @@ export type ConsentTexts = {
/** Policy version from the panel — a stored consent from another version asks again. */
version?: number
}
/** One row of Cookie Settings → Cookies, resolved to a single language. */
export type CookieTableRow = {
category: ConsentCategory
duration?: string
name: string
provider?: string
purpose?: string
}