Skip to content

Conversation

@jzempel
Copy link
Member

@jzempel jzempel commented Mar 28, 2024

Description

Provides a fully refactored getColor utility that will support v9 color redesigns (incl. dark mode) along with supporting tests and Storybook demo.

Checklist

  • 👌 design updates will be Garden Designer approved (add the designer as a reviewer)
  • 🌐 demo is up-to-date (npm start)
  • ⬅️ renders as expected with reversed (RTL) direction
  • 🤘 renders as expected with Bedrock CSS (?bedrock)
  • 💂‍♂️ includes new unit tests. Maintain existing coverage (always >= 96%)
  • tested for WCAG 2.1 AA accessibility compliance
  • 📝 tested in Chrome, Firefox, Safari, and Edge

@coveralls
Copy link

coveralls commented Mar 28, 2024

Coverage Status

coverage: 96.068% (+0.03%) from 96.037%
when pulling 87dfc57 on jzempel/get-color
into d2b7c8e on next.

}
};

type ColorParameters = {
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Wondering if there is consumer value in externalizing this type.

Copy link
Member Author

Choose a reason for hiding this comment

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

💡 Wondering if there is consumer value in externalizing this type.

Yeah, I was wondering the same thing. Let's hold off for now, as we don't export types for the other utilities. If a consumer wants it, we can release the exported type.

} else {
const _colors = scale([PALETTE.white, _hue, PALETTE.black])
.correctLightness()
.colors(PALETTE_SIZE + 2);
Copy link
Contributor

Choose a reason for hiding this comment

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

It might be good to explain that this generates a 14-shade color palette that includes white and black. Further down white and black is excluded to create a standardized 12-shade palette.

* found at http://www.apache.org/licenses/LICENSE-2.0.
*/

import { scale, valid } from 'chroma-js';
Copy link
Contributor

Choose a reason for hiding this comment

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

While chroma-js is a wonderful library, it does add 15.7k to the bundle size. And because it's not tree-shakeable, even pulling in a couple methods will import the whole package.

In the future, we could attempt to reproduce something close to scale to reduce the JS footprint.

As for valid, we could potentially leverage CSS.support (browser only). Ex:

CSS.support('color', 'red') // true
CSS.support('color', '#fff') //true

CSS.support('color', 'bad') // false

Copy link
Member Author

@jzempel jzempel Mar 29, 2024

Choose a reason for hiding this comment

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

Great callout @ze-flo. Can I request that we allow this "brand backfill" feature of getColor through for now? I'd like to lean into the RFC process for evaluating efficacy of other approaches (let's take a closer look at color2k, d3-color, etc). Specifically, let's add a scale research task to our v9 dev sequence. That way, we can get this into the hands of early adopters while continuing forward with the v9 effort.

Copy link
Contributor

Choose a reason for hiding this comment

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

Absolutely! 💯

if (shade === undefined) {
retVal = _hue;
} else {
const _colors = scale([PALETTE.white, _hue, PALETTE.black])
Copy link
Contributor

Choose a reason for hiding this comment

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

Chaining .mode('lab') could result in more vibrant colors in some cases.

Here's a sandbox highlighting the differences.

Copy link
Member Author

Choose a reason for hiding this comment

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

Awesome. Similar to the previous comment, I'd like to continue forward and get some of this comparative analysis into our designer's hands for evaluation. To my eyes, the LAB side has a tendency to yellow/brown-out the colors. We know the designers are getting good leverage out of Leonardo, which defaults to RGB and then adds some OKLCH sugar on top of chroma.js. But we also know that standard CSS advancements are happening fast, and Leonardo only just graduated from alpha after having been dormant for nearly 2 years. Anyway, more to research in this space.

Copy link
Contributor

Choose a reason for hiding this comment

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

To my eyes, the LAB side has a tendency to yellow/brown-out the colors.

Good observation! 👁️

defaults to RGB and then adds some OKLCH sugar on top of chroma.js

Very interesting. Thanks for sharing this.

I agree. We can iteratively fine-tune this as we see fit. Great work!

Base automatically changed from jzempel/v9-palette to next March 28, 2024 21:51
Comment on lines +51 to +53
- `npm start` to launch Storybook with live reload. Use `PACKAGE=dirname npm start`
(where `dirname` is a package directory name) to limit Storybook launch to the
given Garden package.
Copy link
Member Author

Choose a reason for hiding this comment

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

Slipped this efficiency tip in since I keep forgetting about it 😅

@jzempel jzempel marked this pull request as ready for review March 29, 2024 15:16
@jzempel jzempel requested a review from a team as a code owner March 29, 2024 15:16
@jzempel jzempel requested review from geotrev and ze-flo March 29, 2024 15:16
@jzempel jzempel merged commit c141531 into next Mar 30, 2024
@jzempel jzempel deleted the jzempel/get-color branch March 30, 2024 03:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

6 participants