Skip to content

feat(swatch+swatchgroup): S2 migration #3677

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

Open
wants to merge 38 commits into
base: spectrum-two
Choose a base branch
from

Conversation

cdransf
Copy link
Member

@cdransf cdransf commented Apr 17, 2025

Description

CSS-1026 + CSS-1029

This migrates the swatch and swatchgroup components to the latest Spectrum 2 designs. Custom properties have been remapped and added per the design specification.

An Add Swatch variant has been added with the required color tokens and the specified add UI icon.

The Add Swatch and Mixed Value variants may not be combined with background colors or images.

The border should not be set when the swatch is selected as the border conflicts with the display of the selected state.

Removed custom properties

--spectrum-swatch-border-color
--spectrum-swatch-dash-icon-color (replaced by --spectrum-swatch-icon-color)

New custom properties

--spectrum-swatch-border-color-rgb
--spectrum-swatch-border-opacity
--spectrum-corner-radius-full
--spectrum-corner-radius-none
--spectrum-swatch-disabled-icon-border-opacity
--spectrum-swatch-icon-color
--spectrum-swatch-rectangle-width-multiplier
--spectrum-swatchgroup-border-color

New mods

--mod-add-button-background
--mod-add-button-background-down
--mod-add-button-background-hover
--mod-add-button-background-keyboard-focus
--mod-corner-radius-full
--mod-mixed-button-background
--mod-swatchgroup-border-color
--mod-swatch-border-color-rgb
--mod-swatch-border-opacity

How and where has this been tested?

Please tag yourself on the tests you've marked complete to confirm the tests have been run by someone other than the author.

Validation steps

Regression testing

Validate:

  1. The documentation pages for at least two other components are still loading, including:
  • The pages render correctly, are accessible, and are responsive.
  1. If components have been modified, VRTs have been run on this branch:
  • VRTs have been run and looked at.
  • Any VRT changes have been accepted (by reviewer and/or PR author), or there are no changes.

Screenshots

To-do list

  • I have read the contribution guidelines.
  • I have updated relevant storybook stories and templates.
  • I have tested these changes in Windows High Contrast mode.
  • If my change impacts other components, I have tested to make sure they don't break.
  • If my change impacts documentation, I have updated the documentation accordingly.
  • ✨ This pull request is ready to merge. ✨

@cdransf cdransf added wip This is a work in progress, don't judge. skip_vrt Add to a PR to skip running VRT (but still pass the action) labels Apr 17, 2025
@cdransf cdransf self-assigned this Apr 17, 2025
Copy link

changeset-bot bot commented Apr 17, 2025

🦋 Changeset detected

Latest commit: 343a87b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@spectrum-css/swatchgroup Major
@spectrum-css/swatch Major

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

github-actions bot commented Apr 17, 2025

🚀 Deployed on https://pr-3677--spectrum-css.netlify.app

Copy link
Contributor

github-actions bot commented Apr 17, 2025

File metrics

Summary

Total size: 1.38 MB*
Total change (Δ): 🟢 ⬇ 0.91 KB (-0.06%)

Table reports on changes to a package's main file. Other changes can be found in the collapsed Details section below.

Package Size Minified Gzipped Δ
swatch 12.75 KB 11.99 KB 2.08 KB 🔴 ⬆ 2.46 KB
swatchgroup 1.50 KB 1.45 KB 0.69 KB 🔴 ⬆ 0.29 KB

File change details

swatch

Filename Head Minified Gzipped Compared to base
index.css 12.75 KB 11.99 KB 2.08 KB 🔴 ⬆ 2.46 KB
metadata.json 6.55 KB - - 🔴 ⬆ 1.16 KB

swatchgroup

Filename Head Minified Gzipped Compared to base
index.css 1.50 KB 1.45 KB 0.69 KB 🔴 ⬆ 0.29 KB
metadata.json 0.64 KB - - 🔴 ⬆ 0.14 KB

tokens

Filename Head Minified Gzipped Compared to base
css/dark-vars.css 46.40 KB - - 🟢 ⬇ 0.24 KB
css/global-vars.css 77.15 KB - - -
css/index.css 250.83 KB - - 🟢 ⬇ 0.44 KB
css/large-vars.css 41.25 KB - - -
css/light-vars.css 46.40 KB - - 🟢 ⬇ 0.23 KB
css/medium-vars.css 41.37 KB - - -
json/tokens.json 390.56 KB - - -
* Size is the sum of all main files for packages in the library.
* An ASCII character in UTF-8 is 8 bits or 1 byte.

@cdransf cdransf force-pushed the cdransf/s2-swatch-group-migration branch from ffa2cad to 37bccbb Compare April 17, 2025 23:28
@adobe adobe deleted a comment from github-actions bot Apr 17, 2025
@cdransf cdransf force-pushed the cdransf/s2-swatch-group-migration branch 3 times, most recently from 91c31d2 to d0944eb Compare April 21, 2025 15:28
@cdransf cdransf marked this pull request as ready for review April 21, 2025 17:51
@cdransf cdransf added size-3 M ~18-30hrs; moderate effort or complexity, several work days needed. ready-for-review and removed wip This is a work in progress, don't judge. labels Apr 21, 2025
@cdransf cdransf force-pushed the cdransf/s2-swatch-group-migration branch from 9ca18cb to f3f8289 Compare April 22, 2025 13:37
@cdransf cdransf added the wip This is a work in progress, don't judge. label Apr 22, 2025
@cdransf cdransf force-pushed the cdransf/s2-swatch-group-migration branch 2 times, most recently from 02c2cca to 044c357 Compare April 22, 2025 17:23
@cdransf cdransf added size-8 XL ~18-54hrs; huge effort, high complexity, takes a whole sprint, maybe break down. and removed wip This is a work in progress, don't judge. size-3 M ~18-30hrs; moderate effort or complexity, several work days needed. labels Apr 22, 2025
Copy link
Collaborator

@rise-erpelding rise-erpelding left a comment

Choose a reason for hiding this comment

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

Hi! This looks like a pretty minor migration but I have a few comments that I added below that I'll summarize:

  • Would love to see some updated testing options to show variants/states that we aren't seeing, this really helps us prevent regressions (or will once we have these changes in our main branch). Key-focus state was one that I mentioned to add, but it's also helpful to run through these manually too (like for instance, a hover test case usually shouldn't have a hover state, key-focus states shouldn't have an additional key focus state when you tab to the component).
  • I think by default we should be seeing some rounding on the swatch, although it's really still unclear to me after looking through specs whether or not the no-rounding option should still exist in S2. Some clarification from design on that might be good here, but doesn't need to be a blocker, but in the mean time since all the default swatches in the specs have rounding, ours should too.
  • Swatch group spacing for spacious maybe needs adjusting.

I have a couple of other questions after looking through the spec and the PR too:

  • Down state is kind of mentioned in the spec, but no tokens are referenced. Does this mean that swatch gets a down state treatment (with the perspective-based transform)? Not a blocker for this PR but we should find out.
  • Is that swatch border color (default) correct? I'm seeing it compute to rgba(19, 19, 19, 0.42) but the spec says gray-1000 which should be 0, 0, 0. If we adjust that though is there a difference between that default border and the light border?

I didn't check WHCM on this pass, but will plan to in the future!

@cdransf cdransf force-pushed the cdransf/s2-swatch-group-migration branch from 0fcbcb5 to db0370d Compare April 24, 2025 15:30
Copy link
Collaborator

@castastrophe castastrophe left a comment

Choose a reason for hiding this comment

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

Looking good! My biggest feedback note is about the sizing for Swatch Group. Danke!

@cdransf cdransf force-pushed the cdransf/s2-swatch-group-migration branch from 8adbddb to f585079 Compare April 24, 2025 19:37
cdransf and others added 21 commits May 6, 2025 13:14
…lt; add missing isAddSwatch arg for swatchgroup story
Co-authored-by: [ Cassondra ] <castastrophe@users.noreply.github.com>
- updates some documentation
- removes the light border variants
- removes the border control
- updates some of the test cases
- updates metadata
@cdransf cdransf force-pushed the cdransf/s2-swatch-group-migration branch from 131e6f1 to a39b0a3 Compare May 6, 2025 20:14
Copy link
Collaborator

@rise-erpelding rise-erpelding left a comment

Choose a reason for hiding this comment

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

Ok, this is getting closer! I think swatch is looking pretty nice aside from some minor things, and I had some questions about the spacing in swatch group.

A couple of things that I noticed that aren't from the migration work here and therefore I couldn't single them out in the code:

  • I started playing with the empty/nothing variant a little more. It's nice that you can see it in Storybook by entering transparent for the color! This is entirely optional in my opinion, but it'd be nice to add that to the swatchColor control description, something like "Supports standard color input or any valid input for the background property such as linear-gradient(red, blue) or transparent." Not sure if there are any other fun swatches you can access just from changing swatchColor to something unexpected that isn't already covered. Just a thought, really up to you!
  • Another thing I noticed relating to the empty/nothing variant is that our slash goes from top left to bottom right whereas the spec's goes from top right to bottom left. Should we update that here? Playing with it in the browser, I think we've just got the rotation a bit off, but it looked like changing the rotation for the rectangular variant results in the slash ending before it's filled the whole swatch. That one might need an adjustment to the block-size as well?
    image image
    image image

border-color: var(--spectrum-swatch-focus-indicator-color);
border-radius: var(--spectrum-swatch-focus-indicator-border-radius);

transition: opacity var(--mod-animation-duration-100, var(--spectrum-animation-duration-100)) ease-in-out;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is lovely!! Nice work!

Comment on lines 104 to 109
{
testHeading: "Empty",
swatchColor: undefined,
imageUrl: undefined,
isMixedValue: false,
borderStyle: "default",
isAddSwatch: false,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since we're treating this as a state, the empty + selected and empty + keyfocused combos from the spec are not getting tested:
image

I'm also wondering if we should have empty swatches in the mixed and add variants. Since we have isMixedValue: false and isAddSwatch: false here they end up getting canceled out. Seems like the appropriate behavior would be that mixed value or add swatches override empty swatches (which they do when I play with the Storybook controls!).
image

I'm not sure what the right answer is. I like the idea of keeping empty as a state, but maybe refining this test case with ignore: to take out the mixed value and add swatches. And then perhaps we could also add empty into the testData array but use ignore/include to eliminate some of the unneeded states? (At least for sure we don't need empty x empty.)

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, I added empty to testData and then removed empty, add and mixed value from it in the state data section. I think this makes more sense as it gives us more coverage for the empty states and removes the cases where add/mixed value override empty. ✨

Comment on lines 11 to 20
testHeading: "Extra small",
density: "sizeXS",
},
{
testHeading: "Spacious",
density: "spacious",
testHeading: "Small",
density: "sizeS",
},
{
testHeading: "Large",
density: "sizeL",
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the "Extra small", "Small", and "Large" here describe the density, right? Can we clarify that in the test heading so as not to be confused with the swatch size?

But looking into it further, I'm a bit confused about the density options, it looks like from the spec the spacing options are compact (same spacing for all swatch sizes), regular (same spacing for all swatch sizes), and spacious (these have different tokens for different sizes)?

I'm not sure we've ever applied tokens depending on the size on a child component, but if I'm understanding correctly that that's what we need to do here, I wonder if this could be a job for :has()?

Copy link
Member Author

Choose a reason for hiding this comment

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

Alrighty, I took a look at these changes in e228979. --spectrum-spacing-75 is set as the default (medium variation which is typically our default), then we have sizeS and sizeL where sizeL leverages :has to apply the appropriate density spacing based on the child swatch sizing class.

I split out tests with more informative headers for each density + sizing permutation. ✨

Comment on lines -68 to -78
borderStyle: {
...Swatch.argTypes.borderStyle,
defaultValue: "noBorder",
description: "Apply the `spectrum-Swatch--lightBorder` class to a swatch in the swatch group when it has a color contrast ratio of less than 3:1.",
table: {
type: { summary: "string", required: true },
category: "Component",
defaultValue: { summary: "noBorder" },
},
options: ["noBorder", "lightBorder"],
},
Copy link
Collaborator

Choose a reason for hiding this comment

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

Did we decide we were going to eliminate border options completely for swatch and swatch group? There's only one type of border for swatch, a different type of border for swatch group, and then the no-border option is completely gone?

There's a lingering borderStyle arg in the swatch group controls here and also in both templates, we'll have to adjust/remove accordingly.

image

Copy link
Member Author

Choose a reason for hiding this comment

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

I believe so — @marissahuysentruyt may understand it better. But my understanding is that the individual swatches have border style options but those are superseded by the swatchgroup border styles. 😵‍💫

I went ahead and removed that borderStyle arg in keeping with that understanding. ✨

--spectrum-swatchgroup-spacing: var(--spectrum-spacing-100);

/* Border opacity (swatches in a swatch group have a 20% opacity border instead of 42% default border opacity) */
--spectrum-swatch-border-opacity: 0.2;
Copy link
Collaborator

Choose a reason for hiding this comment

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

We'll probably want to add a comment here to keep Stylelint happy.

image

@cdransf cdransf requested a review from rise-erpelding May 6, 2025 23:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-for-review size-8 XL ~18-54hrs; huge effort, high complexity, takes a whole sprint, maybe break down. skip_vrt Add to a PR to skip running VRT (but still pass the action)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants