Skip to content
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

[zero] Export extendTheme for creating a zero-runtime theme #40897

Merged
merged 18 commits into from
Feb 13, 2024

Conversation

siriwatknp
Copy link
Member

@siriwatknp siriwatknp commented Feb 2, 2024

Changes

  • theme is now optional for using zero-runtime
  • developers can provide a plain theme or using the extendTheme util to generate CSS variables/dark mode support
  • add documentation

What's next

To keep this PR small, I decided to do these in the next PR:

  • update the demo app
  • set zero-runtime version

@siriwatknp siriwatknp added package: system Specific to @mui/system package: pigment-css Specific to @pigment-css/* labels Feb 2, 2024
@mui-bot
Copy link

mui-bot commented Feb 2, 2024

Netlify deploy preview

https://deploy-preview-40897--material-ui.netlify.app/

@material-ui/core: parsed: +0.15% , gzip: +0.16%
@material-ui/system: parsed: +1.09% , gzip: +0.97%
@mui/material-next: parsed: +0.25% , gzip: +0.25%
@mui/joy: parsed: +0.17% , gzip: +0.19%

Bundle size report

Details of bundle changes (Toolpad)
Details of bundle changes

Generated by 🚫 dangerJS against cdfc7a0

@siriwatknp siriwatknp force-pushed the system/extract-theme branch 3 times, most recently from 3c892e8 to 3558d4d Compare February 2, 2024 09:36
@oliviertassinari oliviertassinari changed the title [system] extract extendTheme for zero runtime. [system] extract extendTheme for zero runtime Feb 3, 2024
@oliviertassinari oliviertassinari changed the title [system] extract extendTheme for zero runtime [system] Extract extendTheme for zero runtime Feb 3, 2024
@siriwatknp siriwatknp changed the title [system] Extract extendTheme for zero runtime [zero] Export extendTheme for creating a theme Feb 6, 2024
@@ -1,75 +1,3 @@
:root {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to theme in next.config.js

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Feb 7, 2024
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Feb 7, 2024
@siriwatknp siriwatknp marked this pull request as ready for review February 7, 2024 09:25
Copy link
Member

@cherniavskii cherniavskii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job!
I appreciate the clarity of the readme!

);
```

The `extendTheme` utility will go through the theme and create a `vars` object which represents the tokens that refer to CSS variables.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand correctly, extendTheme is optional.
When should it be used? What are the benefits compared to the plain theme?

Copy link
Member Author

@siriwatknp siriwatknp Feb 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the questions.

extendTheme is optional (I will mention it in the doc)

You would use it if you want zero-runtime to generate CSS variables from the theme.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You would use it if you want zero-runtime to generate CSS variables from the theme.

Is there some added value for the user in doing so?

Copy link
Contributor

@brijeshb42 brijeshb42 Feb 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It allows you to support multiple colorSchemes/themes and access css variables as JS object in your runtime code, ie, you could also do this in your code -

import theme from '@mui/zero-runtime/theme';

function Component() {
  return <div style={{[theme.vars.palette.primary.main]: 'red'}} />
}

which would output

<div style="--mui-palette-primary-main: red"></div>

Copy link
Contributor

@brijeshb42 brijeshb42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

@siriwatknp
Copy link
Member Author

@samuelsycamore @danilo-leal I'd love to hear feedbacks on the docs from both of you.

FYI, I'd like to keep this PR simple so added only the basic things for the docs to get started. We could add more docs, like advanced usage, tutorial, technical explanation in a separate PR.

packages/zero-runtime/README.md Outdated Show resolved Hide resolved
packages/zero-runtime/README.md Outdated Show resolved Hide resolved
packages/zero-runtime/README.md Outdated Show resolved Hide resolved
packages/zero-runtime/README.md Outdated Show resolved Hide resolved
packages/zero-runtime/README.md Show resolved Hide resolved
packages/zero-runtime/README.md Outdated Show resolved Hide resolved
Co-authored-by: Matt <github@nospam.33m.co>
Signed-off-by: Siriwat K <siriwatkunaporn@gmail.com>
@oliviertassinari oliviertassinari changed the title [zero] Export extendTheme for creating a theme [system] Export extendTheme for creating a theme with zero runtime Feb 11, 2024
@siriwatknp siriwatknp dismissed mbrookes’s stale review February 13, 2024 04:06

suggestion applied.

@siriwatknp siriwatknp changed the title [system] Export extendTheme for creating a theme with zero runtime [zero] Export extendTheme for creating a zero-runtime theme Feb 13, 2024
@siriwatknp siriwatknp merged commit f33e247 into mui:master Feb 13, 2024
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package: pigment-css Specific to @pigment-css/* package: system Specific to @mui/system
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants