Shared image lightbox: LightboxProvider, LightboxTrigger, LightboxDialog, lightboxImage

Opt-in click-to-enlarge for small images (cards, galleries, rich text):
- /client: LightboxProvider (one viewer per site), LightboxTrigger (button
  around any thumbnail, works without a provider), LightboxDialog
  (controlled viewer), useLightbox / useOptionalLightbox
- accessible dialog: aria-modal, focus trap and return, Esc, arrows,
  Home/End, swipe, counter, caption, scroll lock, reduced motion
- lightboxImage builds src + srcSet from Payload image sizes
- labels: ipalKit({ lightbox: true }) adds Notifications -> Lightbox;
  getNotificationTexts().lightbox and getSiteShell().lightboxTexts,
  English fallbacks otherwise
- RenderRichText lightbox / withLightboxUploads wrap image uploads
- SiteProviders lightbox mounts the provider
- styling from --ipal-lightbox-* variables; unstyled + classNames,
  renderImage, renderDialog, icons, loop overrides
- tests with happy-dom (vitest's pinned optional peer)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-10-27 14:49:38 +01:00
co-authored by Claude Opus 5.5
parent e53d09b720
commit 476c3ac1df
23 changed files with 1203 additions and 15 deletions
+41
View File
@@ -1,5 +1,7 @@
import type { Field } from 'payload'
import { LIGHTBOX_FALLBACK } from '../../modules/lightbox/texts.js'
/**
* Fields for the Notifications global — localized user-facing texts for action
* results (form submission outcomes, and future contexts). Every text is
@@ -96,3 +98,42 @@ export const notificationsFields: Field[] = [
label: 'Form messages',
},
]
const lightboxText = (name: keyof typeof LIGHTBOX_FALLBACK, width: string, description?: string): Field => ({
name,
type: 'text',
admin: { placeholder: LIGHTBOX_FALLBACK[name], width, ...(description ? { description } : {}) },
localized: true,
})
/**
* The "Lightbox" group — labels of the image viewer (<LightboxProvider texts>).
* Added by ipalKit `lightbox: true`; exported so a project can place it in its
* own global instead.
*/
export const lightboxNotificationFields: Field = {
name: 'lightbox',
type: 'group',
admin: {
description: 'Labels of the enlarged-image viewer, read by screen readers. Leave a field empty to use the built-in default.',
},
fields: [
{
type: 'row',
fields: [
lightboxText('open', '50%', 'Button around a small image; its alt text follows after ": ".'),
lightboxText('dialog', '50%', 'Name of the viewer window.'),
],
},
{
type: 'row',
fields: [
lightboxText('previous', '25%'),
lightboxText('next', '25%'),
lightboxText('close', '25%'),
lightboxText('counter', '25%', '{current} and {total} are replaced.'),
],
},
],
label: 'Lightbox',
}
+5 -4
View File
@@ -1,14 +1,15 @@
import type { GlobalConfig } from 'payload'
import { userMeetsRole } from '../../modules/access/index.js'
import { notificationsFields } from './fields.js'
import { lightboxNotificationFields, notificationsFields } from './fields.js'
/**
* Builds the Notifications global — localized action-result texts. Readable by
* any authenticated panel user; server-side helpers read it with overrideAccess
* so the frontend can resolve texts without a session.
* so the frontend can resolve texts without a session. `lightbox` adds the
* image-viewer labels (ipalKit `lightbox: true`).
*/
export function buildNotifications(): GlobalConfig {
export function buildNotifications({ lightbox = false }: { lightbox?: boolean } = {}): GlobalConfig {
return {
slug: 'notifications',
access: {
@@ -16,7 +17,7 @@ export function buildNotifications(): GlobalConfig {
update: ({ req }) => userMeetsRole(req, 'editor'),
},
admin: { group: 'Settings' },
fields: notificationsFields,
fields: lightbox ? [...notificationsFields, lightboxNotificationFields] : notificationsFields,
label: 'Notifications',
}
}