Skip to content

[WB-1927]: Update wonder-blocks-typography to use rems #2532

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 32 commits into from
Apr 24, 2025
Merged

Conversation

marcysutton
Copy link
Member

@marcysutton marcysutton commented Apr 2, 2025

Summary:

Update wonder-blocks-typography component styles to use REMs for font-sizing and line-heights. This PR follows #2526 where the base font size was changed to 62.5%.

Issue: WB-1927, FEI-6534

Test plan:

  1. Open Chromatic build for this PR.
  2. Look for font-sizes and line-heights to stay the same at the default size, with a few exceptions:
    • BodySerifBlock now has a line-height of 24px (it was 28px before)
    • BodySerif now has a font-size of 16px and line-height of 20px to leverage t-shirt sizing (it was 18px / 22px before)
    • BodyMonospace now has a font-size of 16px and line-height of 20px (it was 17px / 22px before)
  3. Double-check TextArea min-height and Button-Core line-heights are computed with actual values
  4. Increase/decrease font-size in Chrome browser settings (Settings > Appearance > Font Size) and watch it change size.

Adjustments for REM sizing and reflow in webapp are covered under individual font-sizing issues: https://khanacademy.atlassian.net/issues/?jql=labels%20%3D%20%22webapp-font-sizing-rems%22

@marcysutton marcysutton self-assigned this Apr 2, 2025
Copy link

changeset-bot bot commented Apr 2, 2025

🦋 Changeset detected

Latest commit: 3b81908

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

This PR includes changesets to release 26 packages
Name Type
@khanacademy/wonder-blocks-tokens Major
@khanacademy/wonder-blocks-typography Minor
@khanacademy/wonder-blocks-button Patch
@khanacademy/wonder-blocks-form Patch
@khanacademy/wonder-blocks-accordion Patch
@khanacademy/wonder-blocks-banner Patch
@khanacademy/wonder-blocks-birthday-picker Patch
@khanacademy/wonder-blocks-breadcrumbs Patch
@khanacademy/wonder-blocks-cell Patch
@khanacademy/wonder-blocks-clickable Patch
@khanacademy/wonder-blocks-dropdown Patch
@khanacademy/wonder-blocks-grid Patch
@khanacademy/wonder-blocks-icon-button Patch
@khanacademy/wonder-blocks-labeled-field Patch
@khanacademy/wonder-blocks-layout Patch
@khanacademy/wonder-blocks-link Patch
@khanacademy/wonder-blocks-modal Patch
@khanacademy/wonder-blocks-pill Patch
@khanacademy/wonder-blocks-popover Patch
@khanacademy/wonder-blocks-progress-spinner Patch
@khanacademy/wonder-blocks-search-field Patch
@khanacademy/wonder-blocks-styles Patch
@khanacademy/wonder-blocks-switch Patch
@khanacademy/wonder-blocks-tabs Patch
@khanacademy/wonder-blocks-toolbar Patch
@khanacademy/wonder-blocks-tooltip 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

@khan-actions-bot
Copy link
Contributor

khan-actions-bot commented Apr 2, 2025

Gerald

Required Reviewers
  • @Khan/wonder-blocks for changes to pnpm-lock.yaml, .changeset/grumpy-ads-play.md, .changeset/sharp-pens-explode.md, .changeset/unlucky-clocks-cross.md, __docs__/_overview_.mdx, __docs__/wonder-blocks-tokens/tokens-font.mdx, packages/wonder-blocks-typography/package.json, packages/wonder-blocks-typography/tsconfig-build.json, static/sb-styles/preview.css, packages/wonder-blocks-tokens/src/index.ts, packages/wonder-blocks-button/src/components/button-core.tsx, packages/wonder-blocks-button/src/themes/default.ts, packages/wonder-blocks-form/src/components/text-area.tsx, packages/wonder-blocks-tokens/src/tokens/color.ts, packages/wonder-blocks-tokens/src/tokens/font.ts, packages/wonder-blocks-tokens/src/util/color-utils.ts, packages/wonder-blocks-tokens/src/util/index.ts, packages/wonder-blocks-tokens/src/util/sizing-utils.ts, packages/wonder-blocks-typography/src/util/styles.ts, packages/wonder-blocks-tokens/src/theme/primitive/border.ts, packages/wonder-blocks-tokens/src/theme/primitive/sizing.ts, packages/wonder-blocks-tokens/src/util/__tests__/color-utils.test.ts, packages/wonder-blocks-tokens/src/util/__tests__/sizing-utils.test.ts, packages/wonder-blocks-tokens/src/util/__tests__/__snapshots__/color-utils.test.ts.snap

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 April 2, 2025 17:31
Copy link
Contributor

github-actions bot commented Apr 2, 2025

Size Change: +71 B (+0.07%)

Total Size: 103 kB

Filename Size Change
packages/wonder-blocks-button/dist/es/index.js 3.96 kB -8 B (-0.2%)
packages/wonder-blocks-form/dist/es/index.js 6.04 kB +10 B (+0.17%)
packages/wonder-blocks-tokens/dist/es/index.js 3.2 kB +137 B (+4.47%)
packages/wonder-blocks-typography/dist/es/index.js 1.16 kB -68 B (-5.55%)
ℹ️ View Unchanged
Filename Size
packages/wonder-blocks-accordion/dist/es/index.js 3.56 kB
packages/wonder-blocks-announcer/dist/es/index.js 2.04 kB
packages/wonder-blocks-banner/dist/es/index.js 1.58 kB
packages/wonder-blocks-birthday-picker/dist/es/index.js 2.09 kB
packages/wonder-blocks-breadcrumbs/dist/es/index.js 886 B
packages/wonder-blocks-cell/dist/es/index.js 2.36 kB
packages/wonder-blocks-clickable/dist/es/index.js 3.12 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-dropdown/dist/es/index.js 19.7 kB
packages/wonder-blocks-grid/dist/es/index.js 1.36 kB
packages/wonder-blocks-icon-button/dist/es/index.js 2.27 kB
packages/wonder-blocks-icon/dist/es/index.js 873 B
packages/wonder-blocks-labeled-field/dist/es/index.js 1.26 kB
packages/wonder-blocks-layout/dist/es/index.js 1.82 kB
packages/wonder-blocks-link/dist/es/index.js 1.98 kB
packages/wonder-blocks-modal/dist/es/index.js 5.48 kB
packages/wonder-blocks-pill/dist/es/index.js 1.54 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-styles/dist/es/index.js 503 B
packages/wonder-blocks-switch/dist/es/index.js 1.9 kB
packages/wonder-blocks-tabs/dist/es/index.js 1.93 kB
packages/wonder-blocks-testing-core/dist/es/index.js 3.96 kB
packages/wonder-blocks-testing/dist/es/index.js 1.07 kB
packages/wonder-blocks-theming/dist/es/index.js 779 B
packages/wonder-blocks-timing/dist/es/index.js 1.79 kB
packages/wonder-blocks-toolbar/dist/es/index.js 923 B
packages/wonder-blocks-tooltip/dist/es/index.js 7.02 kB

compressed-size-action

Copy link
Contributor

github-actions bot commented Apr 2, 2025

A new build was pushed to Chromatic! 🚀

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

Chromatic results:

Metric Total
Captured snapshots 0
Tests with visual changes 0
Total stories 599
Inherited (not captured) snapshots [TurboSnap] 374
Tests on the build 374

Copy link
Contributor

github-actions bot commented Apr 2, 2025

npm Snapshot: Published

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

Packages can also be installed manually by running:

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

@marcysutton marcysutton force-pushed the FEI-4065-rems branch 4 times, most recently from ec5be22 to df07a46 Compare April 4, 2025 17:40
@marcysutton marcysutton changed the base branch from feature/scalable-sizing to main April 4, 2025 17:41
@marcysutton marcysutton changed the base branch from main to feature/scalable-sizing April 4, 2025 17:41
Base automatically changed from feature/scalable-sizing to main April 8, 2025 17:12
@marcysutton marcysutton changed the title [FEI-4065 - DO NOT MERGE]: Update wonder-blocks-typography to use rems [WB-1927]: Update wonder-blocks-typography to use rems Apr 15, 2025
@marcysutton
Copy link
Member Author

marcysutton commented Apr 15, 2025

I got this PR ready to review by decoupling other work from it, namely updating REMs in webapp! The direct work that will follow this PR is integrating these wonder-blocks- package updates in webapp. Hard-coded pixel font-sizing and WB typography theming will be whole other workstreams.

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.

Thanks for introducing this change! As you are modifying these components, I think it would be great refactoring the typography styles to use font tokens instead, and then modifying font tokens to use the new sizing values.

Comment on lines 27 to 28
fontSize: sizing.size_360,
lineHeight: sizing.size_400,
Copy link
Member

Choose a reason for hiding this comment

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

suggestion: This is something that I never did when creating the font tokens, but I think it would be better to change these styles to use font tokens directly, then change those tokens to map to the sizing tokens instead. That way consumers that use the font tokens would benefit from this change as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

Cool, makes sense! I'll take a look.

Copy link
Member Author

@marcysutton marcysutton Apr 16, 2025

Choose a reason for hiding this comment

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

Related question on one-off tokens for these: https://github.com/Khan/wonder-blocks/pull/2532/files#r2047554570

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.

I agree with Juan's feedback! Left some questions too 😄

xxLarge: sizing.size_280,
xLarge: sizing.size_240,
large: sizing.size_200,
medium: sizing.size_160,
Copy link
Member Author

@marcysutton marcysutton Apr 16, 2025

Choose a reason for hiding this comment

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

This one will need to change in a TB theme file: Foundations uses sizing.size_180 for medium: https://www.figma.com/design/9seilz0fBgo3QUj6eXM0yR/%E2%9A%A1%EF%B8%8F-Foundations?node-id=52-3&t=NFXovVlCFbYhQHvm-0

I'll check for others when I get to that part (in a future PR).

Copy link
Member

Choose a reason for hiding this comment

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

Agreed! you might want to look at the CSS vars refactor that I've been doing + the TB theming PR, as probably most of this stuff will get moved to the theme/ folder to convert these tokens as CSS variables + create the tb version of these tokens. We can chat later about this!

@@ -0,0 +1,6 @@
---
"@khanacademy/wonder-blocks-typography": minor
"@khanacademy/wonder-blocks-tokens": minor
Copy link
Member Author

Choose a reason for hiding this comment

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

Should these be majors as some of the font-sizes are changing? Or just minor?

Copy link
Member

Choose a reason for hiding this comment

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

IMO it should be minor if only the values change. If the font structure changes (public API), then that could be considered as a breaking change.

TBH this is the kind of situation were any option could work :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Alright, I'll leave it as-is!

Copy link
Member

Choose a reason for hiding this comment

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

Since we are using sizing tokens now for the font.size and font.lineHeight tokens, the token values will be strings now including the rem unit, instead of the numeric value. Would this be a breaking change since something like fontSize: ${font.size.small}px would need to be updated so it doesn't become font-size: 1.4rempx?

(Or, depending on if the css variable changes are released first, it'd become font-size: var(--wb-token-name)px)

Copy link
Member Author

Choose a reason for hiding this comment

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

Great question. That does seem breaking to me as it will have to be updated at the call-sites to prevent an issue. I see numerous instances of px added after font.size and font.lineHeight tokens in webapp!

fontFamily: font.family.serif,
fontWeight: font.weight.regular,
fontSize: font.size.large,
lineHeight: font.lineHeight.large,
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: Because the font-size was changed to 20px for BodySerifBlock, I updated the line height to match the scale (24px).

lineHeight: "22px",
fontFamily: font.family.mono,
fontWeight: font.weight.regular,
fontSize: font.size.medium,
Copy link
Member Author

@marcysutton marcysutton Apr 16, 2025

Choose a reason for hiding this comment

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

Note: 17px isn't on our REM scale. Rather than use a one-off value, I converted BodyMonospace to font.size.medium (16px).

fontFamily: font.family.mono,
fontWeight: font.weight.regular,
fontSize: font.size.medium,
lineHeight: font.lineHeight.medium,
Copy link
Member Author

@marcysutton marcysutton Apr 16, 2025

Choose a reason for hiding this comment

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

Note: 22px also isn't on our REM scale so I converted BodyMonospace to font.lineHeight.medium (20px)

For Font-size: large or extra-large, the -64px margin on `<main>` was cutting off the h1 on the overview page. I decreased the top padding instead, as an experiment. We could add padding back in to other pages, if they need it.
…REMs instead of pixels for user-scalable font-sizing and line-heights.
Also exports utility functions for converting between Pixels and REMs
…font tokens with REM units instead of pixels for user-scalable font-sizing and line-heights.
@marcysutton marcysutton merged commit b9e4946 into main Apr 24, 2025
14 checks passed
@marcysutton marcysutton deleted the FEI-4065-rems branch April 24, 2025 19:34
Copy link

codecov bot commented Apr 24, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 0.00%. Comparing base (aef4e56) to head (3b81908).
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

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

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 aef4e56...3b81908. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

4 participants