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

Use semantic tokens for CellCore #2448

Open
wants to merge 4 commits into
base: wb-1797-cell-color-contrast
Choose a base branch
from

Conversation

beaesguerra
Copy link
Member

Summary:

Use semantic tokens for cell-core.

Issue: WB-1797

Test plan:

  • Review use of semantic tokens in code to make sure the intent makes sense.
  • Review stories + Chromatic diff to make sure visual updates are intended

@beaesguerra beaesguerra self-assigned this Jan 29, 2025
Copy link

changeset-bot bot commented Jan 29, 2025

🦋 Changeset detected

Latest commit: e57290b

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

This PR includes changesets to release 3 packages
Name Type
@khanacademy/wonder-blocks-cell Patch
@khanacademy/wonder-blocks-dropdown Patch
@khanacademy/wonder-blocks-birthday-picker Patch

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 Jan 29, 2025

Size Change: +151 B (+0.15%)

Total Size: 98.5 kB

Filename Size Change
packages/wonder-blocks-cell/dist/es/index.js 2.35 kB +151 B (+6.87%) 🔍
ℹ️ View Unchanged
Filename Size
packages/wonder-blocks-accordion/dist/es/index.js 3.77 kB
packages/wonder-blocks-banner/dist/es/index.js 1.53 kB
packages/wonder-blocks-birthday-picker/dist/es/index.js 1.77 kB
packages/wonder-blocks-breadcrumbs/dist/es/index.js 887 B
packages/wonder-blocks-button/dist/es/index.js 4.31 kB
packages/wonder-blocks-clickable/dist/es/index.js 3.06 kB
packages/wonder-blocks-core/dist/es/index.js 2.9 kB
packages/wonder-blocks-data/dist/es/index.js 6.24 kB
packages/wonder-blocks-dropdown/dist/es/index.js 18.9 kB
packages/wonder-blocks-form/dist/es/index.js 5.99 kB
packages/wonder-blocks-grid/dist/es/index.js 1.36 kB
packages/wonder-blocks-icon-button/dist/es/index.js 2.95 kB
packages/wonder-blocks-icon/dist/es/index.js 871 B
packages/wonder-blocks-labeled-field/dist/es/index.js 1.84 kB
packages/wonder-blocks-layout/dist/es/index.js 1.82 kB
packages/wonder-blocks-link/dist/es/index.js 2.28 kB
packages/wonder-blocks-modal/dist/es/index.js 5.42 kB
packages/wonder-blocks-pill/dist/es/index.js 1.65 kB
packages/wonder-blocks-popover/dist/es/index.js 4.88 kB
packages/wonder-blocks-progress-spinner/dist/es/index.js 1.52 kB
packages/wonder-blocks-search-field/dist/es/index.js 1.34 kB
packages/wonder-blocks-switch/dist/es/index.js 1.92 kB
packages/wonder-blocks-testing-core/dist/es/index.js 3.74 kB
packages/wonder-blocks-testing/dist/es/index.js 1.07 kB
packages/wonder-blocks-theming/dist/es/index.js 693 B
packages/wonder-blocks-timing/dist/es/index.js 1.8 kB
packages/wonder-blocks-tokens/dist/es/index.js 2.54 kB
packages/wonder-blocks-toolbar/dist/es/index.js 905 B
packages/wonder-blocks-tooltip/dist/es/index.js 6.99 kB
packages/wonder-blocks-typography/dist/es/index.js 1.23 kB

compressed-size-action

Copy link
Contributor

github-actions bot commented Jan 29, 2025

A new build was pushed to Chromatic! 🚀

https://5e1bf4b385e3fb0020b7073c-hgakpygect.chromatic.com/

Chromatic results:

Metric Total
Captured snapshots 19
Tests with visual changes 54
Total stories 536
Inherited (not captured) snapshots [TurboSnap] 0
Tests on the build 386

Comment on lines 232 to 243
const cellTokens = {
hover: {
background: color.fadedBlue8,
},
press: {
background: color.fadedBlue8,
},
selected: {
background: color.fadedBlue8,
foreground: color.activeBlue,
},
};
Copy link
Member Author

Choose a reason for hiding this comment

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

The semantic colors from our current action tokens don't apply to the cell:

  • the cell hover and press background is different
  • there is no selected state for actions currently

I've created this set of tokens for now so that we can swap it out later to support theming. All the usage of primitive colors in this component are consolidated to this object now! We could create new global semantic tokens for this, though I'm not sure if it would be useful for other things (this may be a one-off)

Let me know if there's something else I can do to help support the token work.

Copy link
Member

Choose a reason for hiding this comment

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

This is great! thanks a lot. I agree with you that this probably makes sense to keep it as component tokens for now.

@beaesguerra beaesguerra marked this pull request as ready for review January 29, 2025 23:59
@khan-actions-bot
Copy link
Contributor

Gerald

Required Reviewers
  • @Khan/wonder-blocks for changes to .changeset/new-seas-sin.md, packages/wonder-blocks-cell/src/components/internal/cell-core.tsx

Don't want to be involved in this pull request? Comment #removeme and we won't notify you of further changes.

@khan-actions-bot khan-actions-bot requested a review from a team January 29, 2025 23:59
Copy link
Contributor

github-actions bot commented Jan 30, 2025

npm Snapshot: Published

🎉 Good news!! We've packaged up the latest commit from this PR (1b649a0) and published all packages with changesets to npm.

You can install the packages in webapp by running:

./services/static/dev/tools/deploy_wonder_blocks.js --tag="PR2448"

Packages can also be installed manually by running:

yarn add @khanacademy/wonder-blocks-<package-name>@PR2448

Copy link
Member

@jandrade jandrade left a comment

Choose a reason for hiding this comment

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

This looks great! just a minor suggestion to build on top of your implementation to consider before merging.

Comment on lines 232 to 243
const cellTokens = {
hover: {
background: color.fadedBlue8,
},
press: {
background: color.fadedBlue8,
},
selected: {
background: color.fadedBlue8,
foreground: color.activeBlue,
},
};
Copy link
Member

Choose a reason for hiding this comment

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

This is great! thanks a lot. I agree with you that this probably makes sense to keep it as component tokens for now.

Comment on lines 247 to 248
background: semanticColor.surface.primary,
color: semanticColor.text.primary,
Copy link
Member

Choose a reason for hiding this comment

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

suggestion/thought: It's great that you created the cellTokens object. How do you feel about moving this to that object as I'm thinking this could go in the component theme object.

e.g.

const cellTokens = {
  default: {
    background: semanticColor.surface.primary,
    foreground: semanticColor.text.primary,
  },
  ...
};  

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated! I added more to cellTokens. I was going to move all the semantic token usage to cellTokens, though I wasn't sure about other things like the color for the icon since I haven't seen that in the other PRs. Let me know though what you think!

Copy link
Member

Choose a reason for hiding this comment

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

Great question! I'm curious to hear your thoughts on how to approach those tokens for the other elements in the component.

Copy link
Member Author

Choose a reason for hiding this comment

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

If we wanted to include other elements in the component tokens, we could have something like this:

const cellTokens = {
    default: {
        background: semanticColor.surface.primary,
        foreground: semanticColor.text.primary,
        icon: semanticColor.icon.primary, // <--
  },
  selected: {
        background: color.fadedBlue8,
        foreground: color.activeBlue,
        border: semanticColor.surface.emphasis,
        icon: semanticColor.icon.action,  // <--
    },
};  

I'm wondering now, what if there were multiple icons that are supposed to have different colors? Or maybe there's different text colors in the component? We could get more specific in the component tokens:

const componentTokens = {
    default: {
        background: semanticColor.surface.primary,
        foreground: semanticColor.text.primary,
        startIcon: semanticColor.icon.primary,
        endIcon: semanticColor.icon.primary,
        subtitle: semanticColor.text.secondary,
  },
};

But then, what about other non-color properties, like font size or border radius? We could normalize it so the elements are at the first level (option A) so it doesn't get to nested (option B)

// Option A
const componentTokens = {
  root: {
     default: { background: ..., foreground: ... },
     hover: { background: ..., foreground: ... },
     ...
  },
  leftIcon:  {
     default: { foreground: ..., height: ... },
     hover: { foreground: ..., height: ... },
  },
  subtitle: {
     default: { foreground: ..., fontSize: .... },
     hover: { foreground: ..., fontSize: .... },
  },
};

// Option B
const componentTokens = {
  root: {
     default: {
        background: ...,
        foreground: ...,
        leftIcon: {
           foreground: ...,
           height: ...,
        },
       subtitle: {
          foreground: ...,
          fontSize: ....
       }
    },
     hover: {
        background: ...,
        foreground: ...,
        leftIcon: {
           foreground: ...,
           height: ...,
        },
       subtitle: {
          foreground: ...,
          fontSize: ....
       }
    },
     ...
  },
};

Let me know what you think, happy to chat more about this!

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for your thinking on that! Both approaches are super valid, but I have a slight preference over A) as I think it makes easier to consume tokens dynamically. I feel that we currently don't have a defined structure for our component tokens (I mean every component is different), but maybe it is a good point to think about that.

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 updated the structure following option A! I moved all the semanticColor token usage to the cellTokens object. Let me know what you think!

@beaesguerra beaesguerra requested a review from jandrade January 30, 2025 19:01
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.

3 participants