# Image lightbox One shared viewer for images that appear small — a card, a gallery grid, a product thumbnail, an image inside rich text. The visitor clicks the thumbnail and sees the large version; images in the same group browse with arrows, keys and swipe. Optional: nothing renders and nothing is added to the schema until you use it. - `` (`/client`) — one per layout; owns the viewer. - `` (`/client`) — a ` // box.openGroup('gallery-1', 2) · box.next() · box.previous() · box.close() · box.isOpen · box.index ``` A product page with a stage image: the stage can be the trigger, and the thumbnail strip keeps choosing the stage image — `box.open(productImages, activeIndex, e.currentTarget)`. ## Media sizes `lightboxImage(media, { size?, sizes?, srcSet?, alt?, caption? })`: | option | default | effect | |---|---|---| | `size` | original file | the Payload image size used as `src` (fallback when the browser ignores `srcSet`), e.g. `'hero'` | | `srcSet` | `true` | every generated size + the original as `url 768w, …`; `false` = `src` only | | `sizes` | `'100vw'` | `sizes` of the large image | | `alt` | the doc's `alt` | override | | `caption` | the doc's `caption` when it is a string | override; `false` = none | Returns `null` for a video, PDF or unpopulated id — render the thumbnail without a trigger. A collection without `imageSizes` still works: the original file is the large image. For a phone- friendly viewer add at least one large size (e.g. `hero` 1920 wide) to the Media collection. ## Styling Out of the box the viewer is styled inline from CSS variables — override them on `:root` or any parent: | variable | default | |---|---| | `--ipal-lightbox-backdrop` | `rgb(0 0 0 / 0.9)` | | `--ipal-lightbox-color` | `#fff` | | `--ipal-lightbox-padding` | `4rem 1rem` | | `--ipal-lightbox-z-index` | `1000` | | `--ipal-lightbox-image-max-height` | `calc(100dvh - 9rem)` | | `--ipal-lightbox-control-bg` | `rgb(255 255 255 / 0.14)` | | `--ipal-lightbox-control-color` | `inherit` | | `--ipal-lightbox-control-size` | `2.75rem` | | `--ipal-lightbox-control-radius` | `999px` | | `--ipal-lightbox-inset` | `1rem` | | `--ipal-lightbox-caption-color` | `inherit` | | `--ipal-lightbox-caption-size` | `0.95rem` | | `--ipal-lightbox-duration` | `var(--ipal-duration, 200ms)` (fade; none with reduced motion) | | `--ipal-lightbox-easing` | `var(--ipal-ease-out, ease)` | ```css :root { --ipal-lightbox-backdrop: rgb(15 23 42 / 0.95); --ipal-lightbox-control-bg: var(--color-brand); } ``` Full control: `unstyled` (on the provider — applies to triggers too — or on one trigger / dialog) drops every inline style; style with `classNames` (`dialog`, `figure`, `image`, `caption`, `counter`, `button`, `close`, `previous`, `next`) and the `data-ipal` hooks: `lightbox`, `lightbox-backdrop`, `lightbox-figure`, `lightbox-caption`, `lightbox-counter`, `lightbox-previous`, `lightbox-next`, `lightbox-close`, `lightbox-trigger` (+ `data-group`). Icons: `icons={{ close, previous, next }}`. ## Turn off, override, extend | Feature | Default | Turn off / override | |---|---|---| | Whole feature | off — nothing renders without a trigger | don't use the components | | Form messages → Image viewer labels | off | `iapl({ lightbox: true })`; `lightboxNotificationFields` for your own global; `globalOverrides.notifications` | | Texts | panel → `lightboxFallback(locale)` (`LIGHTBOX_FALLBACK_PL` on `pl`, else `LIGHTBOX_FALLBACK`) | `texts` on the provider / trigger / dialog; `resolveLightboxTexts` | | Provider in `SiteProviders` | off | `lightbox` prop; or your own `` in a client component | | Large image markup | `` | `renderImage={({ image, imgProps, index }) => }` (provider, client only) | | The whole viewer | `LightboxDialog` | `renderDialog={(props) => }` — same props, your markup | | Wrap-around | on | `loop={false}` | | Swipe threshold | 40 px | `swipeThreshold` on `LightboxDialog` | | Rich text | off | `RenderRichText lightbox`; `withLightboxUploads(converters, options)` | | Look | inline styles from `--ipal-lightbox-*` | CSS variables; `unstyled` + `classNames` + `data-ipal` | Building blocks: `lightboxImage`, `lightboxIndex` (wrap / clamp), `formatLightboxCounter`, `resolveLightboxTexts(texts, locale?)`, `LIGHTBOX_FALLBACK`, `LIGHTBOX_FALLBACK_PL`, `lightboxFallback`, `prefersReducedMotion`, `useOptionalLightbox` (null outside a provider), `useLightbox`, `LightboxDialog`. ## Replacing a hand-made modal (migration) Projects built before this feature open images in different ways: a `glightbox` wrapper, an inline `div role="dialog"` with `next/image fill`, a link to the raw file in a new tab, or nothing. Move them to the shared lightbox: 1. **Config:** `iapl({ lightbox: true })`, then `pnpm payload migrate:create` (Postgres) and commit the migration. Fill **Forms → Form messages → Image viewer** in every language — copy the labels from the old block fields (e.g. `closeLabel`, `prevLabel`, `nextLabel`) or seed them. 2. **Layout:** ``. 3. **Gallery block:** replace the clickable `
` / custom `