-
Notifications
You must be signed in to change notification settings - Fork 872
Charts: Replace hardcoded typography with WPDS design tokens #47989
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
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
fc050c9
Charts: Replace hardcoded typography with WPDS design tokens
cursoragent 7fdf5b0
Charts: Remove CSS Custom Properties docs section from conversion funnel
cursoragent 6da627d
Charts: Simplify font-family fallback to just sans-serif
cursoragent 3be6ee8
Charts: Remove redundant font-family from child selectors in conversi…
cursoragent a3a5f8f
Charts: Revert bold/semibold weights to hardcoded values
cursoragent 92cb1fd
Charts: Align all font-weights to WPDS design system tokens
cursoragent 25a52e5
Charts: Add font-family token to the root selector of every chart
cursoragent 3d809a6
Charts: Remove fontFamily from svgLabelSmall theme property
cursoragent e4de571
Charts: Fix PieChart label background sizing to use full theme typogr…
adamwoodnz b2a0941
Charts: Restore backward compat for deprecated funnel font-family vars
adamwoodnz 5111668
Charts: Consolidate changelog into single entry for this PR
adamwoodnz 2442d34
Charts: Inherit font-family from host app instead of declaring it on …
adamwoodnz 5e99b6e
Charts: Scope Storybook WPDS body font to charts stories only
adamwoodnz f8be364
Charts: Move WPDS font-family host wrapper into the charts story deco…
adamwoodnz 034edd4
Charts: Extract resolveFontSize into a shared utility
adamwoodnz 079ced1
Charts: Override visx SVG label font-family with inherit
adamwoodnz cc4f37d
Charts: Drop system-ui from Storybook host font fallback
adamwoodnz eaf6d2a
Charts: Standardize --wpds-font-size-md fallback to 13px
adamwoodnz 046738f
Charts: Tighten resolveFontSize parsing and add unit tests
adamwoodnz 8f9618c
Charts: Drop id="app" from Storybook chart decorator wrapper
adamwoodnz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
projects/js-packages/charts/changelog/charts-typography-tokenization
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| Significance: minor | ||
| Type: changed | ||
|
|
||
| Replace hardcoded typography values with WPDS design tokens for font family, size, weight, and line height. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
projects/js-packages/charts/src/utils/resolve-font-size.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| /** | ||
| * Resolve a theme `fontSize` value into a plain number suitable for | ||
| * canvas-based measurement (e.g. `getStringWidth`). | ||
| * | ||
| * Accepts: | ||
| * - A number — returned as-is | ||
| * - A pixel string like `"12px"` — parsed and returned as a number | ||
| * | ||
| * Returns `undefined` for any other input (missing value, NaN, or | ||
| * relative units like `rem`/`em`/`%`/`vh`) so callers can fall back to | ||
| * their own default. Relative units are intentionally rejected because | ||
| * we cannot resolve them to absolute pixels here without a parent | ||
| * computed style, and silently returning the unitless prefix | ||
| * (`parseFloat("0.875rem") === 0.875`) would produce nearly-zero | ||
| * widths in measurement code. | ||
| * @param val - Raw font size value from a theme, axis style, or props | ||
| * @return Parsed numeric font size in pixels, or `undefined` when unresolvable | ||
| */ | ||
| export const resolveFontSize = ( val?: number | string ): number | undefined => { | ||
| if ( typeof val === 'number' ) { | ||
| return isNaN( val ) ? undefined : val; | ||
| } | ||
|
|
||
| if ( typeof val === 'string' ) { | ||
| // Only accept plain numeric strings or pixel values. | ||
| // Reject rem, em, %, vh, vw, etc. — they cannot be resolved to | ||
| // absolute pixels without a computed style context. | ||
| const match = val.trim().match( /^(-?\d+\.?\d*|-?\.\d+)(px)?$/ ); | ||
| if ( ! match ) { | ||
| return undefined; | ||
| } | ||
| const parsed = parseFloat( match[ 1 ] ); | ||
| return isNaN( parsed ) ? undefined : parsed; | ||
| } | ||
|
|
||
| return undefined; | ||
| }; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.