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.5] Refactor IconButton to use semantic colors #2449

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

jandrade
Copy link
Member

@jandrade jandrade commented Jan 30, 2025

Summary:

Next step is to refactor the IconButton component to use semantic colors.

Besides the migration, this PR also includes the following changes:

  • Reworked the theme structure to make it closer to the semanticColor structure.
  • Moved all the color-related CSS properties to a separate function (getStylesByKind).
  • Added border to all the states to prepare the work for Polaris as these
    icon buttons will look similar to the Button ones.

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. IconButton (current PR)
  6. Clickable, Link
  7. Modal
  8. Popover, Tooltip
  9. Pill, Toolbar

Issue: WB-1814

Test plan:

Verify that the Chromatic snapshots are unchanged.

URL: /?path=/story/packages-iconbutton-all-variants--default

@jandrade jandrade self-assigned this Jan 30, 2025
Copy link

changeset-bot bot commented Jan 30, 2025

🦋 Changeset detected

Latest commit: d6ca781

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

This PR includes changesets to release 8 packages
Name Type
@khanacademy/wonder-blocks-icon-button Patch
@khanacademy/wonder-blocks-banner Patch
@khanacademy/wonder-blocks-modal Patch
@khanacademy/wonder-blocks-popover Patch
@khanacademy/wonder-blocks-search-field Patch
@khanacademy/wonder-blocks-dropdown Patch
@khanacademy/wonder-blocks-tooltip 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 30, 2025

Size Change: +169 B (+0.17%)

Total Size: 98.3 kB

Filename Size Change
packages/wonder-blocks-icon-button/dist/es/index.js 3.12 kB +169 B (+5.73%) 🔍
ℹ️ 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-cell/dist/es/index.js 2.01 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/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.85 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 30, 2025

A new build was pushed to Chromatic! 🚀

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

Chromatic results:

Metric Total
Captured snapshots 228
Tests with visual changes 0
Total stories 530
Inherited (not captured) snapshots [TurboSnap] 152
Tests on the build 380

Comment on lines +220 to +224
buttonColor: ButtonColor,
disabled: boolean,
kind: Kind,
light: boolean,
buttonColor: string,
theme: IconButtonThemeContract,
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: Just reordered the arguments alphabetically.

) {
switch (kind) {
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: Changed from switch to if as constants cannot be redefined within switch statements. I did this as I wanted to be able to reuse const themeVariant etc for better readability.

}

const _generateStyles = (
buttonColor = "default",
kind: "primary" | "secondary" | "tertiary",
buttonColor: ButtonColor = "default",
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: Same here related to reordering args alphabetically.

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: Modified the structure to make it really closer to semanticColor.action. Note that this time used primary, secondary, etc instead of filled, outlinedto be able to map the keys to the props defined inIconButton(e.g.kind="primary"`). Still undecided with which approach to take. Any thoughts are completely welcome!

@jandrade jandrade marked this pull request as ready for review January 30, 2025 21:54
@khan-actions-bot
Copy link
Contributor

Gerald

Required Reviewers
  • @Khan/wonder-blocks for changes to .changeset/sixty-jars-guess.md, __docs__/wonder-blocks-icon-button/icon-button-variants.stories.tsx, packages/wonder-blocks-icon-button/src/components/icon-button-core.tsx, packages/wonder-blocks-icon-button/src/themes/default.ts, packages/wonder-blocks-icon-button/src/themes/khanmigo.ts

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 30, 2025 21:55
Copy link
Contributor

npm Snapshot: Published

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

Packages can also be installed manually by running:

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

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.

2 participants