Repository navigation
Theme: Add shadow tokens that adapt to the background seed - #87287
Conversation
🤖 PR meta 🤖🎉 PropsIf you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
Updated as activity occurs, without notifying anyone named here. Add the 📦 Bundle sizeSize Change: +3.68 kB (+0.04%) Total Size: 8.73 MB 📦 View Changed
⚡ PerformanceShow the resultsClient side metrics exclude the server response time. front-end-block-theme
front-end-classic-theme
media-processing
media-upload
post-editor
site-editor
🏁 Flaky testsSome tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information. As a user I want to be able to create a navigation overlay for a specific navigation block in
|
a63f427 to
29bdaf0
Compare
|
For the open question about the Popover and Menu stroke: #87288 is a draft on top of this PR that hides the stroke (keeping it in forced-colors mode) and raises the minimum shadow opacity from 0.05 to 0.08, so the two can be compared in Storybook. |
For @WordPress/gutenberg-design the min/max of this is easily adjusted. Please feel free to check out the branch, adjust, and push suggestions. |
There was a problem hiding this comment.
Thanks for picking this up! At a high level, I feel like we now have so many PRs all happening at once, maybe it would be better to discuss how we want to prioritise DS work? I remember you said you were working on high contrast too, for example?
Apart from that, I'll leave some initial thoughts. The overall approach (box shadow values depending on bg seed) sounds like a good start. A couple of bigger-picture things before we tune values:
- I'd keep the stroke and drop the top highlight. On dark backgrounds a black shadow has very little left to darken, so the lighter stroke ends up doing most of the work. I looked at a few major design systems, and most of them keep a lighter stroke on popovers in dark mode. None of them uses a top highlight. Keeping the stroke also lines up with the surface + edge + shadow idea from #75266, and dropping the highlight gets rid of the doubled top edge.
- I'd reconsider the
--wpds-elevation-*name. We removed these tokens in #80099, partly because the name didn't fit: they're really just shadows. I'd either call them that (something like--wpds-shadow-*), or design elevation as a whole, with surface, border and shadow tokens that work together.
Numbers and references
CIELAB lightness difference (ΔL*) from the surface, using the PR's curve and our generated ramps:
| Seed | Shadow | 100% black shadow | Stroke | Highlight |
|---|---|---|---|---|
#ffffff |
4.4 | 100 | 11.5 | 0 |
#777777 |
11.6 | 64.7 | 11.4 | 1.9 |
#1e1e1e |
4.1 | 11.3 | 7.0 | 9.0 |
#000000 |
0 | 0 | 10.2 | 11.2 |
Lighter strokes in dark mode: Primer (0 0 0 1px #3d444d), Atlassian (0 0 0 1px #BDBDBD1F), Radix (gray-a6) and Spectrum (popover-border-opacity 0 in light, 1.0 in dark). Primer and Spectrum add the stroke only for dark mode. Fluent and Material 3 have no stroke and use lighter surfaces instead.
Smaller points:
- Menus from the site editor sidebar (dark seed) keep their 27% shadow when they spill over the light content area, so they look about 5× darker there. Might be worth a quick look.
grid,edit-site,block-editorandeditorstill use the old static$elevation-*variables. Maybe a follow-up issue?- Tiny one: the
ELEVATION_LEVELSJSDoc points totest/elevation.ts, but the file istest/elevation.test.ts.
|
Fair, I'll remove the highlight to discuss separately. |
|
Prioritisation is probably something we should work on as a group. I'd consider this low prio fwiw. |
|
I think I agree with the principle: the darker the background, the higher the opacity, which I understand is the only shadow property changing. An interesting question, should the colour of the shadow also change based on background tint? Not something to explore here, but something to ponder. E.g. if the background is theme coloured, seeding the shadow with that might be nice too. |
|
I think tinted shadows are worth exploring in a follow-up. They already pick up the background a little, but the pure black shadows can look a bit muddy on saturated backgrounds. Using a dark shade of the seed's own hue would look richer. That said, shadows don't always cast on the seed background. Especially in the editor menus and such can appear over images and basically any color imaginable. It's fine in the default theme which has a neutral background seed, but tinted shadows could look odd these cases. |
|
The highlight removal, the rename and the new curve all look good to me. I re-ran some checks, and A few things before this lands: Tooltips get a much stronger shadow. What should the token follow? The tooltip is one case of a broader mismatch. The token follows the provider around the surface, but the shadow falls on whatever is behind it. I also need to correct my earlier point about sidebar menus. Portaled menus and popovers read the light root provider, so they look the same as trunk even when opened from the dark sidebar. That also means most popovers, menus and dialogs in wp-admin won't change with this PR until an app has a dark root seed. Should snackbars read the content seed, or do we accept this for now? Either way, I think the README should say that the token assumes the surface sits on its provider's background. Description. It still covers the two-layer version, including the "Visible change" note, the 9% and 16% figures, and probably the screenshots. Could you refresh it now that the tokens match Let's also make sure to track the follow-up refactor across the rest of the repo |
|
Probably not the place to discuss it but should we revisit the decision to render The screenshots are accurate. |
4b52a1e to
49fe0a1
Compare
|
Applied the changes you suggested and updated the PR description. Once this merges, I'll open follow-ups for:
|
Agreed that the What replaces it is a design decision first. I see two options:
The color ramps already generate the colors for both. What's missing is dedicated semantic tokens. The always-dark colors ( So the next steps would be:
The same decision should cover Snackbar. This probably deserves its own issue so it doesn't hold up this PR. |
|
Actually I think the tooltip should just follow the theme—no fancy inversion or exceptions. But yes this will need to be discussed in a dedicated issue. Any other changes to make in this PR do you think? |
|
Update: after chatting with @jameskoster , we agreed to ship the "safe" version of this PR soon (ie adding Separately, we prepared a list of follow-ups that we're going to work on; the list is in the PR description and it involves both changes / improvements in the repo, and next steps / iteration on the elevation work, specifically on how to best visually show elevation on dark surfaces. |
- Link to the token reference with a full URL, so the link also works in the Storybook copy of the README. - Stop claiming shadows look the same on any background. They strengthen up to a cap, and near black the stroke separates the surface. - Restore the formatting of README sections this PR doesn't change, including a JSON example that had gained trailing commas.
The parity test compared rounded CSS output, so a small change to a layer in `shadow.json` could pass without updating `SHADOW_LEVELS`. Compare the raw layers too.
Light backgrounds other than the default already get a slightly stronger shadow, for example `#eeeeee` gets a scale of 1.1.
`ThemeProvider` doesn't paint a background. It generates `--wpds-color-background-surface-neutral` from the seed and scales the shadows for that color. Use that one description across the docs, changelog, story, and comments, and state that the shadows match the backdrop when the area behind a surface uses that token.
`AlertDialog.Popup` uses the Dialog popup styles, so it gets the same adaptive shadow.
Wrapping a portaled popup in a `ThemeProvider` doesn't change its tokens, because the portal mounts it outside the provider's element. Point those consumers to the portal container instead.
The switch thumb's border is the control's accessible outline, not part of its elevation. Drawn on a story card, its dark interactive stroke suggested that `xs` surfaces get a heavy border. Show no stroke for `xs`, use content frames as the main example, and say in the token reference that controls keep their own border.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The name now says the tokens are outer box shadows, which leaves room for inner (inset) shadow tokens later. Also loosen the elevation guidance: the docs no longer tell consumers to pair a shadow with a stroke, because the design system hasn't decided whether raised surfaces should have one. The Shadow stories show only the shadows, and gain stacked overlay examples on light and very dark backgrounds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Show a content frame with a menu and a submenu over it, using placeholder lines instead of labels and token names. Drop the dialog, which isn't accurate without its scrim, and the tooltip. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An earlier commit reformatted every list item in the components, ui, and theme changelogs from `- ` to `- `, which conflicted with trunk on every rebase. Keep trunk's formatting and change only this PR's entries. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
fd41c52 to
c6806d3
Compare
| * | ||
| * Prefer the matching --wpds-shadow-outer-* design tokens in new code. | ||
| */ |
This comment was marked as duplicate.
This comment was marked as duplicate.
Sorry, something went wrong.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ciampo
left a comment
There was a problem hiding this comment.
LGTM 🚀
Let's merge and iterate per the "follow-up" section in the PR description


What?
Part of #75266
Adds
--wpds-shadow-outer-xs,-sm,-mdand-lgtokens whose strength adapts to theThemeProviderbackground, and uses them for the shadows in@wordpress/uiand@wordpress/components.Why?
The shadows are semi-transparent black, so they almost disappear on dark backgrounds. Popovers, menus and dialogs lose their depth in dark themes.
How?
$elevation-*Sass variables, so the default background looks exactly like trunk. Other light backgrounds get a slightly stronger shadow, for example ×1.1 on#f0f0f0.ThemeProvidermakes the shadows stronger, up to 5×, so they stay visible. Near black, a shadow has little left to darken, so it still shows less.$elevation-smallfor now. In the site editor it floats over light content from inside a dark provider, so the token would make its shadow too strong.How the strength is calculated
ThemeProviderscales every layer's opacity so the shadow darkens the background by the same perceived amount (CIELAB ΔL*) as it darkens white: about 1.3× for#bbbbbb, 1.9× for#777777and 3.2× for#3d3d3d. Near black no scale can reach that, so it stops at 5×, and no single layer goes above 25%.--wpds-color-background-surface-neutral), not the raw seed. The background ramp can move that color away from the seed: a#777777seed generates#9d9d9d. For the default seed the two are the same.packages/theme/src/shadow.ts) and output with the color tokens whenever a color seed is set. Without a seed, the static values intokens/shadow.jsonapply.tokens/shadow.json, that the default output matches the static tokens, and that two seeds with the same surface color get the same shadow.Affected components
@wordpress/ui: AlertDialog, Autocomplete, Combobox, Dialog, Drawer, Menu, Popover, Select, Switch and Tooltip.@wordpress/components: CustomSelectControl, FormToggle, Menu, Modal, Popover, ResizableBox and Tooltip. Snackbar keeps$elevation-small(see follow-up 4).Tooltip.Popuprenders inside its own darkThemeProvider, but its shadow falls on the page behind it. The positioner reads--wpds-shadow-outer-smoutside that provider, so tooltips on a light page keep trunk's shadow.Docs and naming
$elevation-*variable to its token, and the Storybook elevation page points to both. A comment in_variables.scsstells new code to prefer the tokens. The variables keep their static values (see follow-up 3).--wpds-elevation-*earlier, but Theme: Remove elevation tokens #80099 removed elevation tokens because they were only shadows. If elevation needs another part later, it gets a token of its own type. Theoutersegment says these are outer box shadows, as the CSS spec calls them, and leaves room for inner (inset) shadow tokens later.--wpds-color-stroke-surface-neutralstroke. The docs don't tell consumers to pair a shadow with a stroke, because we haven't decided whether raised surfaces should have one (see follow-up 2). The Shadow stories show only the shadows. An earlier top-edge highlight was removed after review, and Try: Hide the Popover and Menu stroke and strengthen light elevation #87288 (hiding the stroke instead) was closed.Testing Instructions
npm run storybook:dev.xs) with a menu and a submenu (md) open over it. Each layer should stay distinct from the one below it. On the dark background the shadows are at the strength cap, so they separate the layers less.@wordpress/uiPopover, Menu, Dialog and Tooltip stories, and the@wordpress/componentsModal, Popover and Tooltip stories. They should match trunk on the default background, and still look raised when you switch the Storybook theme to a dark background.More checks in the Shadow story
#777777row should read "surface #9d9d9d · shadow scale ×1.5".Testing Instructions for Keyboard
No interaction changes. The affected components open and close with the keyboard as before.
Screenshots
The After screenshot was taken before the rename, so its cards show the old
--wpds-shadow-*names.Follow-ups
ThemeProviderseed, and look inverted with a lesser hack instead (foreground tokens for the background, background tokens for the foreground). This is a better stopgap than the current one. Check the@wordpress/componentsTooltip too, which hard-codes the same dark colors. Then remove the--_wp-ui-tooltip-shadowworkaround on the Tooltip positioner: without the nested provider, the popup reads the page's shadow, which also fixes a Tooltip with a custompositioner. (@ciampo ) Done in Tooltip: Invert the theme's neutral tokens instead of nesting a dark ThemeProvider #87817.@wordpress/components) and Block Editor, Editor: Use WPDS tokens on raised surfaces #87841 (@wordpress/block-editorand@wordpress/editor). The toolbar variant keeps its high-contrast stroke to match the block toolbar:componentsPopover (isAlternate), Dropdown and Menu (variant="toolbar"), and theblock-editorblock switcher preview. A comment at each one links to Applying design system foundations to the Block Toolbar #67426 and Toolbar: Paint the floating toolbar with the Menu surface. #84567.$elevation-*variables: deprecate in favor of the shadow tokens, or keep (while aliasing the WPDS tokens)? A risk of aliasing them to the tokens is that an alias would move third-party code to the adaptive shadow without checking which background it floats over.edit-siteandboot, then move Snackbar to--wpds-shadow-outer-sm. (@ciampo ) Done in Snackbar: Use WPDS shadow tokens, improve theme inheritance #87818.$elevation-*users (11 files in 6 packages) to the shadow tokens. (@ciampo ) Block Editor, Editor: Use WPDS tokens on raised surfaces #87841 moved theblock-editorURL input modal and theeditorcollaborators popover. Tooltip, Snackbar: Follow the theme instead of staying dark #87863 moves the block drag chip and the canvas stop hint off$elevation-small.1. Tooltip with a custom positioner
Tooltiponly reads the outer shadow on its own positioner. A custom element passed to thepositionerslot resolves the shadow inside the popup's dark provider, so it gets the 5× shadow on a light page. Removing the provider in 1a fixes this.2. Strokes on raised surfaces today
@wordpress/uiPopover, Menu, Dialog and Drawer, and the Select, Combobox and Autocomplete popups, use--wpds-color-stroke-surface-neutral. Popover, Dialog and Drawer make it transparent when they show a backdrop.componentsPopover draws the same token as a box-shadow ring.componentsMenu and CustomSelectControl use the same token (Components: Use WPDS stroke tokens on raised surfaces #87840).block-editorquick inserter and URL input, and theeditorcollaborators popover, use the same token (Block Editor: Use theme colors in the inserter, sidebars, header, and footer #87426, Block Editor, Editor: Use WPDS tokens on raised surfaces #87841).componentsPopover (isAlternate), Dropdown and Menu (variant="toolbar"), and theblock-editorblock switcher preview.widget-dashboardtoolbar uses the weak surface stroke.componentsModal, theedit-sitecontent frames, theeditorselected note and thegriddrag previews have no stroke.4. Snackbar
In
edit-siteandboot(together, for site editor parity), renderSnackbarNoticesunder the light content provider, for example by wrapping it in<ThemeProvider color={ CONTENT_COLOR }>. It renders in three places:edit-site/src/components/layout/index.jsx,boot/src/components/root/index.tsxandboot/src/components/root/single-page.tsx.UploadProgressSnackbaronly creates a notice and renders nothing, so it doesn't need to move. Snackbar hard-codes its own colors, but its focus ring uses--wpds-color-stroke-focus, so check the focus ring as well as the shadow.5. Remaining
$elevation-*usersBefore moving each one, check which
ThemeProviderit renders in and which background it floats over (see the README's Shadows section).componentssnackbar/style.scsssmedit-sitelayout/style.scss(3 uses)xs,lgon hoverblock-editorinserter/style.scssxs--wpds-color-stroke-surface-neutralblock-editorblock-draggable/style.scss(2 uses)smblock-editorwriting-flow/style.scsssmeditorcollaborators-presence/avatar/styles.scssxseditorcollab-sidebar/style.scssmdgriddashboard-grid/grid.module.scss(8 uses)md,xsgriddashboard-lanes/lanes.module.scss(8 uses)md,xswidget-dashboardwidget-toolbar/widget-toolbar.module.scssxs--wpds-color-stroke-surface-neutral-weakwidget-dashboardwidgets/widgets.module.scssxsThe deprecated
__experimentalElevationcomponent is unchanged.src/shadow.tsfromtokens/shadow.jsonduring the token build, so a shadow change needs one edit instead of two. A test catches the two drifting apart until then.Use of AI Tools
Written with Claude Code (Claude Opus 5.5): the token design was worked out together, Claude wrote the implementation, tests and story, and I reviewed the result and checked it in Storybook. After review, Claude Code added the surface-based scale, the Snackbar change, the documentation, the story updates and the
outerrename, at ciampo's direction.🤖 Generated with Claude Code