Banner: Fix types to restrict leadingVisual to variants info and upsell#8151
Banner: Fix types to restrict leadingVisual to variants info and upsell#8151siddharthkp wants to merge 7 commits into
Conversation
🦋 Changeset detectedLatest commit: 9f72c79 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
There was a problem hiding this comment.
Pull request overview
This PR aligns @primer/react’s Banner TypeScript API with its existing runtime behavior by restricting custom visuals (leadingVisual and deprecated icon) to the info and upsell variants.
Changes:
- Refactored
BannerPropsinto a discriminated union soleadingVisual/iconare only accepted forinfo/upsell. - Updated unit tests and Storybook/Figma examples to comply with the new type restrictions (including
@ts-expect-errorcases to validate runtime fallback). - Added a changeset documenting the breaking type change.
Show a summary per file
| File | Description |
|---|---|
| packages/react/src/Banner/Banner.tsx | Converts BannerProps to a discriminated union restricting custom visuals to info/upsell. |
| packages/react/src/Banner/Banner.test.tsx | Adds @ts-expect-error coverage for disallowed prop combinations while asserting runtime fallback behavior. |
| packages/react/src/Banner/Banner.stories.tsx | Adjusts Playground rendering to only pass leadingVisual for info/upsell to satisfy the new types. |
| packages/react/src/Banner/Banner.figma.tsx | Updates Figma code-connect example to conditionally pass icon only for supported variants. |
| .changeset/banner-leading-visual-types.md | Adds a changeset for the type-surface change (currently marked as major). |
Review details
- Files reviewed: 5/5 changed files
- Comments generated: 1
- Review effort level: Low
| --- | ||
| '@primer/react': major | ||
| --- | ||
|
|
||
| Banner: Restrict custom leading visuals to the info and upsell variants No newline at end of file |
|
Integration test results from github/github-ui PR:
All checks passed! |
Summary
The
leadingVisualand deprecatediconprops onBannerare only rendered whenvariantisinfoorupsell. For every other variant (critical,success,warning), the Banner ignores a custom visual and always renders its built-in variant icon.Until now the types allowed
leadingVisual/iconto be passed alongside anyvariant, so this compiled even though it does nothing at runtime:This PR narrows
BannerPropsinto a discriminated union so custom visuals are only accepted for the variants that actually render them. The type surface now matches the runtime behavior.Rollout strategy
Merge checklist