Repository navigation
Block Editor, Editor: Use WPDS tokens on raised surfaces - #87841
Conversation
Use the surface stroke, background, and shadow tokens for the URLInputButton modal and the collaborators popover. The collaborators popover also takes its text colors from the tokens, so it stays readable in dark themes. Note that the block switcher preview keeps its toolbar-style stroke, pending the block toolbar design. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
🤖 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: +324 B (0%) 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
|
|
Thank you, @Mamaduka ! Next up, I'll look into some follow-up work that involves cleaning up Avatar-related custom styles and re-use the new |
What?
Follow-up to #87287 (follow-ups 2a and 5). See #75266. Companion to #87840, which does the same for
@wordpress/components.The
URLInputButtonmodal in@wordpress/block-editorand the collaborators popover in@wordpress/editornow use WPDS tokens for their stroke, background and shadow. The block switcher preview keeps its toolbar-style stroke, with a comment that points to the block toolbar work.Why?
These two raised surfaces hard-code
$gray-300strokes, a$whitebackground and$elevation-*shadows, so they don't follow the theme. On a dark theme they stay white. The design system hasn't decided yet whether raised surfaces should have a stroke (#87287, follow-up 2), but the strokes that exist today should still use tokens.How?
$gray-300becomes--wpds-color-stroke-surface-neutral, and$border-widthbecomes--wpds-border-width-xs. In theURLInputButtonmodal, this also covers the divider next to the back button. The collaborators popover keeps its stroke on the top and left edges only.$whitebecomes--wpds-color-background-surface-neutral-strong, the background thatPopoveralready uses.$elevation-x-smalland$elevation-smallbecome--wpds-shadow-outer-xsand--wpds-shadow-outer-sm. On the default background the tokens resolve to the same layers, so the shadow looks the same as trunk.$gray-700and$gray-900. Without this, the names would be dark text on a dark background in a dark theme.$gray-900stroke matches the high-contrast block toolbar, so it stays. A comment links to Applying design system foundations to the Block Toolbar #67426 and Toolbar: Paint the floating toolbar with the Menu surface. #84567, which changes the block toolbar and drops this stroke.On the default theme, the only visible change is a slightly different gray:
#dbdbdbinstead of#ddd.Testing Instructions
URLInputButtonhas no caller in Gutenberg. To check it, render<URLInputButton url="https://wordpress.org" onChange={ () => {} } />from@wordpress/block-editorin a block or a Storybook story, and click the link button. The modal should look the same as on trunk.ThemeProviderwith a dark background, such as#1e1e1e. The surface should be dark with light text, like the screenshots below.Testing Instructions for Keyboard
No interaction changes. The collaborators popover and the
URLInputButtonmodal open and close with the keyboard as before.Screenshots or screencast
Storybook, using temporary local stories that render the two components (the stories are not part of this PR). Before is trunk (
1e3f8e76cbb), After is this branch.Collaborators popover, dark color theme:
Light color theme, and the URLInputButton modal
Collaborators popover, light color theme. No visible change.
URLInputButtonmodal, light color theme. No visible change.URLInputButtonmodal, dark color theme. The white background and light stroke become the dark surface and its stroke.Follow-ups
The collaborator avatar draws a hard-coded
$whitering, which shows in the dark screenshot above. Instead of changing that ring to a token, the collaborator UI should move to the@wordpress/uiAvatar, which was built for collaborator avatars. I checked the risks in the post editor on a local site (see the details below). The steps are:collaborators-overlayinjects about 380 lines of CSS written as TypeScript strings (avatar-iframe-styles.ts,overlay-iframe-styles.tsandcollaborator-styles.ts). They include copies ofbase-stylesvalues that must be kept in sync by hand. A.module.scssfile in@wordpress/editorreaches the canvas iframe through@wordpress/style-runtime, and it can@usebase-stylesdirectly. Done in Editor: De-duplicate the collaborators overlay styles with a CSS module #87862.@wordpress/style-runtimeas a dependency of@wordpress/editor.:global()or module classes for the classes that other code also uses, such as.block-canvas-cover,.editor-avatar*and the cursor and label classes.MAX_BLOCK_LABEL_AVATARSbecome an SCSS loop.Avatarmigration.AvatarhasdimmedandstatusIndicatorfor disconnected collaborators. The uiAvatarhas neither. Either add an inactive state to the uiAvatar, or keep a wrapper in the editor. The uiAvatarpassesclassNameandstyleto its root, so a wrapper can style it. In progress in Editor: Add a collaborator avatar with an inactive state #87889, which keepsdimmedin an editor wrapper. Whether it belongs in the uiAvataris discussed there. The wrapper dropsstatusIndicator: no caller has ever passed it.Avatarin these places. Decided: the uiAvatardesign is the target. Its fill (a darker tint of the collaborator color inside the ring, with initials that contrast with it) and its gap around images replace the editor's solid fill, white initials and white inner ring. What remains is its larger footprint, which steps 4 and 5 handle.Avatarreserves a 3px track for the ring, so uismtakes 27px (a 24px image) against 24px today, and uimdtakes 35px against 32px. The editorAvatardraws its 2px white ring with abox-shadowoutside its 24px box, so it shows about 28px but reports 24px to layout. The uiAvatarcounts the ring in its box, so most of the difference is in layout, not in what people see.Avatarkeeps the track, so turningactiveon or off never shifts layout. Consumers lay out against the footprint. A custom property on theAvatarroot wouldn't help them, because a parent can't read a child's custom property.translate: -50%centers an element on its own box, the overlap in a group is a design value, andgapspaces a row. Where a layout needs it, the footprint is the size token plus 3px, such ascalc(var(--wpds-dimension-size-sm) + 3px). UI: Document the Avatar footprint of each size #87892 documents the footprint of each size.Avatar(collaborators-presence/index.tsxandlist.tsx), withcolorandactive, after steps 2 and 3.AvatarGroupstays in the editor. Its overlap and stacking selectors target.editor-avatarchildren, so they change. Retune its overlap to the 27px box.CollaboratorAvatarfrom Editor: Add a collaborator avatar with an inactive state #87889 withdimmed, and keeps the 35px avatar. The row grows by 3px.aria-hidden="true", since the row already names the person.Avataris marked "use with caution", so@wordpress/use-recommended-componentsfails on the import. Add an inlineeslint-disable-next-linewith a reason, ascore-fields/src/shared/author/avatar.tsxdoes.Avatar, after steps 1 to 3. The badge stays in the editor: a pill in the collaborator color, with the uiAvatarinside and the name that expands on hover. A cursor label expands on its own hover, and a block label expands when the pointer is over its group. The editor still calculates the name color against the pill color. Replacetranslate(-11px, -100%)and the stack margins: center a wrapper sized to the avatar on the caret withtranslate: -50%, instead of a hard-coded offset. Then remove the editorAvatarand its iframe CSS.What I checked, and how
I added a temporary harness to the canvas overlay and didn't commit it. It rendered the editor
Avatarand the uiAvatarside by side, with a.module.scssprobe, in the post editor onwp-env(WordPress trunk). I measured the computed styles inside the canvas iframe.Iframewraps its content inStyleProvider, which registers the iframe document with@wordpress/style-runtime. ui CSS modules callregisterStyle, so the runtime injects them into that document. The uiAvatarstyles, the ui global CSS defenses and the--wpds-*tokens were all in the iframe.wp-themeloads the tokens there. The sizes matched the expected values.@wordpress/editorworks too. The probe compiled withbase-stylesvalues, and the runtime injected it into the iframe. The editor always renders the canvas in an iframe (shouldIframeinvisual-editor), so the overlay never renders without one.@layer wp-ui, and CSS in a layer loses to theme CSS that isn't in a layer. I tested 9 themes: Twenty Nineteen to Twenty Twenty-Five, the default theme, a dark theme and an empty theme. In all of them, the size, radius, image and initials font of the uiAvatardidn't change. Only two inherited values came from the theme:coloron the root, which the initials don't use, andletter-spacing. The current editor avatar takes the theme's font family and size in all of them, including Times in the empty theme.spanandimg. I added rules without a layer, such as.editor-styles-wrapper spanand.editor-styles-wrapper img, which set font, border, radius and opacity. Both avatars broke. The uiAvatarkept its size, and the editor badge grew from 24px to 46px. The migration doesn't add exposure, but neither implementation fully resists theme CSS onspanandimg.Avatarfrom@wordpress/uiin@wordpress/editorfails@wordpress/use-recommended-componentswith "not yet recommended". That is why step 4 needs the inline exception.Use of AI Tools
Written with Claude Code (Claude Opus 5.5), at my direction: Claude made the change, captured the screenshots, and drafted this description.
🤖 Generated with Claude Code