-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
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
[material-ui][joy-ui] Generate typography tokens #41703
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
bcfadca
add typography extraction
siriwatknp bce880b
add typography tokens to Joy
siriwatknp 470ae1b
remove typography related tests
siriwatknp a5f56de
Merge branch 'next' of https://github.com/mui/material-ui into system…
siriwatknp 8a5e707
fix types
siriwatknp ae319a9
cast to any to prevent internal module augmentation
siriwatknp 7e3a645
add comment
siriwatknp 06741dc
Merge branch 'next' of https://github.com/mui/material-ui into system…
siriwatknp 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 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 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 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 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 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 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 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 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 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 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 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
25 changes: 25 additions & 0 deletions
25
packages/mui-system/src/cssVars/prepareTypographyVars.test.ts
This file contains 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,25 @@ | ||
import { expect } from 'chai'; | ||
import { createTheme } from '@mui/material/styles'; | ||
import prepareTypographyTokens from './prepareTypographyVars'; | ||
|
||
describe('prepareTypographyVars', () => { | ||
it('should prepare typography vars', () => { | ||
const theme = createTheme(); | ||
expect(prepareTypographyTokens(theme.typography)).to.deep.equal({ | ||
body1: '400 1rem/1.5 "Roboto", "Helvetica", "Arial", sans-serif', | ||
body2: '400 0.875rem/1.43 "Roboto", "Helvetica", "Arial", sans-serif', | ||
button: '500 0.875rem/1.75 "Roboto", "Helvetica", "Arial", sans-serif', | ||
caption: '400 0.75rem/1.66 "Roboto", "Helvetica", "Arial", sans-serif', | ||
h1: '300 6rem/1.167 "Roboto", "Helvetica", "Arial", sans-serif', | ||
h2: '300 3.75rem/1.2 "Roboto", "Helvetica", "Arial", sans-serif', | ||
h3: '400 3rem/1.167 "Roboto", "Helvetica", "Arial", sans-serif', | ||
h4: '400 2.125rem/1.235 "Roboto", "Helvetica", "Arial", sans-serif', | ||
h5: '400 1.5rem/1.334 "Roboto", "Helvetica", "Arial", sans-serif', | ||
h6: '500 1.25rem/1.6 "Roboto", "Helvetica", "Arial", sans-serif', | ||
inherit: 'inherit inherit/inherit inherit', | ||
overline: '400 0.75rem/2.66 "Roboto", "Helvetica", "Arial", sans-serif', | ||
subtitle1: '400 1rem/1.75 "Roboto", "Helvetica", "Arial", sans-serif', | ||
subtitle2: '500 0.875rem/1.57 "Roboto", "Helvetica", "Arial", sans-serif', | ||
}); | ||
}); | ||
}); |
This file contains 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,18 @@ | ||
type RecordPropertyNames<T> = { | ||
[K in keyof T]: T[K] extends Function ? never : T[K] extends Record<string, any> ? K : never; | ||
}[keyof T]; | ||
|
||
export type ExtractTypographyTokens<T> = { [K in RecordPropertyNames<T>]: string }; | ||
|
||
export default function prepareTypographyTokens<T extends Record<string, any>>(typography: T) { | ||
const vars: Record<string, string | number> = {}; | ||
const entries = Object.entries(typography); | ||
entries.forEach((entry) => { | ||
const [key, value] = entry; | ||
if (typeof value === 'object') { | ||
vars[key] = | ||
`${value.fontStyle ? `${value.fontStyle} ` : ''}${value.fontVariant ? `${value.fontVariant} ` : ''}${value.fontWeight ? `${value.fontWeight} ` : ''}${value.fontStretch ? `${value.fontStretch} ` : ''}${value.fontSize || ''}${value.lineHeight ? `/${value.lineHeight} ` : ''}${value.fontFamily || ''}`; | ||
} | ||
}); | ||
return vars as ExtractTypographyTokens<T>; | ||
} |
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.
Why is this redefined here as well as here: https://github.com/mui/material-ui/pull/41703/files#diff-158304f3a4b17f65c8bd9dd688681ae17e38aa6da3cabaaa8bbaae0a41948710R608?
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.
Let me clarify, it is redefined to preserve the same behavior as the developers passed the typography in.
In line 608, the typography is configured by
prepareTypographyVars
so that the generated token is in the format offont: …
.At the end, before the theme is return, the original
typography
object is redefined back so that this behavior remains the same: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.
So, line 608 adds the
theme.vars.typography...
values?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.
Not really, line 608 builds up the typography structure so that
prepareCssVars
at line 667 generates thevars.typography
based on that structure.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.
Thanks for the explanation!