Skip to content

Conversation

blunteshwar
Copy link
Contributor

@blunteshwar blunteshwar commented Aug 4, 2025

Overview

This PR refactors the sp-alert-banner 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/alert-banner/src/AlertBannerBase.ts as the base class for AlertBanner component.

Code Separation

AlertBannerBase (Abstract Base Class)

  • Location: packages/alert-banner/src/AlertBannerBase.ts
  • Contains:
    • Property declarations (open, dismissible, variant)
    • All base functionality except rendering
    • Event handling (shouldClose, close, handleKeydown)
    • Variant validation logic
    • Abstract renderIcon method for subclasses to implement

AlertBanner (Concrete Class)

  • Location: packages/alert-banner/src/AlertBanner.ts
  • Contains:
    • Class that extends AlertBannerBase
    • Rendering logic (render() method)
    • Icon rendering implementation (renderIcon() 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 { AlertBanner } from '@spectrum-web-components/alert-banner' still works
  • All existing component usage remains valid

Related issue(s)

  • fixes [SWC-978]

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

@blunteshwar blunteshwar requested a review from a team as a code owner August 4, 2025 06:10
Copy link

changeset-bot bot commented Aug 4, 2025

⚠️ No Changeset found

Latest commit: 2cf0b5b

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

Copy link
Contributor

github-actions bot commented Aug 4, 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-5664

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
Contributor

github-actions bot commented Aug 4, 2025

Tachometer results

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

@Rajdeepc Rajdeepc changed the title chore(alert-banner): refactor AlertBanner to extend AlertBannerBase a… chore(alert-banner): refactor AlertBanner to extend AlertBannerBase Aug 4, 2025
Copy link
Contributor

@Rajdeepc Rajdeepc left a comment

Choose a reason for hiding this comment

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

This change introduces a breaking update by removing exports from AlertBanner.ts and moving them solely to AlertBanner.base.ts. While I agree that consolidating types into a dedicated type definition file is our right long-term approach, we should ensure backward compatibility in the interim.

To avoid disruption for existing consumers, please add re-exports in AlertBanner.ts. The types should continue to be defined in the base file, but re-exported from the original entry point until we can clean this up more formally.

@@ -12,7 +12,7 @@

import { html, TemplateResult } from '@spectrum-web-components/base';

import { AlertBannerVariants } from '@spectrum-web-components/alert-banner';
import { AlertBannerVariants } from '@spectrum-web-components/alert-banner/src/AlertBanner.base.js';
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not needed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -11,7 +11,7 @@
*/

import { html, TemplateResult } from '@spectrum-web-components/base';
import { AlertBannerVariants } from '@spectrum-web-components/alert-banner';
import { AlertBannerVariants } from '@spectrum-web-components/alert-banner/src/AlertBanner.base.js';
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not needed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -10,3 +10,4 @@
* governing permissions and limitations under the License.
*/
export * from './AlertBanner.js';
export * from './AlertBanner.base.js';
Copy link
Contributor

@Rajdeepc Rajdeepc Aug 4, 2025

Choose a reason for hiding this comment

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

No need to export base from here.

import '@spectrum-web-components/button/sp-close-button.js';
import '@spectrum-web-components/icons-workflow/icons/sp-icon-alert.js';
import '@spectrum-web-components/icons-workflow/icons/sp-icon-info.js';
import styles from './alert-banner.css.js';

const VALID_VARIANTS = ['neutral', 'info', 'negative'];
export type AlertBannerVariants = (typeof VALID_VARIANTS)[number];
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add the re-export pattern in AlertBanner.ts? Type should be defined in base but re-exported for backward compatibility so existing consumers don't break.

  import type { AlertBannerVariants } from './AlertBanner.base.js';
   export type { AlertBannerVariants };

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

@blunteshwar blunteshwar requested a review from Rajdeepc August 4, 2025 10:27
@blunteshwar blunteshwar merged commit 381d304 into spectrum-two-phase-zero Aug 5, 2025
21 checks passed
@blunteshwar blunteshwar deleted the pvashish/alert-banner branch August 5, 2025 11:21
marissahuysentruyt pushed a commit that referenced this pull request Aug 20, 2025
…5664)

* chore(alert-banner): refactor AlertBanner to extend AlertBannerBase and add variant handling

* chore(alert-banner): export AlertBannerBase and update imports in stories

* chore(alert-banner): minor fix

* chore(alert-banner): minor fix

* chore(alert-banner): minor fix

* chore(alert-banner): update import paths for AlertBannerVariants
marissahuysentruyt pushed a commit that referenced this pull request Aug 20, 2025
…5664)

* chore(alert-banner): refactor AlertBanner to extend AlertBannerBase and add variant handling

* chore(alert-banner): export AlertBannerBase and update imports in stories

* chore(alert-banner): minor fix

* chore(alert-banner): minor fix

* chore(alert-banner): minor fix

* chore(alert-banner): update import paths for AlertBannerVariants
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.

2 participants