Repository navigation
Icons: maintain absolute stroke-width regardless of icon-size - #78774
Merged
Merged
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What?
This PR that I created with help from Claude does a few things:
It adds a new strokeWidth prop to the Icon component, so that not only does the stroke-width remain absolute across different sizes, you can change it from the default 1.5px.vector-effect="non-scaling-stroke", the only existing icon that is in trunk that is already fully stroke-based.For the moment, the only visual change will be in Storybook, and that is intentional, the system is fully backwards compatible: existing icons will work just as they did, they'll just ignore the strokeWidth prop.
The purpose of this effort is to enable a parallel effort of redrawing our entire icon set from fills to strokes (which sounds like a lot, but isn't actually since that's already mostly the case in the Figma source of truth, it mostly needs re-exports).
Doing that—redrawing the remaining icons to be stroke-based, in batches—is one of the followups after this PR, the other is to add the stroke property to the PHP counterpart as well, assuming #78332 lands.
Before:
After:
Why?
The icon set is currently fill-based, which means it scales poorly, e.g. to 16×16 as used in places like the Badge component, or upwards to larger icons where suddenly fill-based strokes can be very thick and out of place in its context. While not used widely for that precise reason, larger icons can play a meaningful role in empty-states.
How?
This PR is intentionally invisible to existing consumers:
Changes
ReactIconcomponent — addsstrokeWidth?: numberprop, passed throughcloneElementto the outer<svg>when set.PHPWP_Icons_Registry::sanitize_icon_content()— addsstroke,stroke-width,stroke-linecap,stroke-linejoin,vector-effect, andfillto thewp_ksesallowlist on<svg>,<path>, and<polygon>so stroke-based icons survive registry load.square.svg(the only existing stroke-based icon) — updated to the new convention as a canary:stroke,stroke-width,fillmoved to the outer<svg>so thestrokeWidthprop can override them.vector-effect="non-scaling-stroke"added to the path so the stroke renders at a constant pixel weight at any size. At 24×24 this looks identical to before; at 16×16 and 32×32 it now renders at a true 1.5px instead of scaling down/up. The two existing consumers (zoom-out-toggle, HTML block modal) render at the default 24px so are visually unchanged.Stroke widthRangeControl (0.5–5, step 0.25) to the icons library story for visualising the system and spotting which icons still need redrawing.Usage
Source SVG convention (for the redraw effort)
Stroke-based icons should carry the defaults in their source files so the raw
.svgpreviews correctly outside its rendered context:square.svgis the reference.Follow-ups
PHPwp_get_icon()stroke_widtharg — blocked on #78332 landing. Will be a one-line addition towp_get_icon()that calls$processor->set_attribute( 'stroke-width', ... )alongside the existing args. Tests to follow in that PR.Testing instructions
square.squareicon should respond; fill-based icons (e.g.plus,check) should not change.<svg>in DevTools and confirmvector-effect="non-scaling-stroke"is present on thesquarepath and that the outer<svg>'sstroke-widthreflects the slider value.Use of AI Tools
This PR was authored with Claude Code (Claude Opus 4.7). Tested and reviewed by the author; Claude Code is credited via
Co-Authored-Byin the commit.