-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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
Conversation
Netlify deploy previewhttps://deploy-preview-41703--material-ui.netlify.app/ packages/material-ui/material-ui.production.min.js: parsed: +0.08% , gzip: +0.06% Bundle size reportDetails of bundle changes (Toolpad) |
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.
Looks good! Just have one question:
@@ -675,6 +677,7 @@ export default function extendTheme(themeOptions?: CssVarsThemeOptions): Theme { | |||
return createSpacing(spacing, createUnarySpacing(this)); | |||
}; | |||
theme.spacing = theme.generateSpacing(); | |||
theme.typography = mergedScales.typography as any; // cast to `any` to avoid internal module augmentation in the repo. |
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 of font: …
.
prepareTypographyVars({ h1: { fontFamily: …, fontSize: …, lineHeight: …, fontWeight: … }})
// { h1: "…valid CSS `font` value", …other typography }
At the end, before the theme is return, the original typography
object is redefined back so that this behavior remains the same:
styled('div')({ theme }) => ({
…theme.typography.h1,
})
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 the vars.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!
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.
Nicely done 🚀
Part of #40225
closes #39677
mui-typography-tokens.mp4
Typography is the last piece for generating CSS theme variables. It's almost perfect (the limitation is on the CSS side) with CSS
font
property which is a shorthand forfont-family, font-size, font-style font-weight, line-height
(exceptletter-spacing
).Now typography token can be accessed from
theme.vars.typography.*
.How it works
MUI system provides a
prepareTypographyTokens
to convert typography objects into CSS font values.