diff --git a/dev/app/(frontend)/[locale]/layout.tsx b/dev/app/(frontend)/[locale]/layout.tsx index 26537f5..3d608c7 100644 --- a/dev/app/(frontend)/[locale]/layout.tsx +++ b/dev/app/(frontend)/[locale]/layout.tsx @@ -15,6 +15,12 @@ export default async function LocaleLayout({ children, params }: Props) { } logEndpoint="/api/ipal/consent" shell={await getSiteShell(locale)} stats={{ locale }}>
{children}
+ {/* A footer with links in the bottom-left corner: CookieButton must not cover them. */} +
diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 8c639e8..c5ccd1a 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -48,6 +48,14 @@ fifteen ready page sections and ten page templates. - **Reference site for agents:** `docs/agent/reference-site/INDEX.md` (shipped) maps every plugin feature to a file in a complete example site built on ipal-kit, so an agent can copy a working pattern. The site itself lives in the plugin repo (`reference/`, not shipped) and is built, seeded and smoke-tested in the plugin's CI. +- **2FA screens in plain English and Polish:** `TOTP_TEXTS` (en, pl) go over `@clocklimited/payload-2fa`'s texts, and + the setup / verify screens get a tab title (`TOTP_VIEW_TITLE`, in the site's default language) instead of + "Payload". The project's own `i18n.translations..totpPlugin` still wins, a view's own `meta.title` stays, and + `twoFactor: { …, texts: false }` keeps the package's texts. The admin language still follows the browser. +- **`` stays clear of the footer:** when the footer scrolls into view the button moves up above it + (`avoid`, default `COOKIE_BUTTON_AVOID` = `footer, [role="contentinfo"]`; `avoid={false}` turns it off), `side` + (`'left'` default / `'right'`), position tokens `--ipal-cookie-button-inset`; `bottomOverlap` for your own widget. + Type `CookieButtonProps`. ### Fixed - **Sitemap, llms.txt, the site index (MCP `list_pages`), search (`searchContent`, the search route, MCP @@ -89,6 +97,8 @@ fifteen ready page sections and ten page templates. Existing sites move block by block when they get work (an own block with the same slug and fields can be replaced by the library block with `slug`, else a migration with **ipal-migrate-fields**). After turning blocks on: `pnpm generate:types`, `pnpm payload generate:importmap`, Postgres/SQLite `pnpm payload migrate:create`. +6. **CookieButton:** it now lifts above the site footer when the footer is in view. A site with its own fixed footer + bar or a button placed by `className`: check it; `avoid={false}` keeps the old fixed position. ## 1.14.6 diff --git a/docs/agent/skills/ipal-reference/SKILL.md b/docs/agent/skills/ipal-reference/SKILL.md index 15c5e0b..d55fd57 100644 --- a/docs/agent/skills/ipal-reference/SKILL.md +++ b/docs/agent/skills/ipal-reference/SKILL.md @@ -36,6 +36,7 @@ description: Complete map of everything @intecion/ipal-kit provides — every ip | `twoFactor.plugin` | — (required) | injected `payloadTotp` (the plugin does not import the peer) | missing function → throws | | `twoFactor.collectionSlug` | the panel's login collection (`admin.user`, else the first auth collection) | collection with 2FA; startup fails with `[ipal] twoFactor…` when it is not an auth collection or differs from `admin.user` | point it at the login collection | | `twoFactor.provider` | `'@intecion/ipal-kit/admin#TotpRedirectProvider'` | admin provider that sends users to `setup-totp` / `verify-totp` (path read in the browser); replaces the package's header-based one | own component path / `{ path, clientProps, serverProps }` (gets clientProps `forceSetup`); `false` keeps the package's (needs `x-pathname` on `/admin`, else `setup-totp?back=null` loops) | +| `twoFactor.texts` | ipal-kit's en/pl texts (`TOTP_TEXTS`) over the package's; 2FA screens titled "Two-step verification" / "Weryfikacja dwuetapowa" (site's language) | `false` = the package's texts; one text: `i18n.translations..totpPlugin.` (security.md) | | `twoFactor.allowCollectionMismatch` | `false` | allows `collectionSlug` ≠ `admin.user` (panel users of the other collection then skip 2FA) | `true` only when you protect a second auth collection on purpose | | `whiteLabel` | none | `admin.components.graphics.Logo/Icon` (`AdminLogo`/`AdminIcon`) from Site settings + vendor credit | omit / `false`; `true` = defaults | | `whiteLabel.settingsSlug` | `'site-settings'` | global it reads the logo/name from | — | diff --git a/docs/agent/skills/ipal-reference/resources/api.md b/docs/agent/skills/ipal-reference/resources/api.md index d9f646b..2671eff 100644 --- a/docs/agent/skills/ipal-reference/resources/api.md +++ b/docs/agent/skills/ipal-reference/resources/api.md @@ -144,7 +144,9 @@ Fifteen ready blocks and ten page templates. **Use a library block (or a variant |---|---|---| | `ConsentProvider` | `@intecion/ipal-kit/client` | Consent provider: `{ texts, cookieMap?, logEndpoint? }` — consent state, cookie, Consent Mode, deleting cookies after consent is withdrawn, optional POST of the decision to the log (`'/api/ipal/consent'`). Wrap the layout once; required by the banner, `Analytics`, `ConsentScript`. | | `CookieBanner` | `@intecion/ipal-kit/client` | Consent banner + category settings: `settings: 'inline' \| 'modal' \| 'detailed'`, `controls`, `equalChoice` (recommended `true`), `order`, `settingsActions`, `icon`, `classNames`; colours from `--ipal-*` CSS vars. Do not write your own banner. | -| `CookieButton` | `@intecion/ipal-kit/client` | Floating button that reopens the cookie settings (withdrawing consent); hidden while the banner is visible. Prop `className`. | +| `CookieButton` | `@intecion/ipal-kit/client` | Floating button that reopens the cookie settings (withdrawing consent); hidden while the banner is visible. Props `className`, `side` (`'left' \| 'right'`), `avoid` (selector it lifts above, default `COOKIE_BUTTON_AVOID` = footer; `false`). Tokens `--ipal-cookie-button-offset`, `--ipal-cookie-button-inset`. Type `CookieButtonProps`. | +| `COOKIE_BUTTON_AVOID`, `bottomOverlap(tops, viewportHeight)` | `@intecion/ipal-kit/client` | Default footer selector; pixels the footer covers at the bottom of the screen (how far the button moves up) | +| `TOTP_TEXTS`, `TOTP_VIEW_TITLE` | `@intecion/ipal-kit` | en/pl texts of the 2FA screens (`totpPlugin:*`, merged by `twoFactor`) and their tab title | | `ConsentScript` | `@intecion/ipal-kit/client` | Loads an external script (`src` or `code`) only after consent for `category` — for vendors without Consent Mode (chat, Plausible etc.). Inside `ConsentProvider`. | | `CookieTable` | `@intecion/ipal-kit/rsc` | Server Component: cookie table for the cookie policy page — `{ rows, labels?, locale?, categories?, caption?, classNames?, storageColumn?, storageTypes? }`; `rows` from `getCookieTable()`; a **Type** column when a row is local / session storage (`storageColumn: 'auto' \| boolean`). | | `useConsent(options?)` | `@intecion/ipal-kit/client` | Low-level consent state hook → `{ state, decided, consentId, acceptAll, rejectAll, savePreferences, reopen }`. Usually use `ConsentProvider` + `useConsentContext` (the provider calls it itself). | diff --git a/docs/consent.md b/docs/consent.md index db573ea..25daa6e 100644 --- a/docs/consent.md +++ b/docs/consent.md @@ -105,7 +105,12 @@ takes `locale` and optional `labels`; defaults: `COOKIE_TABLE_LABELS` (`@intecio | `controls` | `'checkbox'` | `'checkbox' \| 'switch'` | | `settingsActions` | `['back', 'save']` | buttons under the categories (`'accept' \| 'back' \| 'reject' \| 'save'`) | -`CookieButton` takes only `className` (replaces the default). +`CookieButton` props: `className` (replaces the default classes; position is then yours too), +`side` (`'left'` default or `'right'`), `avoid` (CSS selector, default `COOKIE_BUTTON_AVOID` = +`'footer, [role="contentinfo"]'`; `false` = never move). While the footer is on screen the button +moves up by its visible part (`bottomOverlap`), so it never covers footer links. Position tokens: +`--ipal-cookie-button-offset` (from the bottom, default `1rem`), `--ipal-cookie-button-inset` (from the +side, default `1rem`); z-index `--ipal-z-header`. Type `CookieButtonProps`. ## Overriding the look (Level 2) diff --git a/docs/dev/admin-ux.md b/docs/dev/admin-ux.md index 57003d3..f5bd3f0 100644 --- a/docs/dev/admin-ux.md +++ b/docs/dev/admin-ux.md @@ -80,6 +80,7 @@ Use these terms everywhere: labels, descriptions, docs, toasts. Never a synonym. | The whole website | site | `witryna` | website, page, domain | | A blog/news entry | post | `wpis` | article (unless the project calls it so) | | Electronic mail | e-mail | `e-mail` | email, mail | +| Code from an authenticator app at login | two-step verification (2FA in short labels) | `weryfikacja dwuetapowa` | TOTP, two-factor authentication | | Cookie consent | consent | `zgoda` | permission, opt-in | | Cookie consent banner | cookie banner | `baner cookies` | popup, consent bar, CookieBanner | | Form entry sent by a visitor | submission | `zgłoszenie` | entry, response, lead | diff --git a/docs/i18n.md b/docs/i18n.md index 3e41ca7..178c745 100644 --- a/docs/i18n.md +++ b/docs/i18n.md @@ -404,7 +404,10 @@ about the matcher — paste it inline. This is a Next limitation, not a plugin o ## Admin panel languages and texts The site's content languages (`i18n.locales`) and the **admin panel's** language are -separate. The panel's language is what each user picks in *Account → Language*. +separate. The panel's language is what each user picks in *Account → Language*; until they pick one, +Payload takes the browser's language (English or Polish), else `i18n.fallbackLanguage` (Payload's +default `en`). An English browser therefore gets an English panel — 2FA screens included — on a +Polish site; set `i18n.fallbackLanguage: 'pl'` in your config to change the last step. - **Default:** when the project's `buildConfig` has no `i18n.supportedLanguages`, ipal-kit sets English and Polish. A project that sets its own list keeps it, untouched: diff --git a/docs/security.md b/docs/security.md index 75e0121..8b4aa5b 100644 --- a/docs/security.md +++ b/docs/security.md @@ -402,6 +402,22 @@ pnpm generate:importmap `src/app/(payload)/admin/importMap.js` must list `@intecion/ipal-kit/admin#TotpRedirectProvider` and `@clocklimited/payload-2fa/rsc#TOTPSetup` / `#TOTPVerify` / `#TOTPField`. Commit the file. +### Texts of the 2FA screens (`twoFactor.texts`) + +The setup and verify screens and the user field read their texts through Payload's i18n +(`totpPlugin:*`), in the user's admin language (*Account → Language*; without a choice, the +browser's language — an English browser sees English screens on a Polish site). The package's own texts are long and informal, +so ipal-kit merges `TOTP_TEXTS` (English and Polish, per `docs/dev/admin-ux.md`) over them, e.g. +"Two-step verification" / "Weryfikacja dwuetapowa", "Enter the 6-digit code from the app:" / +"Wpisz 6-cyfrowy kod z aplikacji:". The browser tab reads "Weryfikacja dwuetapowa — | Panel" +(`TOTP_VIEW_TITLE` in the site's default language: Payload's view title is a plain string). + +- **Override one text:** `i18n.translations..totpPlugin.` in your config — your keys win + over both sets. +- **Keep the package's texts:** `twoFactor: { …, texts: false }`. +- **Not translatable:** a network failure while sending the code shows the package's hardcoded + "Something went wrong" toast (rare: the server's own errors are translated). + ### The redirect to the 2FA screens (`twoFactor.provider`) The package's own admin provider decides on the server where to send the user, from an `x-pathname` diff --git a/src/exports/client.ts b/src/exports/client.ts index e6f33e5..0b12af7 100644 --- a/src/exports/client.ts +++ b/src/exports/client.ts @@ -15,14 +15,16 @@ export { shouldLoadGoogle } from '../modules/analytics/shouldLoadGoogle.js' * client-only code. */ export { + bottomOverlap, ConsentProvider, ConsentScript, + COOKIE_BUTTON_AVOID, CookieBanner, CookieButton, useConsent, useConsentContext, } from '../modules/consent/client.js' -export type { CookieBannerAction, CookieBannerClassNames, CookieSettingsAction } from '../modules/consent/client.js' +export type { CookieBannerAction, CookieBannerClassNames, CookieButtonProps, CookieSettingsAction } from '../modules/consent/client.js' export { ConstructionNotice } from '../modules/construction/ConstructionNotice.js' export type { ConstructionNoticeClassNames } from '../modules/construction/ConstructionNotice.js' export { CONSTRUCTION_CLOSE_LABEL, CONSTRUCTION_CLOSE_LABEL_PL, constructionCloseLabel } from '../modules/construction/texts.js' diff --git a/src/index.ts b/src/index.ts index bd5bba2..2c1177e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -316,8 +316,9 @@ export type { TotpUser, WithSecurityConfigOptions, } from './modules/security/index.js' - export type { BuildSecurityHeadersArgs, SecurityHeader } from './modules/security/index.js' + +export { TOTP_TEXTS, TOTP_VIEW_TITLE } from './modules/security/totp/totpTexts.js' export type { OgImage } from './modules/seo/buildMetadata.js' export type { PageMetadata, SeoMeta, SeoOption } from './modules/seo/index.js' export { diff --git a/src/modules/consent/CookieButton.tsx b/src/modules/consent/CookieButton.tsx index 8d173cb..6762b35 100644 --- a/src/modules/consent/CookieButton.tsx +++ b/src/modules/consent/CookieButton.tsx @@ -1,22 +1,42 @@ 'use client' +import type { CSSProperties } from 'react' + import { Cookie } from 'lucide-react' +import { useEffect, useRef, useState } from 'react' import { useConsentContext } from './ConsentContext.js' import { useIsMounted } from './useIsMounted.js' +/** Elements the button moves up for, so it never covers footer links. */ +export const COOKIE_BUTTON_AVOID = 'footer, [role="contentinfo"]' + +export type CookieButtonProps = { + /** + * CSS selector of elements the button lifts above while they are on screen + * (default: the site footer). `false` = never move. + */ + avoid?: false | string + /** Replaces the default classes (look and position). The lift above `avoid` still applies. */ + className?: string + /** Corner. Default 'left'. */ + side?: 'left' | 'right' +} + /** * Floating "cookie settings" button — lets visitors reopen the consent panel * after deciding (GDPR: withdrawing consent must be as easy as giving it). * Hidden while the banner is showing. * * Colours follow the same design tokens as CookieBanner (--ipal-surface, - * --ipal-border, --ipal-hover, --ipal-text), so a client's palette applies to - * both without touching either component. Pass className to - * replace the styling outright. + * --ipal-border, --ipal-hover, --ipal-text). Position: --ipal-cookie-button-offset + * (distance from the bottom, default 1rem), --ipal-cookie-button-inset (from the + * side, default 1rem), z-index --ipal-z-header. When the footer scrolls into + * view the button moves up by the visible part of it, so footer links stay free. */ -export function CookieButton({ className }: { className?: string } = {}) { +export function CookieButton({ avoid = COOKIE_BUTTON_AVOID, className, side = 'left' }: CookieButtonProps = {}) { const isMounted = useIsMounted() const { decided, reopen, texts } = useConsentContext() + const lift = useLiftAbove(avoid, isMounted && decided) // Render nothing until mounted — prevents hydration mismatch (no project // ConsentWrapper workaround needed). @@ -25,9 +45,18 @@ export function CookieButton({ className }: { className?: string } = {}) { const cls = className ?? - 'fixed bottom-4 left-4 z-40 flex h-11 w-11 items-center justify-center rounded-full border shadow-md transition-colors ' + + 'flex h-11 w-11 items-center justify-center rounded-full border shadow-md transition-[background-color,transform] ' + 'bg-[var(--ipal-surface,light-dark(#fff,var(--ipal-surface-dark,#171717)))] border-[var(--ipal-border,light-dark(#e5e5e5,var(--ipal-border-dark,#262626)))] hover:bg-[var(--ipal-hover,light-dark(#f5f5f5,var(--ipal-hover-dark,#262626)))]' + const position: CSSProperties = className + ? {} + : { + bottom: 'calc(var(--ipal-cookie-button-offset, 1rem) + env(safe-area-inset-bottom, 0px))', + position: 'fixed', + [side]: 'var(--ipal-cookie-button-inset, 1rem)', + zIndex: 'var(--ipal-z-header, 40)' as unknown as number, + } + return (