Skip to content
SprecherEast
Issue 816

feat: Shared floated figure with a figure badge, short caption and the key only in the lightbox

Back to our plan
Done
enhancementfrontendstylinguxpriority: medium

Numbering: 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: an annotated image in an article is always as wide as the text column, with its numbered key hanging under it as a separate block (MediaBlock followed by DiagramKey, joined by LEGEND_GAP, #636/#658). A tall map then fills more than a screen. We have no shared way to show a picture small beside the text, label it "Figure 2-9", and keep the key and the long caption for when the reader asks for them.

Proposed fix

A new shared presentational component, Figure (working name), in src/platform/ui/. It takes plain props (decision 0013), so MediaBlock and the block in 03 only pass editor data in:

  • image (an ImageRef for Media), alt
  • label (optional): the figure label, drawn as Badge variant="neutral" (src/platform/ui/Badge.tsx: border border-border bg-muted text-muted-foreground, a pill). It shows above or at the start of the caption and again in the lightbox.
  • caption: short, drawn with Caption as="figcaption" size="sm" (src/platform/ui/Caption.tsx)
  • details (optional): the long caption, credit and conditions, shown only in the lightbox (Caption with finePrint there)
  • legendItems (optional): the numbered key, drawn with Legend marker="number" attach="none" columns="one" (src/platform/ui/Legend.tsx), only in the lightbox
  • align: right (default) | left | none (full column, as today)
  • size: the share of the text column the floated figure takes from md up. One named value per allowed width, each a variable in globals.css read through layoutSizes.ts. See the [PUSHBACK] and [QUESTION] below for the default.

Layout:

  • From md up, align="right" floats the figure right (float-right, with FIGURE_GAP spacing and a left margin token), so the following paragraphs wrap on its left. Headings and wide blocks clear the float (clear-both), so a heading never squeezes beside it.
  • Below md it stacks: full width, with the text above and below. This matches ui-ux-design.md's "stack before it wraps badly" rule.
  • The small view never shows the key. The figure opens in the lightbox from 01 with large = the same image, larger, and aside = badge, Legend, long caption.
  • Image frame as in MediaBlock today (border border-border rounded-[0.8rem]). Move that class string to one shared constant if a second place needs it (guard rail 1).
  • The figure keeps its link-preview and card behavior untouched: it is body content and doesn't change heroImage or meta.image. 03 covers the card rule.

#654 decision (comment draft to post on #654):

[DECISION] An image and its legend become one presentational component

Settled under epic 00 by sub-issue 02. A small shared Figure in src/platform/ui/ holds the image, the caption, the figure badge and, for annotated images, the legend. The legend shows only in the lightbox, where the numbers can be read (owner's request, 2026-11-07, Claude in Chrome side panel, summarized on epic 00). MediaBlock and the new figure block only map editor data into its props. Nothing joins two blocks with a negative margin any more, for new content. The existing mediaBlock + diagramKey pair keeps rendering as it does, so no stored post breaks. Moving it is a content edit (04), and retiring LEGEND_GAP waits until no live content uses the pair. Legend stays its own component, because charts use it without an image. The gallery spacing item from this issue is fixed in the same PR (the Legend sample gets block flow). One PR closes one issue, so 02's PR says Closes for 02 only and links #654. #654 is closed by hand with a link to that PR once it merges.

[PUSHBACK] How wide the floated figure is

The owner asked for about half the text column. docs/guidelines/ui-ux-design.md says a two-element layout is text 60–65% and picture 35–40%, and #796 set the About map block to that range (text 5/8, picture 3/8). Half is outside the guideline. The key now lives only in the lightbox, so the small picture doesn't need to be large enough to read numbers. Its only job is to show what the figure is and invite a click. We recommend 2/5 of the text column (40%), which is inside the guideline. size is a prop, so half is one value away (size="half"), and no rebuild is needed if he prefers it. Changing the guideline itself is a policy change (docs/guidelines/ is a process path, AGENTS.md step 3). Because the owner asked for this layout, it follows the normal path with a summary of his answer recorded (07).

[QUESTION] Default width of a floated figure

Question: Should a floated figure take 2/5 (40%) of the text column by default, or half?

  • 2/5 (recommended): inside the current design guideline and the same balance as the map block (#796). The key is in the lightbox, so the small picture only needs to be recognizable.
  • Half: what was first asked for. It means changing the 35–40% rule in ui-ux-design.md for figures (a policy change, recorded in 07).

Recommendation: 2/5, with half available per figure. Next: we build with 2/5 as the default and half as a value. His answer only sets the default and the guideline text in 07.

(Not labeled needs owner: the build doesn't wait for this answer, only the default value and 07's wording do.)

Native-first check:

  • (1) Native: CSS float with shape-outside is the standard way to wrap text around an element, and Tailwind has float-right and clear-both, so we use those. HTML figure/figcaption are the semantic elements, already used by MediaBlock.
  • (2) Official plugins: Payload's Lexical upload node has no alignment or lightbox on the front end.
  • (3) Open source: no maintained library does figure + badge + legend + lightbox with our kit.
  • Conclusion: compose our existing Media, Caption, Badge, Legend and the zoom from 01. New code is layout only.

Acceptance criteria

  • Not done: Tests come first: failing component tests for Figure (the badge renders as Badge neutral with the label text; the key and the long caption are not in the page's small view and are in the open lightbox; align="none" renders full width; size maps to the right class), then the code.
  • Not done: An axe check passes, closed and open (expectAccessible). The image has its alt text, the figure has a figcaption, and the lightbox has an accessible name.
  • Not done: From md up, a right-aligned figure floats right at the default width, and the next paragraphs wrap on its left. Below md it stacks full width. Headings clear it.
  • Not done: Alignment e2e: e2e/alignment.spec.ts (#678) gets a seeded post with a floated figure. At each of the six widths it checks that the figure's top lines up with the paragraph it starts beside, that no heading sits beside it, and that the text beside it is never narrower than a set minimum (so no column of one or two words). At 320 and 430 it checks the figure is stacked.
  • Not done: Text wraps well at all six widths: no line of one or two words beside the figure. If it happens at a width, the figure stacks at that width instead of squeezing the text.
  • Not done: Keyboard: the Enlarge button is reachable, Escape closes, focus returns to it, and the key is readable in the lightbox.
  • Not done: Colors and sizes come from theme tokens and layoutSizes.ts variables only. No literals.
  • Not done: A gallery entry shows Figure right, left and none, with and without a key, and docs/ui/component-set.md has a row for it, with Badge · neutral noted as the figure label's look.
  • Not done: #654 has the [DECISION] comment above, and its gallery spacing item is fixed here.
  • Not done: The width [PUSHBACK] and [QUESTION] are posted on this issue. The default is the answer when it comes, or 2/5 until then.
  • Not done: Checked at 320, 430, 768, 1024, 1280 and 1920 px in light and dark (visual-design-review).
  • Not done: Documentation follows behavior: the generated components reference is regenerated, and the figure rule (small view, lightbox, badge) is written in docs/ui/component-set.md in this PR. The guideline's width text is 07.

Files likely touched

  • new src/platform/ui/Figure.tsx (+ test)
  • src/platform/ui/layoutSizes.ts, src/app/(frontend)/globals.css (figure width variables)
  • src/platform/richtext/MediaBlock.tsx (only if its frame class moves to a shared constant)
  • src/app/(frontend)/dev/gallery/ (the entry, and the Legend sample fix from #654)
  • e2e/alignment.spec.ts, e2e/seed.ts
  • docs/ui/component-set.md, docs/reference/components/ (generated)

Must not touch

  • src/platform/ui/Legend.tsx, Caption.tsx, Badge.tsx: use them as they are. If one needs a variant, add it there and say so in the PR (use, configure or split).
  • src/platform/ui/Alert.tsx, src/platform/theme/, src/themes/ (05, 06)
  • Payload configs, src/payload-types.ts, src/migrations/ (03)
  • docs/guidelines/ui-ux-design.md (07)

Area

frontend, ux, styling

Priority

priority: medium


Generated by Claude Code, opens in a new tab

See it on GitHub, opens in a new tab