Skip to content

docs: Add a Color Token Search component to the docs #2607

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

Merged
merged 6 commits into from
Jun 30, 2025

Conversation

taylorvnoj
Copy link
Contributor

@taylorvnoj taylorvnoj commented Jun 28, 2025

Motivations

I've been hearing from Atlantis users that they've been wanting a color token search (I've also always wanted one) - so here it is. This is helpful in multiple scenarios: finding the correct semantic token to use instead of grabbing the base color, maybe a figma doesn't have the token name listed but has the hex value, etc.
I think this will encourage token usage & will save time finding the correct token to use.

Changes

Added

  • Added a ColorSearch component to the design documentation (Colors page)
    • Allows users to search for color tokens by entering a hex code, HSL, or RGB(A) value
    • Displays matching color tokens with a swatch, token name, and a copy-to-clipboard button
    • Shows a message when no matching color tokens are found
Screen.Recording.2025-06-27.at.9.27.32.PM.mov

Testing

Enter a bunch of different color values and make sure you're getting a variety of tokens.
When there is no matching token, subdued text under the input will inform you of that.
For example you can find color token values in:

  • packages/design/src/assets/tokens.all.colors.ts
  • packages/design/src/tokens/

Changes can be
tested via Pre-release


In Atlantis we use Github's built in pull request reviews.

@taylorvnoj taylorvnoj self-assigned this Jun 28, 2025
Copy link

cloudflare-workers-and-pages bot commented Jun 28, 2025

Deploying atlantis with  Cloudflare Pages  Cloudflare Pages

Latest commit: bdc0572
Status: ✅  Deploy successful!
Preview URL: https://7fc3c848.atlantis.pages.dev
Branch Preview URL: https://taylor-color-search.atlantis.pages.dev

View logs

@taylorvnoj taylorvnoj changed the title Taylor/color search feat(docs): Add a Color Token Search component to the docs Jun 28, 2025
@taylorvnoj taylorvnoj changed the title feat(docs): Add a Color Token Search component to the docs docs: Add a Color Token Search component to the docs Jun 28, 2025
@taylorvnoj taylorvnoj marked this pull request as ready for review June 30, 2025 12:37
@taylorvnoj taylorvnoj requested a review from a team as a code owner June 30, 2025 12:37
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there, perhaps, a well-maintained and small size library that has all of those utils included? I'm not necessarily pushing for using an external dependency, but my concern is that none of those newly added utils are covered by tests. Moreover, it feels like to properly test everything, we'd need to write very extensive and robust test suites.

Copy link
Contributor Author

@taylorvnoj taylorvnoj Jun 30, 2025

Choose a reason for hiding this comment

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

There are a few lightweight packages but I would also like to avoid using an external dependency, especially when it's just 1 utils file that gets us what we want, also easy to configure later on if we need to change anything.
I am happy to write a test file for the utils. Many other files in our new docs site do not have test files because we were just pushing to release but I can start that pattern here

@taylorvnoj taylorvnoj requested a review from nad182 June 30, 2025 19:17
Copy link
Contributor

Choose a reason for hiding this comment

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

If this file is moved to colorTokenMatch folder, we can just name it index.ts, unless you want to separate each util into a separate folder/file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oops! Good call!

Comment on lines 79 to 115
const cases = [
{
input: "#032B3A",
expectedTokens: ["color-base-blue--900", "color-heading"],
},
{
input: "hsl(86, 100%, 46%)",
expectedTokens: ["color-brand--highlight"],
},
{
input: "rgba(255, 255, 255, 1)",
expectedTokens: ["color-white", "color-text--reverse"],
},
{
input: "rgb(85, 106, 203)",
expectedTokens: ["color-indigo"],
},
];

cases.forEach(({ input, expectedTokens }) => {
test(`returns the correct token(s) for input "${input}" (expects: ${expectedTokens.join(
", ",
)})`, () => {
const normalizedInput = normalizeColor(input);

const matches = Object.entries(allColors).filter(
([, colorValue]) =>
typeof colorValue === "string" &&
colorsAreEqual(normalizedInput, normalizeColor(colorValue), 2),
);

const matchTokens = matches.map(([token]) => token);

expectedTokens.forEach(expected => {
expect(matchTokens).toContain(expected);
});
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be possible to leverage test.each here? Similar to this JFE example.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated!

Copy link
Contributor

@nad182 nad182 left a comment

Choose a reason for hiding this comment

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

Nice addition to the docs site! I'm approving the PR.

One thing I think would be nice to do (perhaps, in the next iteration) is to make search more flexible (by supporting partial matches), which could make it even faster/more useful to find tokens.
Otherwise, you need to be very precise (which is fine for the most part if colors are just being copied from Figma).

Screenshot_20250630-171507
Screenshot_20250630-171521

@taylorvnoj
Copy link
Contributor Author

@nad182 good call out! Thanks for approving - this way we can get it out and get some feedback. That change should be very minimal so happy to iterate on that soon!

@taylorvnoj taylorvnoj merged commit 9369cb0 into master Jun 30, 2025
13 checks passed
@taylorvnoj taylorvnoj deleted the TAYLOR/color-search branch June 30, 2025 21:26
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.

2 participants