Repository navigation
feat(Icon): a theme's width and height on an Icon size set its glyph dimension - #8759
Conversation
…dimension spec:AST-087 FR10 and component:Icon FR7: the `icon` target guarantees `width` and `height` on its size selectors. A theme writing them on `components.icon['size:sm']` now resizes that size's glyph for semantic icon names and for SVG components passed to Icon, at runtime and in built themes. The derived-var registry carries both properties as the private `--_icon-width` / `--_icon-height` vars, and Icon's size styles read them with each size's rem value as the fallback; registry glyphs also take the smaller side as their font size so 1em artwork follows. Sizes a theme does not style render as before.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
PR Analysis Report📚 Storybook Preview🧪 Sandbox PreviewModified ComponentsIcon (@astryxdesign/core) · View in Storybook
IconButton (@astryxdesign/core) · View in Storybook
Component Size
Sizes are gzip. Import counts the JavaScript the import loads eagerly; CSS counts the package stylesheet rules referenced by the modules it can load from its own package, lazily loaded ones included. Bundle Size SummaryGzip figures measure each package's entry file, not the code an import pulls in.
Accessibility AuditStatus: No accessibility violations detected. Visual Regression57 of 504 shot(s) changed. A change here is a question, not a failure: check whether the after is the
and 37 more. Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
There was a problem hiding this comment.
The registry route works: a theme's width and height on components.icon['size:*'] now size both semantic and SVG icons, whether or not StyleX is layered, and unstyled sizes are unchanged. Two small fixes are needed before this can be approved:
- With an
emdimension, a semantic icon's box resolves against its own enlarged font size, sosize:mdat1.25emin 16px text gives a 25px box around 20px artwork beside a 20px SVG icon; please either documentpx/remdimensions and add anemtest, or keep that box from compounding. apps/storybook/stories/IconSizeTheming.stories.tsxstill tells theme authors to addfontSizebecause width and height alone cannot resize a semantic glyph, and with a non-square dimension that rawfontSizemakes the glyph depend on StyleX layering again, so please drop it and describe the width-and-height form.
[Automated review]
| md: { | ||
| width: 'var(--_icon-width, 1.25rem)', | ||
| height: 'var(--_icon-height, 1.25rem)', | ||
| fontSize: 'min(var(--_icon-width, 1.25rem), var(--_icon-height, 1.25rem))', |
There was a problem hiding this comment.
With a font-relative theme value this reads the same var twice: font-size: min(…) resolves 1.25em against the parent text (20px in 16px text), then width/height resolve 1.25em against that 20px. The semantic box ends up 25px around 20px artwork, while an SVG icon at the same size is 20px. Either document px/rem dimensions and add an em test, or keep the box from resolving against the font size it sets.
There was a problem hiding this comment.
Took the documentation option in 2975578. The size prop docs, astryx docs theme, the Icon JSDoc and the changeset now say an Icon dimension is given in px or rem, and why. Stopping the box from compounding would take a second element around the artwork: the box's em resolves against the font size the artwork needs, and architecture:component-style-authoring INV5/INV7 do not admit that wrapper. On the em test: jsdom resolves neither var() nor em, so the ui project cannot observe this case. I measured it in Chromium instead (size:md at 1.25em in 16px text: 20px artwork in a 25px box, SVG component 20px, layered or not) and added that to Evidence. The same commit drops fontSize from the size theming story and describes the width-and-height form.
| content: [ | ||
| { | ||
| type: 'prose', | ||
| text: "A theme sets the dimension of each Icon size in its stylesheet: `width` and `height` on `components.icon['size:sm']` (or `xsm`, `md`, `lg`) resize that size's glyph, for semantic icon names and SVG components passed to `Icon` alike. A size the theme leaves alone stays 12, 16, 20, or 24px at a 16px root (`xsm`, `sm`, `md`, `lg`) and scales with the root font size; use `rem` values to keep that scaling. The four size names are fixed.", |
There was a problem hiding this comment.
"alike" holds for px and rem only. With an em value, semantic icons get a larger box than SVG components (see the comment on IconSize.stylex.ts), so it is worth saying which lengths an Icon dimension takes.
There was a problem hiding this comment.
Done in 2975578: the section now says to give the dimension in px or rem, and that an em value would also grow a semantic icon's box.
… workaround from the size theming story A semantic icon takes its font size from the theme's dimension, so an `em` dimension would also grow its box. The docs now say which lengths the dimension takes. The size theming story no longer tells theme authors to add `fontSize`: width and height alone size both glyph modes, and a raw `fontSize` beside a non-square dimension would make the glyph depend on StyleX layering again.
There was a problem hiding this comment.
Incremental review of bc1001c..2975578; prior findings carried: user_impact.
This looks ready to approve: both earlier points are resolved, with every surface that describes Icon size theming now saying to give the dimension in px or rem and why, and the Size Theming story teaching width and height alone while rendering the same frames as before. One behavior to keep in mind is that component-owned icon boxes such as Button's 16px icon wrapper keep their own size, so a theme that enlarges sm past 16px will see the glyph overflow there, which AST-087 leaves out of scope.
[Automated review]
…ensions # Conflicts: # packages/cli/test/__golden__/no-icon-set/search-icon-set.json # packages/cli/test/__golden__/no-icon-set/search-icon-set.txt
There was a problem hiding this comment.
The Icon size theming itself looks ready: width and height on components.icon['size:*'] now size both semantic and SVG icons in runtime and built themes, whether or not StyleX is layered, and unstyled sizes are unchanged. One small change is needed before approval: the merge from main rewrote packages/core/src/Kbd/Kbd.tsx:93 into a one-line braced form that neither parent has and Prettier rejects, so please restore main's version of that file (git checkout origin/main -- packages/core/src/Kbd/Kbd.tsx). Nothing in the Icon change needs to move.
[Automated review]
| return isMac ? '\u2318' : t('@astryx.kbd.key.controlShort'); | ||
| } | ||
| if (key === 'escape') return t('@astryx.kbd.key.escapeShort'); | ||
| if (key === 'escape') {return t('@astryx.kbd.key.escapeShort');} |
There was a problem hiding this comment.
This line comes from the merge commit, not from either parent: main has if (key === 'escape') return t('@astryx.kbd.key.escapeShort');. Behavior is the same, but Prettier rejects the one-line braces and Kbd is unrelated to Icon sizing, so restoring main's file (git checkout origin/main -- packages/core/src/Kbd/Kbd.tsx) takes it out of this pull request.
There was a problem hiding this comment.
Restored main's file in 06a73fa. The pre-commit autofix had rewritten that line while committing the merge; the branch no longer touches Kbd.
…ix during the main merge
There was a problem hiding this comment.
The Icon size theming works as intended: width and height on components.icon['size:*'] now size semantic and SVG icons in runtime and built themes whether or not StyleX is layered, unstyled sizes are unchanged, and restoring Kbd.tsx clears the earlier point. One change is needed before approval: iconRegistrySizeStyles is now exported from packages/core/src/Icon/IconSize.stylex.ts, which the package publishes as @astryxdesign/core/Icon/IconSize.stylex, so it would ship as new public API that no spec admits, and removing it later would need the compatibility process. Please declare it somewhere the package does not export, for example beside styles and colorStyles in Icon.tsx, so that subpath keeps the exports it has today.
[Automated review]
| * so `fontSize` follows the glyph dimension too: the smaller side, which fits | ||
| * square artwork into a non-square box the way an SVG viewBox does. | ||
| */ | ||
| export const iconRegistrySizeStyles = stylex.create({ |
There was a problem hiding this comment.
This module is published as @astryxdesign/core/Icon/IconSize.stylex (the ./Icon/IconSize.stylex entry in packages/core/package.json), so this export ships as public API that no spec admits, and removing it later would need the compatibility process. Only Icon.tsx reads it, so declaring it there beside styles and colorStyles keeps the subpath's exports as they are today.
There was a problem hiding this comment.
Moved in 1f446ae: the registry size styles now live beside styles and colorStyles in Icon.tsx and are not exported. @astryxdesign/core/Icon/IconSize.stylex exports exactly what it did before (IconSize, iconSizeStyles, iconBoxSizeStyles).
The published IconSize.stylex subpath keeps exactly the exports it had before this change; only Icon reads the registry glyph sizes.
There was a problem hiding this comment.
This looks ready to approve: width and height on components.icon['size:*'] now size both semantic and SVG icons in runtime and built themes, whether or not StyleX is layered, and icons without theme size styles render exactly as before. The registry size styles now live unexported in Icon.tsx, so @astryxdesign/core/Icon/IconSize.stylex keeps the exports it has on main. One behaviour to keep in mind is that component-owned icon boxes such as Button's 16px wrapper keep their size, so a theme that enlarges sm gets a glyph slightly larger than that box, which AST-087 leaves out of scope.
[Automated review]
The only conflict is the CLI's icon-set search golden, which counts matching docs: main's meta#8753 and meta#8759 add two icon docs (367 → 369), and this pull request's on-screen keyboard section adds one. Regenerated at the merged tree with the golden test's --update, as its header says to: the count is 370 and the twenty results shown are main's.
User need
A theme author who wants a product's icons at a different scale — a dense theme with smaller
smicons, or a brand whose artwork reads better slightly larger — has no working way to change what an Icon size measures. Writingwidthandheighton theicontarget only resizes the box around a semantic icon: its 1em artwork keeps the old size inside it. In an app that compiles StyleX without CSS layers, the theme rule loses to Icon's own size styles and nothing changes at all. Authors fall back to patching the Icon component, wrapping it, or passing pixel sizes at every callsite, so the product's icon scale drifts per callsite instead of being one theme decision.Problem and solution fit
icontarget's dimension. The derived-var registry carrieswidthandheightwritten on theicontarget as two private vars, and both glyph modes size from them, falling back to each size's rem value. A semantic icon's box also takes the smaller side as its font size, so the 1em artwork that the built-in icons and the shipped themes supply follows the dimension.Icon.doc.mjstheming.vars/theming.derivedmetadata, consumer docs for the size prop and an Icon sizes section inastryx docs theme, the size theming story's guidance (it no longer tells authors to addfontSize), focused tests at the runtime and built-theme layers, and a changeset.Current specification
spec:AST-087FR10 and DEC-3: the Icon theming target guaranteeswidthandheighton its size selectors; without theme styles, sizes are 12, 16, 20, and 24px at a 16px root and scale with the root font size.component:IconFR7 (the guarantee as a reviewed target-specific addition), FR3 (width, height, and font size for 1em sources), ORD2.architecture:component-theming-surfaceINV7, INV8, and INV11 (exact declared properties; private expansion stays private).architecture:theme-compilationINV2–INV5 (one compiler for runtime and built themes; a guaranteed property may route through a checked registry entry to stay observable).Public delta and caller burden
Theme code is unchanged; what it does changes:
Iconresized only when StyleX was layered; in an unlayered StyleX app neither changed.smandlgglyphs render at the theme's dimension for semantic icon names (built-in and theme-supplied artwork) and for SVG components, in runtime and built themes, layered or not.Compatibility:
width/heighton theicontarget as Icon's private size vars rather than as raw properties, the way it already does forprogress-bar-mark.viewBoxalready does for an SVG component.pxorrem, as the docs say. A semantic icon takes its font size from the dimension, so anemdimension also scales its own box:size:mdat1.25emin 16px text renders 20px artwork (as an SVG component does) inside a 25px box. Avoiding that would need a second element around the artwork.fontSizeit told theme authors to add: width and height now size both glyph modes, and a rawfontSizebeside a non-square dimension would make the glyph depend on StyleX layering again.xstylewidth or height on an Icon wins over the theme's dimension in every cascade (ORD2); before, the result depended on whether StyleX was layered.Caller decisions added: none for product code. Theme authors who want sizes to keep scaling with the root font size use
rem, as the docs say.Design and alternatives
replaces: true) to private vars that only Icon's size styles read, with each size's value as the fallback. This is the existingprogress-bar-markmechanism. It lands whatever the consumer's StyleX layering is, and runtime and built themes share it because both call the same compiler.width/heightand add a font size. Raw properties still lose to unlayered StyleX, and a font size cannot follow a width declared by another rule.architecture:component-style-authoringINV5 and INV7 do not admit.--icon-sizecustom property.architecture:component-theming-surfaceINV10 admits a public var only when no guaranteed property expresses the need;widthandheightdo.Evidence
Automated:
Icon.test.tsx: for each of the four sizes, a runtime theme that styles only that size mounts a rule that writes the dimension (18×22) into exactly the vars that size's glyph reads, in both source modes, with no rawwidth/height; a semantic icon's font size reads both vars; the other three sizes get no rule and keep their own rem value. Unthemed sizes resolve to 0.75, 1, 1.25, and 1.5rem in both modes. Fails if the registry entry is removed, if a size stops reading a var, or if the registry font size stops following.IconButton.test.tsx: the contextual-size suite reads the Icon's unthemed value through the same fallback; the wrapper is unchanged.derivedVarRegistry.test.ts: the registry entry, its doc mirror, and that a component reads each var.build.test.mjs:astryx theme buildwrites theiconsize dimension as the same vars, with no warnings.Real browser (Chromium 149, headless). I rendered the same matrix on this branch and on
main: each Icon size × a built-in semantic icon, a theme-supplied 1em semantic icon, and an SVG component withwidth="24" height="24"attributes. Pages carry the StyleX CSS from the test compiler, both unlayered and inside@layer astryx-base, plus the theme CSS from the runtime provider or fromastryx theme build. The theme stylessize:sm18×18 andsize:lg32×28;xsmandmdare unstyled. Cells give the icon element's box, then the artwork's box where they differ, in px:mainand branch, no theme, 16px rootmainand branch, no theme, 20px rootmain, runtime theme, unlayered StyleXmain, runtime theme, layered StyleXWith
size:mdat1.25em(16px text), both semantic icons render 20px artwork in a 25px box and the SVG component renders at 20px, layered or not: the documented reason dimensions takepxorrem.Not covered here: WebKit and Firefox runs, and screenshots attached to this description. Unthemed pixels are unchanged by construction (identical measurements above); the visual gate on this pull request checks the stories.
Scope
Testing
pnpm exec vitest run --project ui packages/core/src/Icon packages/core/src/IconButton packages/core/src/Button packages/core/src/theme/derivedVarRegistry.test.ts: pass.pnpm exec vitest run --project node packages/cli/api/theme/build/build.test.mjs: pass.pnpm exec vitest run --project node packages/cli/test/experimental-isolation.test.mjs --update: the no-icon-set goldens gain the newthemedocs section and its two search matches, and nothing else.pnpm test:ui: everything this change touches passes.DateTimeInputTouchandCodeBlockHeaderPluginfailed under full-suite load and pass alone. Thepostinstall.test.mjsmonorepo-nudge case also fails onmainin this environment.pnpm exec vitest run --project node packages/cli/api/docs packages/cli/foundation/doc-compiler packages/cli/foundation/discovery packages/cli/test: pass after the golden update, exceptpackages/cli/test/global-local.test.mjs, which fails the same 18 cases onmainin this environment.pnpm -F @astryxdesign/core typecheck,pnpm -F @astryxdesign/cli typecheck(after building@astryxdesign/theme-neutral),pnpm check:repo, strict ESLint and Prettier on changed files: pass.