Skip to content

feat: icon provider custom icons#4352

Merged
pan-kot merged 2 commits intocloudscape-design:mainfrom
bmv437:feature/custom-icons
Mar 19, 2026
Merged

feat: icon provider custom icons#4352
pan-kot merged 2 commits intocloudscape-design:mainfrom
bmv437:feature/custom-icons

Conversation

@bmv437
Copy link
Contributor

@bmv437 bmv437 commented Mar 12, 2026

Description

Adds custom icon support to IconProvider, allowing consumers to register arbitrary icon names (beyond the built-in set) and use them across all Cloudscape components that accept icon names.

Notable changes:

  • IconRegistry / IconMap types — Consumers use TypeScript module augmentation (declare module) to register custom icon names, making them type-safe across Icon, Button, and all other icon-accepting components.
  • defineIcons helper — A type-identity function that lets consumers define a custom icon map (defineIcons({ rocket: <RocketSvg /> })).
  • Single source of truth for icon names — The duplicated IconProps.Name union type is replaced by a shared IconName type defined in icon-provider/interfaces.ts. IconProviderProps.Icons is now a mapped type over IconName instead of a hand-maintained interface with ~130 explicit keys. This is now possible due to this update to documenter.
  • Runtime handlingInternalIcon renders custom icons from context and warns when a name isn't found. Nested IconProviders inherit custom icons from parent context, and null values correctly fall back to either the built-in default or the inherited custom icon.
  • ExportsdefineIcons, IconRegistry, and IconMap are exported from icon-provider/index.tsx.

API proposal: oY6SACNg4aOu

How has this been tested?

  • Unit tests (src/icon-provider/__tests__/define-icons.test.ts): Validates that defineIcons returns the same object reference and accepts built-in, custom, and mixed icon keys.
  • Unit tests (src/icon-provider/__tests__/icon-provider.test.tsx): New test cases for rendering custom icons through context, inheriting across nested providers, null-reset fallback behavior, and console warnings for missing icons.
  • Integration tests (src/icon-provider/__integ__/custom-icons.test.ts): Browser tests verifying custom icon rendering in Icon and Button, built-in icon coexistence, nested provider inheritance, and null-reset behavior.
  • Demo page (pages/icon-provider/custom-icons/): Visual test page exercising all scenarios with a separate tsconfig.json to isolate module augmentation.
Review checklist

The following items are to be evaluated by the author(s) and the reviewer(s).

Correctness

  • Changes include appropriate documentation updates.
  • Changes are backward-compatible if not indicated, see CONTRIBUTING.md.
  • Changes do not include unsupported browser features, see CONTRIBUTING.md.
  • Changes were manually tested for accessibility, see accessibility guidelines.

Security

Testing

  • Changes are covered with new/existing unit tests?
  • Changes are covered with new/existing integration tests?

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@bmv437 bmv437 requested a review from a team as a code owner March 12, 2026 18:10
@bmv437 bmv437 requested review from pan-kot and removed request for a team March 12, 2026 18:10
@bmv437 bmv437 changed the title Icon provider custom icons feat: icon provider custom icons Mar 12, 2026

export default function CustomIconsPage() {
return (
<article>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: You can use SimplePage helper for this page instead. Passing screenshotArea={{}} to it will enable the internal screenshot area for it, too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

@@ -0,0 +1,8 @@
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good thinking 👍

expect(firstIcon).toStrictEqual(expectedSvg);
expect(secondIcon).toStrictEqual(expectedSvg);
});
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we add tests for the following cases:

  1. Custom icon is defined using provider and is then overridden with a nested provider
  2. Custom icon override behaviour when passing { rocket: undefined } to the nested provider

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added.

expect(icons).toHaveProperty('close');
});

it('accepts arbitrary string keys', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this test for, isn't it captured by e.g. the first one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I simplified/reworked this, and added a type assertion test to validate the object keys would return from defineIcons as exact values, are weren't widened to string.

expect(icons).toHaveProperty('zap');
});

it('accepts a mix of built-in and custom keys', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it not the same as first?

}
}

function setupTest(testFn: (page: CustomIconsPage) => Promise<void>) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these tests are not really needed, because:

  1. The logic can be and is tested by the unit tests
  2. We will provide an internal screenshot test to capture the actual render output of the page - it will capture the presence of the icons and also the way they render, which can include colour inheritance and size variants, once supported.

@bmv437 bmv437 force-pushed the feature/custom-icons branch from cb286be to 8f032c4 Compare March 13, 2026 21:53
@codecov
Copy link

codecov bot commented Mar 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.44%. Comparing base (7d1f303) to head (8f032c4).
⚠️ Report is 11 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4352   +/-   ##
=======================================
  Coverage   97.44%   97.44%           
=======================================
  Files         897      901    +4     
  Lines       26397    26422   +25     
  Branches     9527     9523    -4     
=======================================
+ Hits        25723    25748   +25     
  Misses        631      631           
  Partials       43       43           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@pan-kot pan-kot added this pull request to the merge queue Mar 19, 2026
Merged via the queue into cloudscape-design:main with commit 3ea9572 Mar 19, 2026
83 of 85 checks passed
amanabiy pushed a commit that referenced this pull request Mar 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants