feat: add createIcon factory to decouple Icon from a single icon set#786
Open
adrienzheng-cb wants to merge 2 commits into
Open
feat: add createIcon factory to decouple Icon from a single icon set#786adrienzheng-cb wants to merge 2 commits into
adrienzheng-cb wants to merge 2 commits into
Conversation
Extract the web and mobile Icon rendering into a `createIcon<Name>` factory
that binds a glyph map, font family, and typed name union. The default
`Icon` becomes `createIcon<IconName>({ glyphMap, fontFamily })`, so behavior
and the public API are unchanged, while consumers with their own icon
package can create a typed icon component that reuses all CDS rendering,
accessibility, and theming logic.
Font family is now injectable (moved off the static Linaria block on web to
an inline style) rather than hardcoded, enabling alternate icon sets without
forking the component.
Co-authored-by: Cursor <cursoragent@cursor.com>
Collaborator
🟡 Heimdall Review Status
🟡
|
| Code Owner | Status | Calculation | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| ui-systems-eng-team |
🟡
0/1
|
Denominator calculation
|
Contributor
Keep the static Linaria block and express font-family as `var(--cds-icon-font-family, 'CoinbaseIcons')`. The factory only sets the variable when a non-default font is bound, so consumers can override the icon font via className, inline style, or theme scope without a specificity battle. Default rendering is unchanged. Co-authored-by: Cursor <cursoragent@cursor.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 changed? Why?
The web and mobile
Iconcomponents hardcode a single icon source (@coinbase/cds-icons/glyphMap), a single font family ('CoinbaseIcons'), and a singlenametype (IconName). That makes it impossible to render an alternate icon set (e.g. a private, retail-specific style) without forking the whole component.This PR extracts the rendering logic into a
createIcon<Name>factory (mirroring the existingcreateIllustration<Variant>convention) that binds:GlyphMap<Name>, keys`${name}-${size}-${active}`),'CoinbaseIcons'), andName).The default
Iconbecomes a one-liner:So the public API and behavior are unchanged, while a consumer with their own icon package can do
createIcon<RetailIconName>({ glyphMap, fontFamily })and get a fully-typed icon component that reuses all CDS accessibility, theming, sizing, andcomponentConfigbehavior — no duplicated component logic.On web,
font-familymoved off the static Linariacssblock (which can't interpolate a runtime value) to an inline style on the glyph span; mobile already applied it via an inline style object.Root cause (required for bugfixes)
N/A — additive infrastructure.
UI changes
None. The default icon set, font, glyph keys, and sizing are identical, so rendering is unchanged.
Testing
How has it been tested?
Testing instructions
yarn nx run web:typecheckandyarn nx run mobile:typecheck— passyarn nx run web:test --testPathPattern="icons/"— pass (5 suites)yarn nx run mobile:test --testPathPattern="icons/"— passIllustrations/Icons Checklist
N/A — no files under
packages/icons/**orpackages/illustrations/**changed; no icon assets or names added.Change management
type=routine
risk=low
impact=sev5
automerge=false
Made with Cursor