Skip to content
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

refactor(card): clarify component's slot API #4938

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

mizgaionutalexandru
Copy link
Contributor

@mizgaionutalexandru mizgaionutalexandru commented Nov 18, 2024

Description

This PR addresses APIs misunderstandings regarding the sp-card component's slots. Previously used slots preview and cover-photo are now merged into a single one named image. The styles are applied exactly as before, based on the variant and horizontal properties, through using the according id that maps to spectrum CSS styles.
Also, now the quiet variant is included in the style overrides, and a new --mod-* CSS variable was added to allow consumers to reliably obtain the desired behaviour (the added story reflects the usage of this token).
Some CSS was also changed to remove deprecated overrides and improve readability.

Related issue(s)

  • N/A

Motivation and context

  1. The component public API states that the cover-photo slot should be used with the quiet variant. The consumer should not need to determine which slot to use with each variant.
  2. Spectrum-CSS uses preview with the quiet variant
  3. SWC's code examples use preview with the quiet variant
  4. The component, while placing the user in a position to make the correct decision about what slot to use with a specific variant, allows for both slots to be used at the same time but doesn't display the cover-photo anyway
  5. Looks like the quiet variant was included in the width: 100% at a previous point in time but the change to not include it anymore wasn't documented too much. There is a need to come back to the previous behaviour (to include the quiet variant in the full width CSS). It seems like a --mod-* is the best common ground to allow consumers all behaviours related to using an image and how to position it inside the asset, be that cover, contain, scale-down etc. (discussion context)

How has this been tested?

No functional changes were added. All the slots usage in the project have been updated. This being said, all unit tests should pass and VRTs should show changes only for the quiet variant's initial width. A new story was added to reflect the usage of the newly added token.

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Chore (minor updates related to the tooling or maintenance of the repository, does not impact compiled assets)

Checklist

  • I have signed the Adobe Open Source CLA.
  • My code follows the code style of this project.
  • If my change required a change to the documentation, I have updated the documentation in this pull request.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • I have reviewed at the Accessibility Practices for this feature, see: Aria Practices

Best practices

This repository uses conventional commit syntax for each commit message; note that the GitHub UI does not use this by default so be cautious when accepting suggested changes. Avoid the "Update branch" button on the pull request and opt instead for rebasing your branch against main.

Copy link

Branch preview

Review the following VRT differences

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

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

github-actions bot commented Nov 18, 2024

Lighthouse scores

Category Latest (report) Main (report) Branch (report)
Performance 0.99 1 0.97
Accessibility 1 1 1
Best Practices 1 1 1
SEO 1 0.92 0.92
PWA 1 1 1
What is this?

Lighthouse scores comparing the documentation site built from the PR ("Branch") to that of the production documentation site ("Latest") and the build currently on main ("Main"). Higher scores are better, but note that the SEO scores on Netlify URLs are artifically constrained to 0.92.

Transfer Size

Category Latest Main Branch
Total 250.341 kB 236.685 kB 🏆 236.731 kB
Scripts 60.341 kB 54.088 kB 🏆 54.30 kB
Stylesheet 53.809 kB 48.161 kB 48.005 kB 🏆
Document 6.227 kB 5.459 kB 🏆 5.465 kB
Font 127.008 kB 126.63 kB 126.613 kB 🏆

Request Count

Category Latest Main Branch
Total 52 52 52
Scripts 41 41 41
Stylesheet 5 5 5
Document 1 1 1
Font 2 2 2

@coveralls
Copy link
Collaborator

coveralls commented Nov 18, 2024

Pull Request Test Coverage Report for Build 12648533469

Details

  • 39 of 39 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.009%) to 98.215%

Totals Coverage Status
Change from base Build 12278981558: 0.009%
Covered Lines: 32987
Relevant Lines: 33409

💛 - Coveralls

Copy link

github-actions bot commented Nov 18, 2024

Tachometer results

Chrome

card permalink

test-basic

Version Bytes Avg Time vs remote vs branch
npm latest 781 kB 36.71ms - 37.80ms - faster ✔
5% - 9%
1.92ms - 3.63ms
branch 758 kB 39.37ms - 40.69ms slower ❌
5% - 10%
1.92ms - 3.63ms
-

grid permalink

basic-test

Version Bytes Avg Time vs remote vs branch
npm latest 716 kB 43.62ms - 44.68ms - unsure 🔍
-1% - +4%
-0.26ms - +1.54ms
branch 674 kB 42.78ms - 44.23ms unsure 🔍
-3% - +1%
-1.54ms - +0.26ms
-

icons permalink

test-basic

Version Bytes Avg Time vs remote vs branch
npm latest 628 kB 31.14ms - 31.50ms - faster ✔
1% - 3%
0.41ms - 0.98ms
branch 607 kB 31.80ms - 32.24ms slower ❌
1% - 3%
0.41ms - 0.98ms
-
Firefox

card permalink

test-basic

Version Bytes Avg Time vs remote vs branch
npm latest 781 kB 72.92ms - 78.08ms - faster ✔
3% - 11%
2.03ms - 9.25ms
branch 758 kB 78.63ms - 83.65ms slower ❌
3% - 12%
2.03ms - 9.25ms
-

grid permalink

basic-test

Version Bytes Avg Time vs remote vs branch
npm latest 716 kB 88.48ms - 95.96ms - slower ❌
0% - 12%
0.21ms - 10.15ms
branch 674 kB 83.77ms - 90.31ms faster ✔
0% - 11%
0.21ms - 10.15ms
-

icons permalink

test-basic

Version Bytes Avg Time vs remote vs branch
npm latest 628 kB 55.95ms - 60.25ms - unsure 🔍
-2% - +6%
-1.37ms - +3.25ms
branch 607 kB 56.31ms - 58.01ms unsure 🔍
-6% - +2%
-3.25ms - +1.37ms
-

:host(:not([variant='quiet'])) #preview ::slotted(*) {
width: 100%;
#preview ::slotted(*) {
inline-size: 100%;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should include the quiet variant as per spectrum-css.

@mizgaionutalexandru mizgaionutalexandru changed the title [DRAFT] Imizga/sp card img refactor(card): clarify component's slot API Nov 19, 2024
@mizgaionutalexandru mizgaionutalexandru marked this pull request as ready for review November 20, 2024 11:24
@mizgaionutalexandru mizgaionutalexandru requested a review from a team as a code owner November 20, 2024 11:24
@Rajdeepc
Copy link
Contributor

This will become a breaking change! Will bring this up in our office hours!

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.

We need to create a section called BREAKING CHANGE to surface up this change to the consumers. Let's talk in the office hours and get some more opinions from other product teams. I feel there is a lot of usage of the Card and the asset components in multiple products.

import '@spectrum-web-components/checkbox/sp-checkbox.js';
import '@spectrum-web-components/popover/sp-popover.js';
import { Checkbox } from '@spectrum-web-components/checkbox/src/Checkbox';
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
import { Checkbox } from '@spectrum-web-components/checkbox/src/Checkbox';
import { Checkbox } from '@spectrum-web-components/checkbox';


/**
* @element sp-card
*
* @fires change - Announces a change in the `selected` property of a card
* @slot preview - This is the preview image for Gallery Cards
* @slot cover-photo - This is the cover photo for Default and Quiet Cards
* @slot image - This is the image of the card
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* @slot image - This is the image of the card
* @slot image - Image content

@@ -207,7 +204,7 @@ export class Card extends LikeAnchor(
this.addEventListener('pointercancel', handleEnd);
}

protected get renderHeading(): TemplateResult {
protected renderHeading(): TemplateResult {
Copy link
Contributor

Choose a reason for hiding this comment

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

I dont see any computation logic here so why change to a callable function instead of keeping it as a getter?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the naming fits a method better than a getter due to the fact that it contains a verb. Would you prefer another naming pattern?

Copy link

changeset-bot bot commented Jan 7, 2025

⚠️ No Changeset found

Latest commit: bf8320b

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.

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

@rubencarvalho
Copy link
Collaborator

Thank you for your contribution here! I’m fully on board with this proposal. Just one thing: we’ve been following a practice of providing a migration period where we log developer warnings to inform users and allow them time to migrate while maintaining backward compatibility.
Could we log a descriptive message recommending the new image slot approach while still keeping the existing cover-photo and preview slots for now? We could then follow up with another PR to remove all deprecated functionality and tests. This intermediary step has proven to be very useful in the past :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants