Skip to content

chore(badge): refactor with abstracted base class #5648

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: spectrum-two-phase-zero
Choose a base branch
from

Conversation

TarunAdobe
Copy link
Contributor

@TarunAdobe TarunAdobe commented Jul 30, 2025

Overview

This PR refactors the sp-badge component to separate its base logic from rendering code, following the technical specifications for the Swan migration preparation. This is a purely internal change with no customer impact.

Changes Made

File Structure Changes

  • Created: New packages/badge/src/Badge.base.ts as the base class for Badge component.

Code Separation

BadgeBase (Abstract Base Class)

  • Location: packages/badge/src/Badge.base.ts
  • Contains:
    • Property declarations
    • All base functionality except rendering

Badge (Concrete Class)

  • Location: packages/badge/src/Badge.ts
  • Contains:
    • Class that extends BadgeBase
    • Rendering logic (render() method)
    • Styles import and declaration

Impact

Customer Impact

  • None - This is a purely internal refactoring
  • Public API remains identical
  • No visual or behavioural changes
  • No breaking changes

Developer Impact

  • None - Existing imports and usage patterns continue to work
  • import { Badge } from '@spectrum-web-components/badge' still works
  • All existing component usage remains valid

Related issue(s)

  • fixes 981

Screenshots (if appropriate)


Author's checklist

  • I have read the CONTRIBUTING and PULL_REQUESTS documents.
  • I have reviewed at the Accessibility Practices for this feature, see: Aria Practices
  • I have added automated tests to cover my changes.
  • I have included a well-written changeset if my change needs to be published.
  • I have included updated documentation if my change required it.

Reviewer's checklist

  • Includes a Github Issue with appropriate flag or Jira ticket number without a link
  • Includes thoughtfully written changeset if changes suggested include patch, minor, or major features
  • Automated tests cover all use cases and follow best practices for writing
  • Validated on all supported browsers
  • All VRTs are approved before the author can update Golden Hash

Manual review test cases

  • Manual Testing

    • Component renders correctly in Storybook
    • All variants (horizontal/vertical) work as expected
    • All sizes (s, m, l) display properly
    • ARIA attributes are set correctly
  • Automated Testing

    • All existing tests pass
    • No new tests needed (no functional changes)

Device review

  • Did it pass in Desktop?
  • Did it pass in (emulated) Mobile?
  • Did it pass in (emulated) iPad?

Migration Preparation

This refactoring prepares the badge component for future migration to the Swan architecture by:

  1. Separating concerns - Base logic vs. rendering logic
  2. Preserving git history - Base logic in Badge.base.ts will carry forward
  3. Maintaining compatibility - Public API unchanged
  4. Following established patterns - Consistent with other component refactoring

Related

  • Epic: Swan Migration Preparation - Component Refactoring
  • Technical Notes: Follows specified refactoring process for base logic extraction

@TarunAdobe TarunAdobe requested a review from a team as a code owner July 30, 2025 09:34
Copy link

changeset-bot bot commented Jul 30, 2025

⚠️ No Changeset found

Latest commit: 6fba948

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@TarunAdobe TarunAdobe force-pushed the ttomar/badge-refractor branch from 1657c9f to 7f38617 Compare July 30, 2025 13:34
Copy link

github-actions bot commented Jul 30, 2025

📚 Branch Preview

🔍 Visual Regression Test Results

When a visual regression test fails (or has previously failed while working on this branch), its results can be found in the following URLs:

Deployed to Azure Blob Storage: pr-5648

If the changes are expected, update the current_golden_images_cache hash in the circleci config to accept the new images. Instructions are included in that file.
If the changes are unexpected, you can investigate the cause of the differences and update the code accordingly.

Copy link

Tachometer results

Currently, no packages are changed by this PR...

blunteshwar
blunteshwar previously approved these changes Jul 30, 2025
Copy link
Contributor

@blunteshwar blunteshwar left a comment

Choose a reason for hiding this comment

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

Can you resolve at the failing tests for badge

@blunteshwar blunteshwar dismissed their stale review July 30, 2025 13:49

The tests were failing for badge

Copy link
Contributor

@blunteshwar blunteshwar left a comment

Choose a reason for hiding this comment

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

Can you resolve at the failing tests for badge

Copy link
Contributor

@nikkimk nikkimk left a comment

Choose a reason for hiding this comment

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

Nice work, including the PR description (which I totally copied for my component btw). Left two suggestion that will fix your tests, if you commit them.

@nikkimk nikkimk changed the base branch from main to spectrum-two-phase-zero July 30, 2025 21:24
@TarunAdobe TarunAdobe force-pushed the ttomar/badge-refractor branch from 7f38617 to 6fba948 Compare July 31, 2025 09:04
Copy link
Contributor

@nikkimk nikkimk left a comment

Choose a reason for hiding this comment

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

Lost gold treasure map (LGTM)

Comment on lines +28 to +30
"./src/Badge.base.js": {
"default": "./src/Badge.base.js",
"development": "./src/Badge.base.dev.js"
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't need to add this now as this would change the existing API contract.

@Rajdeepc Rajdeepc changed the title chore(badge): abstract base class logic chore(badge): refactor with abstracted base class Aug 4, 2025
Copy link
Contributor

@blunteshwar blunteshwar left a comment

Choose a reason for hiding this comment

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

Shouldn't we add export * from './Badge.base.js'; in index.ts file as well so that we could use/import objects exported by BadgeBase in stories and tests.

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