Repository navigation
Font Library: Fix the preview weight for variable fonts #81748
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
8 commits
Select commit
Hold shift + click to select a range
c413113
Add `resolveFontWeight` to resolve variable font weight ranges to a s…
juanfra 6020f4f
Migrate from text component off to span and update the suppressions f…
juanfra b290ef2
Add changelog entry.
juanfra 4b60c09
Resolve the font weight keywords to numbers and fall back to 400 for …
juanfra 59c73e6
Reuse `resolveFontWeight` for the family preview and remove `extractF…
juanfra 7ced102
Add tests for the font library preview.
juanfra fd05150
Merge branch 'trunk' into try/font-demo-variable-weight
juanfra c2e589c
Merge branch 'trunk' into try/font-demo-variable-weight
juanfra 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
There are no files selected for viewing
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
55 changes: 55 additions & 0 deletions
55
packages/global-styles-ui/src/font-library/utils/test/preview-styles.js
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,55 @@ | ||
| import { getFacePreviewStyle, getFamilyPreviewStyle } from '../preview-styles'; | ||
|
|
||
| describe( 'getFacePreviewStyle', () => { | ||
| it.each( [ | ||
| [ '700', '700' ], | ||
| [ '200 900', '400' ], | ||
| [ '500 900', '500' ], | ||
| [ '100 300', '300' ], | ||
| [ 'bold', '700' ], | ||
| [ '500 bold', '500' ], | ||
| [ 'auto', '400' ], | ||
| [ undefined, '400' ], | ||
| ] )( 'resolves %p to %p', ( fontWeight, expected ) => { | ||
| expect( | ||
| getFacePreviewStyle( { fontFamily: 'Inter', fontWeight } ) | ||
| ).toEqual( expect.objectContaining( { fontWeight: expected } ) ); | ||
| } ); | ||
| } ); | ||
|
|
||
| describe( 'getFamilyPreviewStyle', () => { | ||
| it( 'resolves the range of the normal faces', () => { | ||
| expect( | ||
| getFamilyPreviewStyle( { | ||
| fontFamily: 'Inter', | ||
| fontFace: [ { fontStyle: 'normal', fontWeight: '150 700' } ], | ||
| } ) | ||
| ).toEqual( expect.objectContaining( { fontWeight: '400' } ) ); | ||
| } ); | ||
|
|
||
| it( 'picks the weight closest to regular across the normal faces', () => { | ||
| expect( | ||
| getFamilyPreviewStyle( { | ||
| fontFamily: 'Inter', | ||
| fontFace: [ | ||
| { fontStyle: 'normal', fontWeight: '700' }, | ||
| { fontStyle: 'normal', fontWeight: '500' }, | ||
| ], | ||
| } ) | ||
| ).toEqual( expect.objectContaining( { fontWeight: '500' } ) ); | ||
| } ); | ||
|
|
||
| it( 'falls back to the first face when none are normal', () => { | ||
| expect( | ||
| getFamilyPreviewStyle( { | ||
| fontFamily: 'Inter', | ||
| fontFace: [ { fontStyle: 'italic', fontWeight: '200 900' } ], | ||
| } ) | ||
| ).toEqual( | ||
| expect.objectContaining( { | ||
| fontStyle: 'italic', | ||
| fontWeight: '400', | ||
| } ) | ||
| ); | ||
| } ); | ||
| } ); |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need to support non-numerical values like
boldorauto?It might be a good idea to have unit tests for this function.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch!
autowas going through. Added a few guardrails now for that with keyword mapping and fallbacks.Added tests here 7ced102