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

chore: make the spectrum-two theme fully functional #4731

Closed
wants to merge 240 commits into from

Conversation

graynorton
Copy link

@graynorton graynorton commented Sep 6, 2024

Description

The spectrum-two theme didn't yet have all of the necessary plumbing in tools/styles and tools/theme.

This PR adds the missing files and updates various build scripts to create a fully functioning spectrum-two theme.

Note that the spectrum-two theme (like the spectrum and express themes) includes the core-global CSS variables to ensure that application views relying on these variables will not break when migrating to the spectrum-two theme. Per the plan of record, these variables remain deprecated and will be removed in a future major version of SWC.

Related issue(s)

  • SWC-348, SWC-466 (internal JIRA)

Motivation and context

Allow the spectrum-two theme to be used and tested.

How has this been tested?

Tested in the Storybook theme switcher, in both SWC and the downstream UEC project.

jnjosh and others added 30 commits March 15, 2024 11:51
@graynorton graynorton changed the base branch from main to testing-css-bridge-for-s2 September 11, 2024 18:41
@graynorton graynorton marked this pull request as ready for review September 11, 2024 20:38
@graynorton graynorton requested a review from a team as a code owner September 11, 2024 20:38
Copy link
Collaborator

@rubencarvalho rubencarvalho left a comment

Choose a reason for hiding this comment

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

Great work! I left a few nit comments and a larger question around lightest and darkest artifacts 👍

@@ -138,6 +138,7 @@ const processTypography = async (
// TODO: use resolve package to find node_modules
// TODO: we need to revisit whether we need these
const spectrumPaths = [
// Spectrum 1
path.resolve(
path.join(
__dirname,
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: could we clean up some repetition and avoid using indexes below? For example, instead of relying on the i values, we could structure the spectrumPaths as objects with descriptive fields like system.

const CSSbasePath = path.resolve(path.join(__dirname, '..', 'node_modules', '@spectrum-css'));
const spectrumPaths = [
  // Spectrum 1
  { path: path.join(CSSbasePath, 'vars', 'dist'), system: 'spectrum-one' },
  // Spectrum 2 (same path as S1)
  { path: path.join(CSSbasePath, 'vars', 'dist'), system: 'spectrum-two' },
  // Express
  { path: path.join(CSSbasePath, 'expressvars', 'dist'), system: 'express' }
];

Copy link
Author

Choose a reason for hiding this comment

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

Yes, this would definitely be nicer!

My high-level approach with this PR was to apply as light a touch as possible, doing just what was necessary to make the new theme work, but it seems worth doing this to leave things in a cleaner state. I'll go ahead and make the change.

Copy link
Author

Choose a reason for hiding this comment

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

Done! I started by applying your suggestion directly, then ended up simplifying a bit more in the process of changing to use import.meta.resolve to find the @spectrum-css packages.

@@ -170,10 +183,19 @@ const foundVars = await findUsedVars();

spectrumPaths.forEach((spectrumPath, i) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

this could then look like

spectrumPaths.forEach(({ path, system }) => { ... }


:host,
:root {
-webkit-tap-highlight-color: rgb(0 0 0 / 0%);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I see this is also on the other systems, but why do we need this? 🤔

Copy link
Contributor

Choose a reason for hiding this comment

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

Before we decide to remove this can we confirm if the tap effect coming up in iOS?

Copy link
Author

Choose a reason for hiding this comment

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

That's a good question; again, my "make it work" approach to this PR led me to not pull on this thread at the moment, but we can certainly try to figure it out.

@Rajdeepc, @jnjosh, @nikkimk, does any of you know?

Copy link
Contributor

Choose a reason for hiding this comment

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

Not that I know of right now but I will try to dig into the glossary. But this shouldn't block the merge :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

This comment is mostly for me to get more context. It is non-blocking.

"development": "./spectrum-two/theme-light.dev.js",
"default": "./spectrum-two/theme-light.js"
},
"./spectrum-two/theme-lightest-core-tokens.js": {
Copy link
Collaborator

Choose a reason for hiding this comment

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

AFAIK there is no lightest theme on S2.

Copy link
Author

Choose a reason for hiding this comment

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

I was following the lead of the Express system, which also doesn't have lightest or darkest themes but nonetheless includes files for loading lightest and darkest. These files actually actually just load the light and dark values under the hood.

My assumption was that this was done to avoid failing ungracefully in the case where someone populates the system and color properties of <sp-theme> with a non-existent pairing.

My instinct is that a more principled approach would be to rework <sp-theme> so that you simply get dev mode warnings when trying invalid combinations, rather than using this "facade" approach within each theme...but a) I'm not sure whether any customers of the Express theme might be relying on the status quo; and b) again, my general approach to this PR was to get the spectrum-two theme working with minimal changes to the code.

I am open to going a different way here, but my instinct remains to take a light touch for now, on the assumption that we'll likely end up making significant changes to the whole theming mechanism in the 1.x => 2.0 transition, and that would be a better time to revisit the approach here.

Copy link
Contributor

Choose a reason for hiding this comment

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

This exports are a miss from our side while deprecating lightest and darkest theme. We can tackle it in the main PR. Thanks

Copy link
Collaborator

Choose a reason for hiding this comment

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

Understood, and that does make sense. I agree with the "let's keep changes to a minimum" approach for now. It's definitely something we can address later on.

Copy link
Collaborator

Choose a reason for hiding this comment

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

If nothing else, this provides yet another good data point for us to look at, whenever we take an holistic approach to theming, "systems", sp-theme,...

tools/theme/src/Theme.ts Show resolved Hide resolved
@@ -11,6 +11,8 @@ governing permissions and limitations under the License.
*/

import '../../spectrum-two/theme-light-core-tokens.js';
import '../../spectrum-two/theme-lightest-core-tokens.js';
Copy link
Collaborator

Choose a reason for hiding this comment

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

double check: lightest and darkest should not be needed?

tools/theme/src/spectrum-two/themes.ts Show resolved Hide resolved
@@ -58,7 +58,7 @@
"lit-html"
],
"dependencies": {
"@lit-labs/observers": "^2.0.0",
"@lit-labs/observers": "^2.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.

might as well go for the latest 2.0.3 version? unless there is a transitive dependency conflict :)

Copy link
Author

Choose a reason for hiding this comment

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

I only made this change to ensure that all packages within SWC were pulling in the same version of observers; the others were on 2.0.2 already.

The reason why I went down this path at all in this otherwise-unrelated PR is that the discrepancy was causing yarn link to fail when linking UEC and SWC for testing purposes; making this change allowed yarn link to work! 🎉

We could consider bumping everything to the latest version, but that seemed like a truly unrelated change best done in a separate PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes we can create a follow up PR to version bumps all the dependencies. We usually have one planned from dependebot after we merge colors to main. This can stay at the current version only if you wish to!

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks for the context. Let us keep this as it is - I was mostly wondering if you had faced other upgrade-related conflicts or difficulties.

@@ -138,6 +138,7 @@ const processTypography = async (
// TODO: use resolve package to find node_modules
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: on a side note, we could tackle this TODO and consider using resolve to dynamically locate the node_modules directory instead of hardcoding the paths below. Not sure if it is very needed, but I think this could help with symlinked packages.

Copy link
Author

Choose a reason for hiding this comment

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

Yeah, I thought about that as well, but opted not to in keeping with my "lightest touch" approach to this PR. Let me know if you feel strongly about making this change now and we can discuss.

Copy link
Author

Choose a reason for hiding this comment

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

I actually went ahead and took care of this when incorporating the other change you suggested. 🙌

Copy link
Collaborator

Choose a reason for hiding this comment

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

I see, thanks! 😄 And who knows - maybe it actually will make our future selves happy someday!

@graynorton
Copy link
Author

graynorton commented Sep 12, 2024

Great work! I left a few nit comments and a larger question around lightest and darkest artifacts 👍

Thanks for the thorough review and suggestions, @rubencarvalho!

I took care of the nits and commented with my rationale for including the lightest and darkest "facades".

@TarunAdobe TarunAdobe self-requested a review September 13, 2024 03:58
@TarunAdobe TarunAdobe changed the title Make the spectrum-two theme fully functional chore: make the spectrum-two theme fully functional Sep 13, 2024
Copy link
Collaborator

@rubencarvalho rubencarvalho left a comment

Choose a reason for hiding this comment

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

Thank you for the quick turn-around! 👍

Copy link
Contributor

@TarunAdobe TarunAdobe left a comment

Choose a reason for hiding this comment

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

I'd love to discuss the benefits of supporting non-core styles and lightest/darkest in S2. Both of these things we've marked deprecated in S1/Express and I don't want us to unconsciously promote consumers to use these types in S2 at least. S2 is not yet fully supported either way and I kinda feel okay if someone breaks their system because they were using lightest with S2. We already give dev mode warnings for this so I don't see why we're adding support for this in S2. I might be missing something bt this was basically my thought process while working on the testing-css-bridge-for-s2 branch few months back.

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 PR!

themes.forEach((theme) => {
if (isExpress && ['lightest', 'darkest'].includes(theme)) return;
if (!isSpectrum1 && ['lightest', 'darkest'].includes(theme)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

lightest and darkest will be deprecated in 1.0! Can we include light and dark only?

import { Theme } from '../src/Theme.js';
import '../src/spectrum-two/core.js';

Theme.registerThemeFragment('darkest-spectrum-two', 'color', darkStyles);
Copy link
Contributor

Choose a reason for hiding this comment

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

darkest will be deprecated in 1.0! Should this be dark?

import { Theme } from '../src/Theme.js';
import '../src/spectrum-two/core-tokens.js';

Theme.registerThemeFragment('darkest-spectrum-two', 'color', darkStyles);
Copy link
Contributor

Choose a reason for hiding this comment

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

darkest will be deprecated in 1.0! Should this be dark?

@@ -25,7 +25,7 @@ import {
import { DARK_MODE } from '@spectrum-web-components/reactive-controllers/src/MatchMedia.js';
import '@spectrum-web-components/theme/sp-theme.js';
import '@spectrum-web-components/theme/src/themes.js';
import '@spectrum-web-components/theme/src/spectrum-two/themes-core-tokens.js';
import '@spectrum-web-components/theme/src/spectrum-two/themes.js';
Copy link
Contributor

Choose a reason for hiding this comment

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

This needs to be updated in core-tokens.md also


:host,
:root {
-webkit-tap-highlight-color: rgb(0 0 0 / 0%);
Copy link
Contributor

Choose a reason for hiding this comment

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

Before we decide to remove this can we confirm if the tap effect coming up in iOS?


:host,
:root {
-webkit-tap-highlight-color: rgb(0 0 0 / 0%);
Copy link
Contributor

Choose a reason for hiding this comment

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

Not that I know of right now but I will try to dig into the glossary. But this shouldn't block the merge :)

"development": "./spectrum-two/theme-light.dev.js",
"default": "./spectrum-two/theme-light.js"
},
"./spectrum-two/theme-lightest-core-tokens.js": {
Copy link
Contributor

Choose a reason for hiding this comment

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

This exports are a miss from our side while deprecating lightest and darkest theme. We can tackle it in the main PR. Thanks

@@ -58,7 +58,7 @@
"lit-html"
],
"dependencies": {
"@lit-labs/observers": "^2.0.0",
"@lit-labs/observers": "^2.0.2",
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes we can create a follow up PR to version bumps all the dependencies. We usually have one planned from dependebot after we merge colors to main. This can stay at the current version only if you wish to!

@graynorton
Copy link
Author

I'd love to discuss the benefits of supporting non-core styles and lightest/darkest in S2.

@TarunAdobe

As for including the non-core (global) tokens in the spectrum-two system, this is something that I've discussed extensively with @jnjosh, @rubencarvalho and @Rajdeepc, and we've concluded that these tokens should remain in "deprecated" status for SWC 1.x (across all three systems) and be removed in SWC 2.0.

The rationale is that we want to get customers to spectrum-two as quickly and painlessly as possible, then support them in completing larger migration tasks during the SWC 1.x => 2.0 transition (which we expect to last for a year or more). If we were to ship the spectrum-two system in SWC 1.0 without including the legacy tokens, then teams would face potentially significant migration work before they could even try out and adopt spectrum-two.

As for including lightest and darkest in spectrum-two, please see the discussion with @rubencarvalho and @Rajdeepc elsewhere in this PR review. The tl;dr is that I followed the example of the express theme, which I believe is in exactly the same situation as spectrum-two (the system itself does not include lightest and darkest tokens, but the theme is set up to "fall back" to the light and dark tokens if a user sets color to lightest or darkest). We could reasonably make a different choice here, but I don't think that needs to be handled as part of this PR.

Does this make sense?

@Rajdeepc
Copy link
Contributor

I'd love to discuss the benefits of supporting non-core styles and lightest/darkest in S2.

@TarunAdobe

As for including the non-core (global) tokens in the spectrum-two system, this is something that I've discussed extensively with @jnjosh, @rubencarvalho and @Rajdeepc, and we've concluded that these tokens should remain in "deprecated" status for SWC 1.x (across all three systems) and be removed in SWC 2.0.

The rationale is that we want to get customers to spectrum-two as quickly and painlessly as possible, then support them in completing larger migration tasks during the SWC 1.x => 2.0 transition (which we expect to last for a year or more). If we were to ship the spectrum-two system in SWC 1.0 without including the legacy tokens, then teams would face potentially significant migration work before they could even try out and adopt spectrum-two.

As for including lightest and darkest in spectrum-two, please see the discussion with @rubencarvalho and @Rajdeepc elsewhere in this PR review. The tl;dr is that I followed the example of the express theme, which I believe is in exactly the same situation as spectrum-two (the system itself does not include lightest and darkest tokens, but the theme is set up to "fall back" to the light and dark tokens if a user sets color to lightest or darkest). We could reasonably make a different choice here, but I don't think that needs to be handled as part of this PR.

Does this make sense?

Thanks for the explanation! I feel lightest and darkest are not needed to be shipped as a part of spectrum-two reference since these needs to be deleted in 1.0. We would also want to surface this information to the consumers like express to not to use lightest and darkest global tokens and we have already deleted these two color modes already! I am okay to get these shipped as part of S1 but S2 will not have any global definitions of lightest and darkest.

@graynorton
Copy link
Author

I feel lightest and darkest are not needed to be shipped as a part of spectrum-two reference since these needs to be deleted in 1.0.

Sure, that makes sense to me. My suggestion would be to merge this PR, and then follow up with a new PR to remove lightest and darkest from both express and spectrum-two.

@Rajdeepc
Copy link
Contributor

I feel lightest and darkest are not needed to be shipped as a part of spectrum-two reference since these needs to be deleted in 1.0.

Sure, that makes sense to me. My suggestion would be to merge this PR, and then follow up with a new PR to remove lightest and darkest from both express and spectrum-two.

I feel lightest and darkest are not needed to be shipped as a part of spectrum-two reference since these needs to be deleted in 1.0.

Sure, that makes sense to me. My suggestion would be to merge this PR, and then follow up with a new PR to remove lightest and darkest from both express and spectrum-two.

Sounds great! I think we are all in the same page now! Thanks everyone

Base automatically changed from testing-css-bridge-for-s2 to feature/SWC-1.0-RC October 16, 2024 15:52
@graynorton
Copy link
Author

Closing this PR in favor of the cleanly reconstructed #4859

@graynorton graynorton closed this Oct 24, 2024
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.

10 participants