feat: Shared lightbox that opens a figure larger (from the chart's Enlarge pattern)
Back to our planNumbering: epic #813; banner #814; lightbox #815; figure #816; Payload block #817; blue tone #818; content edit #819; guidelines #820. Where the text below says 01 to 07, read these numbers (01=#815, 02=#816, 03=#817, 04=#819, 05=#814, 06=#818, 07=#820).
Problem
In plain words: we already have a "small picture that opens larger" behavior, but only charts use it (ChartZoom, #681/#686). An image can't do this, so a big annotated map has to be shown at full size in the article. Copying ChartZoom for images would break guard rail 1 (build once).
Proposed fix
Pull the general part of src/platform/ui/chart/ChartZoom.client.tsx out into a shared Zoom (working name; ImageZoom if it stays image-only) in src/platform/ui/. Charts and images both use it, and ChartZoom becomes a thin caller or goes away. What it keeps from ChartZoom:
- It wraps the kit's
Dialog(src/platform/ui/Dialog.client.tsx), which already gives the focus trap, Escape, outside click, scroll lock and focus back to the trigger. - The Enlarge
Button(lucideMaximize2,aria-label"Enlarge: <title>") stays hidden without scripting (thescripted:variant insrc/platform/theme/tailwind.css). Without JavaScript the reader simply sees the small figure. - Clicking or tapping the picture is a pointer shortcut, with the same "a text selection doesn't count" guard. The button stays the keyboard and screen-reader path.
- The holder keeps its measured height while the dialog is open, so the page doesn't collapse behind it.
What it adds:
- Two slots instead of one: the small view (
children) and alargeslot with what the dialog shows. A chart moves its own server-rendered children into the dialog, as today. An image gives the dialog a large rendition of the sameMedia, plusasidecontent: theLegendand the long caption. - Dialog layout: on wide screens the image and the aside sit side by side (image about 2/3, key 1/3, at
lgand up). On narrow screens they stack, image first, key under it. The ratio and the widths are variables inglobals.cssread throughsrc/platform/ui/layoutSizes.ts(next toCHART_LARGE_WIDTH), never typed twice. - No key on the small view. The key is passed only to the
large/asideslot, so the page can't show it small.
Sheet or centered panel: [DECISION] keep the full-screen sheet. docs/ui/component-set-modules.md lists Dialog · center as "not needed yet". A full-screen sheet gives the map the most room on a phone, already has a close button in a top bar, and is what charts use. A centered panel would add a Dialog variant that only this one caller needs (a "split before it bloats" sign in docs/guidelines/components-and-content.md). If the owner later wants the page dimmed behind a centered box, that is one new Dialog variant, and this component doesn't change.
Native-first check:
- (1) Native: the HTML
<dialog>and Next/Image have no lightbox. Radix Dialog, which we already have, gives the modal behavior, so we use it through the kit'sDialog. - (2) Official plugins: Payload and Next.js have no front-end lightbox.
- (3) Open source:
yet-another-react-lightboxis the most used. It brings its own markup, styles and icons that the theme tokens and the UI kit don't control, and it has no slot for a legend beside the image. Our existingChartZoompattern already does what we need with Radix. - Conclusion: reuse and generalize our own pattern. No new package.
Acceptance criteria
- Not done: Tests come first: a failing component test for the shared zoom (opens from the button and from a click on the picture; not from a text selection; Escape closes; focus returns to the Enlarge button; the aside renders only in the dialog), then the code.
- Not done:
ChartZoomuses the shared component. The chart's existing tests and behavior are unchanged, checked in the gallery (/dev/gallery,ChartGallery.tsx) and on a post with a chart. - Not done: Without scripting there is no Enlarge button and no broken layout. The small figure shows as it is.
- Not done: An axe check passes on the closed and the open state (
expectAccessible). - Not done: The dialog has an accessible name (the figure's title), and its close button says "Close".
- Not done: In the dialog the key is readable: side by side from
lg, stacked under the image below it, with numbers at theLegend's normal size. - Not done: Width and ratio values come from
globals.cssthroughlayoutSizes.ts. No literal sizes or raw colors. - Not done: A gallery entry shows an image zoom with a legend, and
docs/ui/component-set.mdhas a row for the new component. TheChartZoomrow is updated to say it uses it. - Not done: The sheet-versus-centered decision is recorded on this issue as a
[DECISION]. - Not done: Checked at 320, 430, 768, 1024, 1280 and 1920 px in light and dark: the open dialog with image and key, and the closed state.
- Not done: Keyboard: Tab reaches Enlarge, Enter opens, Escape closes, and focus returns to Enlarge.
- Not done: Documentation follows behavior: the generated components reference is regenerated (
npm run docs:generate). Visitors see no change until 02 uses it, so the PR declares "Behavior change: none" with that reason, unless the chart's behavior changes.
Files likely touched
src/platform/ui/chart/ChartZoom.client.tsxand its test- new
src/platform/ui/Zoom.client.tsx(name to settle) andZoom.client.test.tsx src/platform/ui/layoutSizes.ts,src/app/(frontend)/globals.css(the dialog's width and ratio variables)src/app/(frontend)/dev/gallery/(an entry;DisplayGallery.tsxorChartGallery.tsx)docs/ui/component-set.md,docs/reference/components/(generated)
Must not touch
src/platform/ui/Dialog.client.tsx, unless a centered variant turns out to be needed. The decision above says it isn't.src/platform/ui/Alert.tsx,src/platform/theme/tokens.ts,src/themes/(06)- Payload configs and
src/migrations/(03)
Area
frontend, ux
Priority
priority: medium
Generated by Claude Code, opens in a new tab