-
-
Notifications
You must be signed in to change notification settings - Fork 38
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
[core] Implement useTheme processor and runtime theme #105
Conversation
a7558aa
to
38fcae8
Compare
const breakpointsImport = hasBreakpoints | ||
? "import createBreakpoints from '@mui/system/createTheme/createBreakpoints';\n" | ||
: ''; | ||
const transitionsImport = hasTransitions | ||
? `import createTransitions from '${process.env.PACKAGE_NAME}/createTransitions';\n` | ||
: ''; | ||
const source = `${breakpointsImport}${transitionsImport} |
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 think this should come from Material UI. Pigment should just call theme.toRuntime()
and let Material UI decide what to add to the runtime.
In Material UI, we can export an adapter function that inserts .toRuntime()
to the theme.
// next.config.js
import { createPigmentConfig, extendTheme } from '@mui/material/styles';
const config = createPigmentConfig(extendTheme());
module.exports = withPigment(config);
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.
If you agree with my proposal, I can create a PR to add the createPigmentCssConfig()
.
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.
Agree with having this in Material UI side, and by default Pigment CSS can only add the CSS vars. What do you think?
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.
Yes, I think Pigment should call specific methods rather than owning the logic inside.
To let Pigment generate CSS variables from the theme:
create a method
generateStyleSheets
totheme
. At build time, Pigment will create CSS file from the result of the method.
To create a runtime theme:
create a method
toRuntime
totheme
. At build time, Pigment will use that result and export as JS (the result has to be a string)
To use the runtime theme:
import theme from '@pigment-css/react/theme';
Here is my proposal, Material UI export a From Pigment side, I see 2 choices:
// next.config.js
const { extendTheme, stringifyTheme } = require('@mui/material/styles');
const theme = extendTheme();
theme.toRuntime = () => stringifyTheme(theme);
module.exports = withPigment({
theme,
})
// next.config.js
const { extendTheme, stringifyTheme } = require('@mui/material/styles');
const theme = extendTheme();
module.exports = withPigment({
theme,
runtimeTheme: stringifyTheme(theme),
}) I like this approach because regardless of the choice, it's not related to Material UI. In the future, |
I like the first approach better, ie, I am naming the method to |
38fcae8
to
bf3d58f
Compare
bf3d58f
to
455c26f
Compare
ca0d6f0
to
b03fd52
Compare
packages/pigment-css-react/tests/useTheme/fixtures/useTheme.input.js
Outdated
Show resolved
Hide resolved
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.
Preapproved, please check my suggestions before merging.
b03fd52
to
54b3db4
Compare
to replace the useTheme function calls with an import from Pigment package
54b3db4
to
3c2b921
Compare
3c2b921
to
de66eb3
Compare
Here's how the replacement works
Before transformation:
After transformation:
Fixes: mui/material-ui#42260