Skip to content

feat(Icon): accept namespaced extension keys from the icon prop - #5475

Closed
cixzhang wants to merge 2 commits into
mainfrom
icon-namespaced-prop
Closed

cixzhang wants to merge 2 commits into
mainfrom
icon-namespaced-prop

Conversation

@cixzhang

Copy link
Copy Markdown
Contributor

Component-scoped icons should be themeable without growing the shared IconName union — the ruling on #5466. The registry already resolved namespaced keys; the surfaces a component actually writes did not accept them, so the union was the only route that kept size/color/xstyle. This is that route.

What

<Icon icon>, useIcon, and defineTheme({icons}) now take a namespaced key as well as a built-in name:

<Icon icon="numberInput:stepperDown" size="xsm" />

defineTheme({
  name: 'brand',
  icons: {
    chevronDown: <ChevronDownIcon />,
    'numberInput:stepperDown': <CaretDownFilledIcon />,
  },
});

defaultIcons may carry a namespaced entry, so a component ships its own fallback where every other default lives.

Why not widen IconName

IconRegistry is Record<IconName, ReactNode>, so each new member adds a required key to every downstream registry — a CLI-scaffolded theme stops compiling on a patch bump. A namespaced key costs no permanent union surface and no precedent for the 13 other components sharing chevronDown.

Not any string

The new type is `${string}:${string}`, not ExtendedIconName. A misspelled built-in name is still a compile error — there's a @ts-expect-error test holding that.

Risk

Additive: three parameter types widen, which is non-breaking. getIconRegistry() still returns built-in names only — it now skips namespaced keys explicitly instead of relying on none existing, which is what makes a namespaced default in defaultIcons safe.

Testing

  • tsc --noEmit clean on @astryxdesign/core (3 pre-existing locales/pseudo.json errors aside).
  • Negative check: reverting only the prop widening makes the three new tests fail to compile — Type '"numberInput:stepperDown"' is not assignable to type 'IconName | IconType' at each call site. The tests are the type assertion.
  • vitest run packages/core packages/richtext — 7,901 passed. Two failures (SideNav focus, Table.perf) are load-sensitive; both pass in isolation and neither touches this code.
  • eslint clean on changed files.

A glyph owned by one component or library gets a namespaced key
(numberInput:stepperDown, richtext:bold) rather than a new member of the
shared IconName union: adding to the union makes every downstream
IconRegistry grow a required key, so a scaffolded theme stops compiling
on a patch bump.

The registry already resolved those keys; the prop, the hook and
defineTheme did not accept them, so the only way to keep Icon's size,
color and xstyle was to widen the union. They accept them now.
getIconRegistry() still returns built-in names only.
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Aug 25, 2026
@vercel

vercel Bot commented Aug 25, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
astryx Ready Ready Preview Aug 26, 2026 5:05pm

Request Review

@github-actions

github-actions Bot commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

🧪 Sandbox Preview

View Sandbox for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

Modified Components

Icon (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 576 -
Complexity N/A High (30) -

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@astryxdesign/core N/A 4.8KB 1.2KB

Accessibility Audit

Status: 1 accessibility violation(s) found — 1 serious.

Icon - 1 issue(s)
  • 🟠 serious: Ensure the contrast between foreground and background colors meets WCAG 2 AA minimum contrast ratio thresholds
    • Rule: color-contrast · Affects 1/18 stories · Learn more
    • WCAG: 1.4.3 (Level AA)

Visual Regression

Status: No visual change across 2 compared shot(s). 34 shot(s) have no baseline yet and were not compared.


Generated by PR Enrichment workflow | Storybook | Sandbox | View full report

@cixzhang

Copy link
Copy Markdown
Contributor Author

Closing because this solves a different problem from the one we need. Namespaced registry keys make app-owned React glyphs typed, but they neither accept URL-backed SVG assets nor tint those external documents. We should design around the URL-backed asset contract rather than land a second Icon extension that leaves it untouched.

@cixzhang cixzhang closed this Aug 27, 2026
@github-actions
github-actions Bot deleted the icon-namespaced-prop branch August 27, 2026 09:11

This branch was successfully deployed

1 active deployment
Preview — 4029a9e4 Deployed Aug 26, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant