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

[WB-1814.10] Refactor wonder-blocks-dropdown to use semantic colors #2474

Merged
merged 8 commits into from
Feb 20, 2025

Conversation

jandrade
Copy link
Member

@jandrade jandrade commented Feb 17, 2025

Summary:

Last PR that migrates the remaining components to use semantic colors.

  • Added All Variants stories to ActionItem and OptionItem.
  • Refactored ActionItem and OptionItem to use semantic colors.
  • Also refactored ActionMenu, SingleSelect, MultiSelect and Combobox to
    use semantic colors.
  • Simplified the styles in ActionMenuOpenerCore to use a single static
    StyleSheet instance (instead of generating another one in runtime).

Implementation plan:

  1. [WB-1814.1] Refactor Checkbox and Radio to use semantic colors #2439
  2. [WB-1814.2] Refactor TextField and TextArea to use semantic colors #2440
  3. [WB-1814.3] Refactor Switch to use semantic colors #2441
  4. [WB-1814.4] Refactor Accordion, Banner, BirthdayPicker to use semantic colors #2446
  5. [WB-1814.5] Refactor IconButton to use semantic colors #2449
  6. [WB-1814.6] Refactor Link to use semantic colors #2464
  7. [WB-1814.7] Refactor Modal to use semantic colors #2468
  8. [WB-1814.8] Refactor Popover, Tooltip, Toolbar to use semantic colors #2470
  9. [WB-1814.9] Refactor Clickable and Pill to use semantic colors #2472
  10. Dropdown (current PR)

Issue: WB-1814

Test plan:

Verify that all the dropdown stories are still working as expected.

@jandrade jandrade self-assigned this Feb 17, 2025
Copy link

changeset-bot bot commented Feb 17, 2025

🦋 Changeset detected

Latest commit: d71e95d

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

This PR includes changesets to release 2 packages
Name Type
@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 Feb 17, 2025

Size Change: +433 B (+0.44%)

Total Size: 98 kB

Filename Size Change
packages/wonder-blocks-dropdown/dist/es/index.js 19.5 kB +433 B (+2.27%)
ℹ️ View Unchanged
Filename Size
packages/wonder-blocks-accordion/dist/es/index.js 3.54 kB
packages/wonder-blocks-banner/dist/es/index.js 1.55 kB
packages/wonder-blocks-birthday-picker/dist/es/index.js 1.82 kB
packages/wonder-blocks-breadcrumbs/dist/es/index.js 886 B
packages/wonder-blocks-button/dist/es/index.js 4.3 kB
packages/wonder-blocks-cell/dist/es/index.js 2.01 kB
packages/wonder-blocks-clickable/dist/es/index.js 3.05 kB
packages/wonder-blocks-core/dist/es/index.js 2.85 kB
packages/wonder-blocks-data/dist/es/index.js 6.25 kB
packages/wonder-blocks-form/dist/es/index.js 6.03 kB
packages/wonder-blocks-grid/dist/es/index.js 1.36 kB
packages/wonder-blocks-icon-button/dist/es/index.js 3.11 kB
packages/wonder-blocks-icon/dist/es/index.js 873 B
packages/wonder-blocks-labeled-field/dist/es/index.js 1.22 kB
packages/wonder-blocks-layout/dist/es/index.js 1.82 kB
packages/wonder-blocks-link/dist/es/index.js 2.22 kB
packages/wonder-blocks-modal/dist/es/index.js 5.5 kB
packages/wonder-blocks-pill/dist/es/index.js 1.48 kB
packages/wonder-blocks-popover/dist/es/index.js 4.92 kB
packages/wonder-blocks-progress-spinner/dist/es/index.js 1.52 kB
packages/wonder-blocks-search-field/dist/es/index.js 1.33 kB
packages/wonder-blocks-switch/dist/es/index.js 2 kB
packages/wonder-blocks-testing-core/dist/es/index.js 3.73 kB
packages/wonder-blocks-testing/dist/es/index.js 1.07 kB
packages/wonder-blocks-theming/dist/es/index.js 679 B
packages/wonder-blocks-timing/dist/es/index.js 1.79 kB
packages/wonder-blocks-tokens/dist/es/index.js 2.51 kB
packages/wonder-blocks-toolbar/dist/es/index.js 923 B
packages/wonder-blocks-tooltip/dist/es/index.js 7.01 kB
packages/wonder-blocks-typography/dist/es/index.js 1.23 kB

compressed-size-action

Copy link
Contributor

github-actions bot commented Feb 17, 2025

A new build was pushed to Chromatic! 🚀

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

Chromatic results:

Metric Total
Captured snapshots 90
Tests with visual changes 0
Total stories 563
Inherited (not captured) snapshots [TurboSnap] 291
Tests on the build 381

background: offBlack,
},
color: theme.hover.foreground,
background: theme.hover.background,
},
Copy link
Member Author

Choose a reason for hiding this comment

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

note: I removed this as it is no longer needed. I checked other popular design systems in the industry and all of them preserve the hover state on mobile devices, so we just let the browsers decide how to apply these styles from now on.


const styles: Record<string, any> = {};

const _generateStyles = (localColor: string) => {
Copy link
Member Author

Choose a reason for hiding this comment

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

note: This was overhead, so I simplified these styles by moving them to the StyleSheet definition above.

@jandrade jandrade marked this pull request as ready for review February 18, 2025 16:12
@khan-actions-bot khan-actions-bot requested a review from a team February 18, 2025 16:13
@khan-actions-bot
Copy link
Contributor

khan-actions-bot commented Feb 18, 2025

Gerald

Required Reviewers
  • @Khan/wonder-blocks for changes to .changeset/seven-mangos-drive.md, .storybook/preview.tsx, __docs__/wonder-blocks-dropdown/action-item-variants.stories.tsx, __docs__/wonder-blocks-dropdown/action-item.stories.tsx, __docs__/wonder-blocks-dropdown/action-menu.stories.tsx, __docs__/wonder-blocks-dropdown/combobox.stories.tsx, __docs__/wonder-blocks-dropdown/listbox.stories.tsx, __docs__/wonder-blocks-dropdown/multi-select.stories.tsx, __docs__/wonder-blocks-dropdown/option-item-variants.stories.tsx, __docs__/wonder-blocks-dropdown/option-item.stories.tsx, __docs__/wonder-blocks-dropdown/single-select.stories.tsx, packages/wonder-blocks-dropdown/src/components/action-item.tsx, packages/wonder-blocks-dropdown/src/components/action-menu-opener-core.tsx, packages/wonder-blocks-dropdown/src/components/checkbox.tsx, packages/wonder-blocks-dropdown/src/components/combobox-multiple-selection.tsx, packages/wonder-blocks-dropdown/src/components/combobox.tsx, packages/wonder-blocks-dropdown/src/components/dropdown-core.tsx, packages/wonder-blocks-dropdown/src/components/listbox.tsx, packages/wonder-blocks-dropdown/src/components/option-item.tsx, packages/wonder-blocks-dropdown/src/components/select-opener.tsx, packages/wonder-blocks-dropdown/src/components/separator-item.tsx

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

Copy link
Contributor

github-actions bot commented Feb 18, 2025

npm Snapshot: Published

🎉 Good news!! We've packaged up the latest commit from this PR (c61daab) 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="PR2474"

Packages can also be installed manually by running:

pnpm add @khanacademy/wonder-blocks-<package-name>@PR2474

Copy link
Member

@beaesguerra beaesguerra left a comment

Choose a reason for hiding this comment

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

Yay last one! Thanks for all of your work on updating our components to use semantic color tokens 😄 I left some non-blocking questions in the PR!

props: {disabled: true},
},
{
name: "Custon label",
Copy link
Member

Choose a reason for hiding this comment

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

nit: typo!

Suggested change
name: "Custon label",
name: "Custom label",

(Story): React.ReactElement<React.ComponentProps<typeof View>> => (
<View
style={{
background: semanticColor.surface.secondary,
Copy link
Member

Choose a reason for hiding this comment

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

What do you think about using the Storybook background control to set the background instead? That way, if we need to, we can change the background color when testing to see how it looks with other backgrounds! https://storybook.js.org/docs/essentials/backgrounds

Comment on lines 177 to 184
hover: {
background: semanticColor.action.filled.progressive.hover.background,
foreground: semanticColor.action.filled.progressive.hover.foreground,
},
press: {
background: semanticColor.action.filled.progressive.press.background,
foreground: semanticColor.action.filled.progressive.press.foreground,
},
Copy link
Member

Choose a reason for hiding this comment

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

I would have thought that this would use the outlined tokens since in it's rest state, it looks more like the outlined styles than filled (it is still a bit different though)! How do we decide if we should use the filled or outlined styles?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ugh I know. This is one of these inconsistencies that we should address very soon.

https://www.figma.com/design/VbVu3h2BpBhH80niq101MHHE/%F0%9F%92%A0-Main-Components?node-id=11266-7343&t=KYvBjNOhKAcin5zT-4

Screenshot 2025-02-18 at 3 26 12 PM

@@ -122,8 +119,13 @@ const sharedStyles = StyleSheet.create({
WebkitTapHighlightColor: "rgba(0,0,0,0)",
},
},
default: {
background: "none",
Copy link
Member

Choose a reason for hiding this comment

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

Should a background of none be tokenized?

Copy link
Member Author

Choose a reason for hiding this comment

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

Probably yes (will ask Caitlyn about this), but that's something that I'm going to address as soon as I add theming support to dropdowns. https://khanacademy.atlassian.net/browse/WB-1868

disabled: {
cursor: "auto",
color: semanticColor.action.disabled.default,
cursor: "default",
Copy link
Member

Choose a reason for hiding this comment

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

Do we use the not-allowed cursor on disabled states?

@@ -69,16 +67,16 @@ const styles = StyleSheet.create({
borderRadius: 3,
borderWidth: 1,
borderStyle: "solid",
borderColor: offBlack50,
borderColor: semanticColor.border.strong,
Copy link
Member

Choose a reason for hiding this comment

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

Out of curiosity, should the Checkbox in the dropdown always have the same style as the Checkbox component from the form package? Would it make sense to share styles between the 2? Or let them each evolve on their own?

If they should always be the same styles, another alternative could be to use the Checkbox component from the form package directly!

Copy link
Member Author

Choose a reason for hiding this comment

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

Good question! I think both need to be separate in terms of semantics and styling. This dropdown checkbox is not focusable/interactive, and instead it is more decorative in the sense that is meant to present a selected/unselected state in the current option item. Another difference is that the form one has a focused style (outline ring) where as this does not include that as the focus is set in the option item element.

Comment on lines 708 to 710
background: semanticColor.action.disabled.secondary,
border: `1px solid ${semanticColor.border.primary}`,
color: semanticColor.text.secondary,
Copy link
Member

Choose a reason for hiding this comment

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

Do you think it would be helpful to follow the background/foreground/outline structure for the primary and secondary disabled action tokens? So that the 3 tokens are always used together!

Copy link
Member Author

Choose a reason for hiding this comment

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

Could you please elaborate on this? would it be to add disabled in outlined and filled?

FYI I moved these tokens for now to a theme object that I'll later move to a dropdown theme file.

Copy link
Member

Choose a reason for hiding this comment

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

Sure! For other action colors, we have (for example)semanticColor.action.filled.progressive.default which has

  • border
  • background
  • foreground

We define the 3 properties for other states and variants. I'm wondering if it would be helpful to have border, background, and foreground for the disabled actions too.

// Before (shows part of the semantic color token structure)
const action = {
  disabled: {
    default: color.fadedOffBlack32,
    secondary: color.offWhite,
  }
}

// After (default and secondary are expanded)
const action = {
  disabled: {
    default: {
      background: color.fadedOffBlack32,
      foreground: semanticColor.text.inverse,
      border: semanticColor.border.primary,
    },
    secondary: {
      background: color.offWhite,
      foreground: semanticColor.text.secondary,
      border: semanticColor.border.primary,
    },
}

Then applying the disabled action tokens would look like:

const styles = {
  disabled: {
        background: semanticColor.action.disabled.secondary.background,
        border: `1px solid ${semanticColor.action.disabled.secondary.border}`,
        color: semanticColor.action.disabled.secondary.foreground,
  }
}

Grouping the foreground, background and border together at the semantic tokens level could help make sure the correct values are used together so that they have enough color contrast (and for consistency)!

Copy link
Member Author

Choose a reason for hiding this comment

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

Ohh I see, thanks! yeah that makes a lot of sense :)

In fact, Design is taking a similar approach. I'm going to discuss with Caitlyn how we are going to align with these tokens and add this change in a separate PR. I'll add a TODO comment for now.

Screenshot 2025-02-20 at 1 45 55 PM

Copy link
Member Author

Choose a reason for hiding this comment

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

},
hover: {
background:
semanticColor.action.filled.progressive.hover.background,
Copy link
Member

Choose a reason for hiding this comment

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

Same question about filled vs outlined tokens!

semanticColor.action.filled.progressive.press.foreground,
},
disabled: {
background: "transparent",
Copy link
Member

Choose a reason for hiding this comment

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

Should we create a color token for transparent?

foreground: semanticColor.text.disabled,
},
},
checkbox: {
Copy link
Member

Choose a reason for hiding this comment

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

Same question about if checkbox styles need to stay in sync with the Checkbox component from the form package!

Copy link
Member

@beaesguerra beaesguerra left a comment

Choose a reason for hiding this comment

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

Looks good to me! Thanks for adding the TODOs :)

@jandrade jandrade merged commit 4ab523b into main Feb 20, 2025
14 checks passed
@jandrade jandrade deleted the semantic-dropdown branch February 20, 2025 20:07
Copy link

codecov bot commented Feb 20, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 0.00%. Comparing base (8fc65a9) to head (d71e95d).
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@     Coverage Diff      @@
##   main   #2474   +/-   ##
============================
============================

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8fc65a9...d71e95d. Read the comment docs.

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