Skip to content

refactor: modernize badge component to latest MD3 spec#5013

Merged
satya164 merged 8 commits into
callstack:mainfrom
MrMuzyk:refactor/modrnize-badge-component
Jun 25, 2026
Merged

refactor: modernize badge component to latest MD3 spec#5013
satya164 merged 8 commits into
callstack:mainfrom
MrMuzyk:refactor/modrnize-badge-component

Conversation

@MrMuzyk

@MrMuzyk MrMuzyk commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Motivation

Modernizes the Badge component to the latest MD3 spec by adopting theme tokens for shape, typography, and sizing.

Changes

  • Shape: borderRadius: size / 2cornerFull (9999) from src/theme/tokens/sys/shape
  • Typography: fontSize: size * 0.5 (8sp at default) → theme.fonts.labelSmall (11sp, letterSpacing 0.5, fontWeight 500)
  • Sizing: configurable size prop → fixed MD3 constants (6dp dot, 16dp pill)
  • Padding: paddingHorizontal: 3 → 4dp (MD3 spec)
  • Max width: unconstrained → 34dp max-width with overflow: hidden
  • Variant: now automatic — no children renders a 6dp dot, children renders a 16dp pill

Breaking change

The size prop has been removed.

// Before (v5)
<Badge size={6} />          // dot
<Badge size={20}>3</Badge>  // pill

// After (v6)
<Badge />        // dot — automatic
<Badge>3</Badge> // pill — automatic

Callsites updated

  • src/components/BottomNavigation/BottomNavigationBar.tsx
  • src/components/Drawer/DrawerCollapsedItem.tsx (+ removed unused badgeSize constant)
  • example/src/Examples/BadgeExample.tsx
  • example/src/DrawerItems.tsx

Related issue

#4974

Test plan

  • yarn typescript — clean
  • yarn lint — clean
  • yarn test — 737 passed (8 Badge tests: 4 snapshot + 4 behavioral)
  • Visual verification: dot badge renders as 6dp circle, pill badge at 16dp with correct typography, "999+" clips at 34dp

Adopt MD3 theme tokens for shape, typography, and sizing:
- cornerFull (9999) replaces borderRadius: size / 2
- theme.fonts.labelSmall replaces fontSize: size * 0.5 (11sp, letterSpacing 0.5, fontWeight 500)
- Fixed MD3 sizes: 6dp dot, 16dp pill, 4dp padding, 34dp max-width

BREAKING CHANGE: size prop removed. Variant is now automatic —
no children renders a 6dp dot, children renders a 16dp pill.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@MrMuzyk MrMuzyk changed the title refactor(badge): modernize to MD3 tokens, remove size prop refactor: modernize to badge component; MD3 tokens, remove size prop Jun 23, 2026
@MrMuzyk MrMuzyk changed the title refactor: modernize to badge component; MD3 tokens, remove size prop refactor: modernize badge component; MD3 tokens, remove size prop Jun 23, 2026
@MrMuzyk MrMuzyk changed the title refactor: modernize badge component; MD3 tokens, remove size prop refactor: modernize badge component to latest MD3 spec Jun 23, 2026
@MrMuzyk MrMuzyk marked this pull request as ready for review June 23, 2026 13:06

@matkoson matkoson left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

src/components/Badge.tsx:22 @MrMuzyk is removing 'size' a breaking change? can we keep it as deprecated?

generated by an automated pr-review pipe, not written by a human. reply and tag the repo owner if it got something wrong.

Comment thread src/components/Badge.tsx Outdated
Comment on lines 23 to 27
/**
* Size of the `Badge`.
* @deprecated Size is determined automatically by MD3 variant (6dp dot / 16dp pill).
* This prop is ignored and will be removed in a future major release.
*/
size?: number;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please remove the prop. This will be a major version and we don't want to keep legacy implementations.

Comment thread src/components/Badge.tsx Outdated
Comment thread src/components/Badge.tsx Outdated
const Badge = ({
children,
size = defaultSize,
size: _size,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What's the point of accepting this prop when it's not used

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

To avoid lint errors, it doesn't matter now anyway as we're scrapping it as originally planned

@MrMuzyk MrMuzyk force-pushed the refactor/modrnize-badge-component branch from 6d29f43 to d06ee25 Compare June 24, 2026 10:18

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Modernizes the Badge component to align with updated Material Design 3 behavior by switching to theme tokens for shape/typography and making the dot vs pill variant automatic based on whether children is provided.

Changes:

  • Refactors Badge sizing/shape/typography to fixed MD3-aligned constants and uses cornerFull + theme.fonts.labelSmall.
  • Removes the size prop and updates callsites to rely on automatic dot (no children) vs pill (with children) rendering.
  • Updates and expands badge tests and snapshots to cover the new sizing behavior and max-width clipping.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/components/Badge.tsx Implements MD3 sizing/typography/shape tokens and automatic dot vs pill behavior.
src/components/BottomNavigation/BottomNavigationBar.tsx Updates badge rendering to remove the removed size prop usage.
src/components/Drawer/DrawerCollapsedItem.tsx Updates badge rendering to remove the removed size prop usage and deletes a now-unused constant.
src/components/tests/Badge.test.tsx Removes size-prop test and adds behavioral tests for dot vs pill sizing and clipping.
src/components/tests/snapshots/Badge.test.tsx.snap Updates snapshots to match new MD3 badge styles.
src/components/tests/snapshots/BottomNavigation.test.tsx.snap Updates snapshots to match new badge rendering in BottomNavigation.
example/src/Examples/BadgeExample.tsx Updates example usage to rely on automatic dot vs pill behavior (no size prop).
example/src/DrawerItems.tsx Updates example callsites to remove the removed size prop usage.

Comment thread src/components/Badge.tsx Outdated
Comment on lines +35 to +37
* The bagde is styled differently based on whether `children` is passed:
* - Small dot when it doesn't have `children`
* - Larger pill when it has `children`
Comment thread src/components/Badge.tsx Outdated
Comment on lines +105 to +109
maxWidth: MAX_LARGE_WIDTH,
paddingHorizontal: LARGE_PADDING,
...labelFont,
lineHeight: LARGE_SIZE / fontScale,
}),
@satya164

Copy link
Copy Markdown
Member

the positioning seems off. in MD screenshots I see the badge is positioned lower, and the small dot is positioned too high in the implementation currently

the pill can also be wider - the guidelines say it should fit 4 characters, but the text is getting ellipsized currently

CleanShot 2026-06-24 at 12 53 18@2x

@MrMuzyk

MrMuzyk commented Jun 24, 2026

Copy link
Copy Markdown
Contributor Author

Got it, will have a look again and get back with fixed version and some screenshots

@MrMuzyk

MrMuzyk commented Jun 25, 2026

Copy link
Copy Markdown
Contributor Author

I've corrected the examples, this is how it looks right now

image

@MrMuzyk MrMuzyk requested a review from satya164 June 25, 2026 10:29

@satya164 satya164 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

thank!

@satya164 satya164 merged commit 641d956 into callstack:main Jun 25, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants