Skip to content

chore(divider): refactor with abstracted base class #5639

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

Merged
merged 7 commits into from
Aug 8, 2025

Conversation

Rajdeepc
Copy link
Contributor

@Rajdeepc Rajdeepc commented Jul 28, 2025

Overview

This PR refactors the sp-divider 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

  • Renamed: packages/divider/src/Divider.ts → packages/divider/src/Divider.base.ts (using git mv)
  • Created: New packages/divider/src/Divider.ts with rendering logic only

Code Separation

DividerBase (Abstract Base Class)

  • Location: packages/divider/src/Divider.base.ts
  • Contains:
    • Property declarations (vertical)
    • Lifecycle methods (firstUpdated, updated)
    • Behavioral logic (ARIA attribute management)
    • All base functionality except rendering

Divider (Concrete Class)

  • Location: packages/divider/src/Divider.ts
  • Contains:
    • Class that extends DividerBase
    • Rendering logic (render() method)
    • Styles import and declaration

Technical Implementation

Before

export class Divider extends SizedMixin(SpectrumElement, {
    validSizes: ['s', 'm', 'l'],
    noDefaultSize: true,
}) {
    public static override styles: CSSResultArray = [styles];
    @property({ type: Boolean, reflect: true })
    public vertical = false;
    
    protected override render(): TemplateResult {
        return html``;
    }
    
    protected override firstUpdated(changed: PropertyValues<this>): void {
        // ... logic
    }
    
    protected override updated(changed: PropertyValues<this>): void {
        // ... logic
    }
}

After

// Divider.base.ts
export abstract class DividerBase extends SizedMixin(SpectrumElement, {
    validSizes: ['s', 'm', 'l'],
    noDefaultSize: true,
}) {
    @property({ type: Boolean, reflect: true })
    public vertical = false;
    
    protected override firstUpdated(changed: PropertyValues<this>): void {
        // ... logic
    }
    
    protected override updated(changed: PropertyValues<this>): void {
        // ... logic
    }
}

// Divider.ts
export class Divider extends DividerBase {
    public static override styles: CSSResultArray = [styles];
    
    protected override render(): TemplateResult {
        return html``;
    }
}

Impact

Customer Impact

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

Developer Impact

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

Related issue(s)

  • fixes 979

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 divider component for future migration to the Swan architecture by:

  1. Separating concerns - Base logic vs. rendering logic
  2. Preserving git history - Base logic in Divider.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

Copy link

changeset-bot bot commented Jul 28, 2025

⚠️ No Changeset found

Latest commit: 0e470ff

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

@Rajdeepc Rajdeepc self-assigned this Jul 28, 2025
Copy link

github-actions bot commented Jul 28, 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-5639

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...

@Rajdeepc Rajdeepc marked this pull request as ready for review July 30, 2025 08:12
@Rajdeepc Rajdeepc requested a review from a team as a code owner July 30, 2025 08:12
@TarunAdobe
Copy link
Contributor

do we not have to add the newly added Divider.Base.ts to exports in package.json?

"exports": {
      ....
      "./src/Divider.base.js": {
          "development": "./src/Divider.base.dev.js",
          "default": "./src/Divider.base.js"
      },
      ....
 }

@nikkimk nikkimk changed the base branch from main to spectrum-two-phase-zero July 30, 2025 21:23
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.

Lonely ghost terminates matchmaker (LGTM)

@Rajdeepc Rajdeepc changed the title feat(divider): extract base logic with new rendering module chore(divider): refactor with abstracted base class Aug 4, 2025
@Rajdeepc Rajdeepc merged commit 12ec0b7 into spectrum-two-phase-zero Aug 8, 2025
21 checks passed
@Rajdeepc Rajdeepc deleted the rajdeep/divider-base-refactor branch August 8, 2025 14:07
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