Skip to content

Conversation

@TarunAdobe
Copy link
Contributor

@TarunAdobe TarunAdobe commented Nov 6, 2025

Description

This PR migrates the next-gen Asset component to Spectrum 2 styles and updates Storybook accordingly.

Motivation and context

This PR migrates the Asset component from first-gen to the second-gen architecture, following the established pattern of separating core component logic from Spectrum-specific implementation.

Changes:

  • Migrated CSS to align with Spectrum CSS structure

What changed

First-gen:

  • first-gen/packages/asset/src/Asset.ts - Remains unchanged for backward compatibility

Core (Base):

  • second-gen/packages/core/components/asset/Asset.base.ts - Updates shared functionalities
  • second-gen/packages/core/components/asset/Asset.types.ts - Creates types file for size and static color variants
  • second-gen/packages/core/components/asset/index.ts - Imports and exports types

Second-gen:

  • second-gen/packages/swc/components/asset/Asset.ts - Updates render method to accommodate classes
  • second-gen/packages/swc/components/asset/asset.css - Adds CSS from spectrum-css
  • second-gen/packages/swc/components/asset/stories/asset.stories.ts - Adds comprehensive story coverage

Related issue(s)

  • SWC-1261

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 (Note: I did not add a changeset, I wasn't sure that this was set up for barebones and didn't see any for progress circle or badge, but I'm happy to add one if I'm mistaken!)
  • 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

Run second-gen Storybook:

yarn workspace @swc/components storybook

Storybook functionality:

  • All controls work correctly on Default story

Documentation:

  • All stories render correctly on Docs page
  • Story descriptions are clear and informative

First-gen verification (use the PR preview or run locally):

yarn start
# or
yarn docs:start
  • First-gen Asset remains unchanged and functional

Code review checklist:

  • TypeScript types are correct and properly exported
  • CSS follows second-gen patterns
  • No linter errors
  • Proper separation of concerns between core and SWC packages

Device review

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

@changeset-bot
Copy link

changeset-bot bot commented Nov 6, 2025

⚠️ No Changeset found

Latest commit: 1b8d3f0

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

@github-actions
Copy link
Contributor

github-actions bot commented Nov 6, 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-5858

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.

@TarunAdobe TarunAdobe force-pushed the ttomar/asset-migration branch 3 times, most recently from 8500305 to e550a7e Compare November 6, 2025 11:07
@TarunAdobe TarunAdobe force-pushed the ttomar/asset-migration branch from e550a7e to 58474d7 Compare November 6, 2025 11:13
@TarunAdobe TarunAdobe marked this pull request as ready for review November 6, 2025 13:54
@TarunAdobe TarunAdobe requested a review from a team as a code owner November 6, 2025 13:54
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.

Good start!

}

::slotted(*) {
.spectrum-Asset-image {
Copy link
Contributor

@Rajdeepc Rajdeepc Nov 11, 2025

Choose a reason for hiding this comment

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

This is a breaking change for the existing behaviour if consumers are slotting an <img> without class.
You can keep this class with a migration shim.

::slotted() { /* same rules */ }
.spectrum-Asset-image { /* same rules */ }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

but can we not break this for spectrum-two?

Copy link
Contributor

Choose a reason for hiding this comment

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

we should try not to treat S2 as a chance to introduce breaking changes unless they’re really necessary. These can have a big impact on adoption for product teams, so it’s worth being mindful about when and why we make them. If a change truly adds more value than the potential disruption, we can definitely go for it

.fileBackground {
fill: var(--spectrum-asset-file-background);
.spectrum-Asset-folderBackground {
fill: var(--spectrum-gray-200);
Copy link
Contributor

Choose a reason for hiding this comment

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

Do these map to the same value? Can you surface up these changes in the PR documentation too for quick reference by reviewers. Its hard to visualize from here

Copy link
Collaborator

@marissahuysentruyt marissahuysentruyt Nov 11, 2025

Choose a reason for hiding this comment

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

These should be the same values, yes (and they look to be mapped correctly).

Before Cassondra left, she started removing some of the complexity from a chunk of components, asset being one of them. You can see the changes (and remove of the --spectrum-asset- variables) here: https://github.com/adobe/spectrum-css/pull/4257/files#diff-3a87a9f21648ac03bf4532993e3cdf48604b9862efd1c0ea68c3f6c2d44b32b3

In a different PR (that does the same and removes mods and some of the --spectrum prefixed variables for asset list and miller), Cassondra left her reasoning as to why: adobe/spectrum-css#4260 (comment)

Hopefully that's useful! I absolutely agree with @Rajdeepc that we should surface the changes in a changeset. None of these migrations have had a changeset yet. (I asked a similar question in Slack when I was working on status light). Do we have the changeset management situation figured out? I've been out, so it might be and we need a changeset!

@Rajdeepc Rajdeepc added the Status: Ready for review PR ready for review or re-review. label Nov 11, 2025
Copy link
Collaborator

@marissahuysentruyt marissahuysentruyt left a comment

Choose a reason for hiding this comment

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

I don't think I have any true changes to request! I did leave some additional context in response to a few of Rajdeep's comments, though- hopefully they're helpful!

.fileBackground {
fill: var(--spectrum-asset-file-background);
.spectrum-Asset-folderBackground {
fill: var(--spectrum-gray-200);
Copy link
Collaborator

@marissahuysentruyt marissahuysentruyt Nov 11, 2025

Choose a reason for hiding this comment

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

These should be the same values, yes (and they look to be mapped correctly).

Before Cassondra left, she started removing some of the complexity from a chunk of components, asset being one of them. You can see the changes (and remove of the --spectrum-asset- variables) here: https://github.com/adobe/spectrum-css/pull/4257/files#diff-3a87a9f21648ac03bf4532993e3cdf48604b9862efd1c0ea68c3f6c2d44b32b3

In a different PR (that does the same and removes mods and some of the --spectrum prefixed variables for asset list and miller), Cassondra left her reasoning as to why: adobe/spectrum-css#4260 (comment)

Hopefully that's useful! I absolutely agree with @Rajdeepc that we should surface the changes in a changeset. None of these migrations have had a changeset yet. (I asked a similar question in Slack when I was working on status light). Do we have the changeset management situation figured out? I've been out, so it might be and we need a changeset!

@marissahuysentruyt
Copy link
Collaborator

@TarunAdobe I had one more thing!

Looking at the title of this PR, I'm curious if this work is a feat as opposed to a chore, since it's the migration into second-gen. Should we update this PR title to reflect that? Is my feat vs. chore logic even accurate? Asset is such a small component so I'm not sure if it's really a "breaking" change or not.

@TarunAdobe TarunAdobe changed the title chore: migrate asset feat: migrate asset to s2 styles and second-gen architecture Nov 13, 2025
Copy link
Collaborator

@marissahuysentruyt marissahuysentruyt left a comment

Choose a reason for hiding this comment

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

I went through it more in depth, and I have a few more questions for you. It still looks really great!

I'd like 2 changes I think:

  1. I think the big thing for me ended up being in the stories file, just keeping the render method in the meta to align with how the other migrated components have it set up currently.
  2. Pretty sure we need a :host selector in the CSS that also has the display: flex property.

var(--spectrum-asset-icon-outline-color)
);

.spectrum-Asset {
Copy link
Collaborator

Choose a reason for hiding this comment

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

The CSS here looks great- matches the S2 code we have in the spectrum-two branch. 👍 🥳

My only question is do we need a selector for :host, giving it the display: flex property? I believe the default display for :host is inline.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
.spectrum-Asset {
:host {
display: flex;
}
.spectrum-Asset {
display: flex; // we would also need this here for the `align-items` & `justify-content`
align-items: center;
justify-content: center;
inline-size: 100%;
block-size: 100%;
}

import { ASSET_VARIANTS, type AssetVariant } from './Asset.types.js';

/**
* @slot - The content to render when no `variant` is provided (typically an <img> element)
Copy link
Collaborator

Choose a reason for hiding this comment

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

There is another JSDoc comment in swc/components/asset/Asset.ts about the @slot that is almost identical to this. Is there a reason to have both? It looks like the content in the swc directory's Asset.ts file is the one being used in the control table when storybook renders.

I'm not opposed to keeping both of them, but I was just curious if we need both, or if some other components should have both.

Comment on lines +61 to +69
* <swc-asset style="block-size: 128px">
* <img class="spectrum-Asset-image" src="example.png" alt="Example image" />
* </swc-asset>
*
* @example
* <swc-asset variant="file" style="min-inline-size: 150px; block-size: 128px"></swc-asset>
*
* @example
* <swc-asset variant="folder" style="min-inline-size: 150px; block-size: 128px"></swc-asset>
Copy link
Collaborator

Choose a reason for hiding this comment

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

For these examples, do we want to encourage setting inline styles with the style attribute? Or is that more often what consumers would do? Maybe we could show just one example with inline styles.

I don't think this is a blocker, but I just noticed each one had inline styles.


export const Default: Story = {
render: (args) => html` <swc-asset variant="${args.variant}"></swc-asset> `,
render: (args) => template(args),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just for consistency, I believe the preference Gray was trying to establish is to include this render in the Meta object. So this line would move up under argTypes (line 42).

Then, we can clean up each story by just redefining args:

Suggested change
render: (args) => template(args),
// @ line 42
render: (args) => template(args),
... // the rest of the metadata and the default export...
export const Default: Story = {
args: {
variant: undefined,
},
};
export const File: Story = {
args: {
variant: 'file',
},
tags: ['!dev'],
};
export const Folder: Story = {
args: {
variant: 'folder',
},
tags: ['!dev'],
};

That does however, remove the inline styles you have on the stories, but are those inline styles necessary? Does this so acceptable to you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Status: Ready for review PR ready for review or re-review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants