chore: migrate icon to core and second-gen#6012
Conversation
|
📚 Branch Preview Links🔍 First Generation Visual Regression Test ResultsWhen 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: If the changes are expected, update the |
83fddc6 to
6ee05f1
Compare
7cc0216 to
9e3aebd
Compare
cbc96d1 to
f2ab00c
Compare
1st-gen/tools/base/src/version.js
Outdated
There was a problem hiding this comment.
Can you verify why this file is showing?
There was a problem hiding this comment.
BLOCKING - can you verify, please?
2nd-gen/packages/swc/components/icon/stories/icon.internal.stories.ts
Outdated
Show resolved
Hide resolved
| // ────────────────── | ||
|
|
||
| /** | ||
| * Accessible label for the icon. |
There was a problem hiding this comment.
nit: we may want to work on these descriptions - we're pending some docs around this - but I imagine we'll want to be more descriptive in the future.
1c0d556 to
03e29a9
Compare
7b89045 to
4973ade
Compare
Rajdeepc
left a comment
There was a problem hiding this comment.
Kindly add the ./components/icon export and typesVersions entry to core/package.json. This will fail for external consumers after build.
| * Icon t-shirt size. | ||
| */ | ||
| @property({ reflect: true }) | ||
| public size: IconSize = 'm'; |
There was a problem hiding this comment.
Other 2nd-gen components uses SizedMixin
There was a problem hiding this comment.
shoot. this was a big deal oops. got it right now
| protected override updated(changedProperties: PropertyValues): void { | ||
| super.updated(changedProperties); | ||
| if (changedProperties.has('label')) { | ||
| this.updateSlottedIcon(); |
There was a problem hiding this comment.
What about the initial render when a user provides
<swc-icon><svg>...</svg></swc-icon>Can you override firstUpdated() to call updateSlottedIcon() and updateHostAccessibility() to ensure the initial state is correct regardless of property change timing. Also please think of using @queryAssignedElements instead of manually querying the slot.
| @@ -0,0 +1,25 @@ | |||
| /** | |||
There was a problem hiding this comment.
These are pure SVG template functions with no rendering layer dependency. Do you feel that we should move icon element templates to 2nd-gen/packages/core/components/icon/elements/ or a separate core/icons/ directory?
There was a problem hiding this comment.
I agree the icon templates are conceptually “core-ish”, but right now they return Lit TemplateResult (html\``), so they still carry a rendering-layer dependency.
For this PR, I’d prefer to keep them under @adobe/spectrum-wc/icon/elements to avoid mixing concerns and expanding scope (move would also require export/typesVersions + import-path updates).
I’m happy to do a follow-up where we decide the long-term home (core/components/icon/elements vs core/icons) and, if needed, first make the templates rendering-agnostic so the move is clean.
There was a problem hiding this comment.
I'm OK with keeping it simpler for now! But interestingly enough, I'd actually argue these may be part of the "rendering layer" - they are theme-specific, e.g. if we were to have a aether/components/icon/elements, these SVGs would be different.
| }; | ||
|
|
||
| export const Chevron100Icon = ({ | ||
| direction = 'right', |
There was a problem hiding this comment.
This is the only icon which is using an inline style transform. There is an inconsistency. We can either make direction a concern of the swc-icon host via a CSS approach or we can document why Chevron is special.
There was a problem hiding this comment.
the rationale here is that we don't want another component to control the icon css or how icon should render.. this should be isolated in the icon template literal itself and so optionally some icons can have these attributes like direction in this case. it was an intentional choice
Rajdeepc
left a comment
There was a problem hiding this comment.
Thanks for addressing the feedback. Added few suggestion but they are mostly trivial. Kindly check @adobe/spectrum-wc/icon/elements subpath issue then we can land this.
| import { Chevron100Icon } from '@adobe/spectrum-wc/icon/elements'; | ||
| import * as iconElements from '@adobe/spectrum-wc/icon/elements'; |
There was a problem hiding this comment.
Here * only matches a single path segment so @adobe/spectrum-wc/icon/elements would not resolve through ./*. This works in Storybook dev via the Vite resolve.alias but will fail for published customers.
| import { | ||
| ICON_VALID_SIZES, | ||
| type IconSize, | ||
| } from '../../../../core/components/icon/Icon.types.js'; |
There was a problem hiding this comment.
You can use absolute import here since export was added to core/package.json
| * All sizes are shown below for comparison. | ||
| */ | ||
| export const Sizes: Story = { | ||
| render: (_args) => html` |
There was a problem hiding this comment.
Please pass ..args here. You are ignoring it through prefixed with underscore. Storybook controls will not work.
| render: (args) => html` | ||
| ${ICON_VALID_SIZES.map( | ||
| (size) => html` | ||
| <swc-icon |
There was a problem hiding this comment.
Can we use the template? 😄
| */ | ||
| export const Sources: Story = { | ||
| render: (args) => html` | ||
| <swc-icon |
| */ | ||
| export const SharedTemplates: Story = { | ||
| render: (args) => html` | ||
| <swc-icon |
There was a problem hiding this comment.
Same! Template wherever possible, please!
| padding: 8px; | ||
| " | ||
| > | ||
| <swc-icon |
| */ | ||
| export const Accessibility: Story = { | ||
| render: (args) => html` | ||
| <swc-icon label=${ifDefined(args.label)} size=${ifDefined(args.size)}> |
There was a problem hiding this comment.
Last comment on the template! 😛
| ${catalog.map( | ||
| (entry) => html` | ||
| <div | ||
| style=" |
There was a problem hiding this comment.
This is breaking the formatting, could we use Lit's styleMap for this, please?
| padding: '8px', | ||
| } as const; | ||
|
|
||
| const renderIcon = ( |
There was a problem hiding this comment.
I think we may be talking past each other 😅 Maybe I'm missing what this does, but why do we need the renderIcon wrapper? Why can't we use template directly?
See the suggestions below
|
|
||
| export const Overview: Story = { | ||
| tags: ['overview'], | ||
| render: (args) => renderIcon(args), |
There was a problem hiding this comment.
Without the renderIcon this could be:
| render: (args) => renderIcon(args), | |
| render: (args) => template(args, iconSvg), |
|
|
||
| export const Playground: Story = { | ||
| tags: ['autodocs', 'dev'], | ||
| render: (args) => renderIcon(args), |
There was a problem hiding this comment.
Without the renderIcon this could be:
| render: (args) => renderIcon(args), | |
| render: (args) => template(args, iconSvg), |
| * - Default slot: Provide SVG markup to render. | ||
| */ | ||
| export const Anatomy: Story = { | ||
| render: (args) => renderIcon(args, { label: 'Chevron icon' }), |
There was a problem hiding this comment.
Without the renderIcon this could be:
| render: (args) => renderIcon(args, { label: 'Chevron icon' }), | |
| render: (args) => template({ ...args, label: 'Chevron icon' }, iconSvg), |
611677c to
43451e7
Compare
be01809 to
9e7bb1a
Compare
9e7bb1a to
fdcf5a7
Compare
Description
This PR introduces a minimal icon component for 2nd-gen in
@adobe/swc, following the RFC direction.It provides a consistent way for 2nd-gen components to render icons via:
It also adds a small shared icon template catalog under
@adobe/swc/icon/elementsto avoid per-component SVG duplication.Motivation and context
This change unblocks migration of icon-dependent components to 2nd-gen without relying on 1st-gen icon packages and global iconset infrastructure.
The goal is to keep icon usage local, explicit, and consistent across 2nd-gen components.
Related issue(s)
Screenshots (if appropriate)
N/A
Author's checklist
Reviewer's checklist
swc-iconbehavior is correct for slot/SVG andsrcfallback.@adobe/swc/icon/icons).Manual review test cases
Review
swc-iconStorybook docs/examplesChevron100Icon,AlertIcon) render correctly.Device review