-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
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
[system] Add unstable_createCssVarsProvider
api
#28965
Conversation
@material-ui/system: parsed: +5.81% , gzip: +5.80% |
…al-ui into feat/css-vars-provider
}, | ||
}; | ||
|
||
export const createCssVarsParser = <Css = NestedRecord<string>, Vars = NestedRecord<string>>( |
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.
What is being parsed into what and why do we need it?
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.
I have changed it a bit to make it easier. The cssVarsParser is responsible for creating { css, vars }
from theme.
the css
will be applied to <GlobalStyles styles={css} />
and vars
will be attached to theme in react context so that the components can read and reference to css variable.
const Button = styled('button')(({ theme }) => ({
color: theme.vars.palette.primary.main, // 'var(--palette-primary-main)'
}))
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.
I will need to spend more time testing this locally, but this is my first round of review :) Really happy to see this 🤩
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.
I love it! I played with it a bit. Just to confirm my understanding, it is expected that theme.vars
is undefined
yet as useTheme
for joy isn't in the scope of this PR, right? Code sandbox
Yes, correct. This PR is from them |
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.
Some small details :)
Co-authored-by: Marija Najdova <mnajdova@gmail.com>
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.
Awesome 🔥 I don't have anything else to add
Codesandbox preview
the idea behind this PR is that Joy & Material will use
unstable_createCssVarsProvider
(similar tocreateStyled
) to provide CSS variables that developers can extend and/or override the default theme.CssVarsProvider
at its core is aThemeProvider
+ a function that computetheme
input to create CSS variables.The picture below describes the high-level flow that this API is responsible for.
How to use this API
First, the design system has to create the Provider with the default theme and then exports it. The theme structure needs to follow the palette structure (the keys will be the
mode
name and the value can be any palette structure). To see how type is defined, check out spec fileThen, developers can import the Provider from the package. (If they don't want to use CSS variables, they can import the
ThemeProvider
as usual)