Skip to content

feat(badge): add recipe and tokens#31043

Open
thetaPC wants to merge 54 commits intoionic-modularfrom
FW-6837
Open

feat(badge): add recipe and tokens#31043
thetaPC wants to merge 54 commits intoionic-modularfrom
FW-6837

Conversation

@thetaPC
Copy link
Copy Markdown
Contributor

@thetaPC thetaPC commented Mar 27, 2026

Issue number: internal


What is the current behavior?

Component styles for ion-badge are fragmented across multiple files (ios, md). Developers were restricted to those themes and how those themes structured the logic and styles.

What is the new behavior?

  • Unified Style Architecture: Combined theme-specific styling into a single badge.scss file that consumes CSS variables, ensuring a single source of truth for component logic.
  • Defined TypeScript Interface: Added badge.interfaces.ts
  • Updated Test Page: Updated the badge test page to be simple since new test pages with more in depth use cases were created
  • Added Test Pages: Badge has multiple use cases based on which component it's slotted into. Test pages were added due to that.

Does this introduce a breaking change?

  • Yes
  • No

This PR introduces a breaking change to how IonBadge is styled. Existing manual CSS overrides targeting internal badge structures or old token names will no longer work due to the shift to thew new token hierarchy and a unified base SCSS file.

Migration Path:

  1. Token Updates: Update any custom theme configurations to match the new nested structure.

  2. CSS Overrides: Ensure selectors align with the new slotted element logic and variable names (e.g., --ion-badge-hue-bold-default-background).

--background should no longer be used. Setting the value, Badge.hue.bold.background, within the tokens file should be used to change the background for the bold hue. Setting the value, Badge.hue.subtle.background, within the tokens file should be used to change the background for the subtle hue.

  1. Theme classes: Remove any instances that target the theme classes: badge.md

Other information

This PR significantly improves the developer experience for theming. By moving logic into default.tokens.ts and away from hardcoded SCSS functions, designers and developers can now override styles (like the size on a slotted avatar) purely through token configuration.

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 27, 2026

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

Project Deployment Actions Updated (UTC)
ionic-framework Ready Ready Preview, Comment Apr 9, 2026 1:26am

Request Review

Comment on lines -59 to -61
:host ::slotted(ion-badge[vertical]:not(:empty)) {
@include globals.padding(2px);
}
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.

Removed this completely because based on MD3, the padding should always be consistent regardless of the host component.

},

// Sizes
size: {
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.

Sizes were based off the current size of next and MD3 designs. MD3 states that badge sizes do not change regardless of it being inside another component. So I decided to keep it simple and follow their approach. This can be found on their badge and tabs pages.

},

// Sizes
size: {
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.

MD3 states that badge sizes do not change regardless of it being inside another component. So I decided to keep it simple and follow their approach. This can be found on their badge and tabs pages.

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.

Avatar sizes have yet to be implemented.

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.

The default is now small so the snapshot was updated.

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.

I renamed the folder from hint to vertical.

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.

Moved this test to badge-size-rectangular since there was no need to split them into smaller tests. The same reason goes for the other shape snapshots that were "deleted".

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.

Moved this test to badge-size-large since there was no need to split them into smaller tests. The same reason goes for the other size snapshots that were "deleted".

Comment on lines +224 to +230
/**
* "-apple-system-body" on iOS never goes smaller than
* 14px according to https://developer.apple.com/design/human-interface-guidelines/typography#Specifications.
* However, we still keep the max() usage here for consistency
* with other components and in case "-apple-system-body" does
* go smaller than 14px in the future.
*/
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.

This comment lived in the ios theme file, I moved it over to keep record of it.

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.

Not sure why this keeps being persistent. I tried reverting it so it wouldn't bog down the PR but it's still here. I was able to revert the other browsers but not Firefox.

@thetaPC thetaPC marked this pull request as ready for review April 9, 2026 02:21
@thetaPC thetaPC requested a review from a team as a code owner April 9, 2026 02:21
@thetaPC thetaPC requested review from brandyscarney and gnbm and removed request for gnbm April 9, 2026 02:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

package: core @ionic/core package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant