[docs] Add theme.applyStyles and migrate docs#42498
Conversation
Netlify deploy preview
Bundle size report |
| sx={[ | ||
| { | ||
| overflow: 'auto', | ||
| }, | ||
| flexBasis | ||
| ? { | ||
| flexBasis: `${flexBasis}px`, | ||
| } | ||
| : { | ||
| flexBasis: null, | ||
| }, | ||
| ]} |
There was a problem hiding this comment.
Are all of these sx ternary stuff related to the PR's goal or should we keep it separate? Also, I'm curious why this approach is better than the previous one 🤔
There was a problem hiding this comment.
Ideally, it can be a separate PR. It was updated due to the sx codemod (also transforming theme.palette.mode condition).
I'm curious why this approach is better than the previous one 🤔
It's compatible with Pigment CSS. If you don't mind, I can update the sx prop docs in this PR altogether.
There was a problem hiding this comment.
Ah cool! I'm slightly sad as this syntax is way uglier than the previous one 😅 but it feels all right to update the docs in a dedicated PR. Maybe it's worth highlighting these things (why these ternaries were picked up and missing tasks) in the PR's description, though!
| '--joy-palette-text-secondary': '#635e69', | ||
| '--joy-palette-primary-plainColor': '#d48cff', | ||
| }, | ||
|
|
There was a problem hiding this comment.
I think a saw a PR for fix this, but in case it was unrelated, we shouldn't transform these lines.
This is fixed, I missed the default color primary. |
Looks good on the latest netlify build, not sure what was the issue. |
mnajdova
left a comment
There was a problem hiding this comment.
I can't find anything else, I think we can merge and fix any regression in case we missed something. Awesome job Jun, both on the codemod and the migration 🤩
|
Heya! @siriwatknp found a place where it seems like the new way to write conditional styles isn't working properly: https://next--material-ui.netlify.app/experiments/docs/demos/ — the toolbar |
This is a codemod bug, I will open a fix today. |
| let Root = 'span'; | ||
| if (shape === 'inline') { | ||
| Root = InlineShape; | ||
| } | ||
| if (shape === 'image') { | ||
| Root = ImageShape; | ||
| } | ||
| /* eslint-disable material-ui/no-hardcoded-labels, react/no-danger */ | ||
| return ( | ||
| <Root shape={shape === 'inline' ? 'inline' : adShape} className={className}> | ||
| <Root className={className}> |
There was a problem hiding this comment.
This logic isn't equivalent. I have opened to fix this: #42735.
oliviertassinari
left a comment
There was a problem hiding this comment.
Great to see that we are getting closer to have the docs, e.g. https://mui.com/material-ui/getting-started/ use the best practice that the docs recommand.
| borderBottom: `1px solid ${ | ||
| theme.palette.mode === 'light' ? '#eaecef' : '#30363d' | ||
| }`, | ||
| borderBottom: `1px solid ${'#30363d'}`, |
There was a problem hiding this comment.
I think we should have expected:
| borderBottom: `1px solid ${ | |
| theme.palette.mode === 'light' ? '#eaecef' : '#30363d' | |
| }`, | |
| borderBottom: `1px solid ${'#30363d'}`, | |
| borderBottom: '1px solid #eaecef', |
because the coding style doesn't fit, and the light/dark colors are inverted.
I'm cleaning this up in #44708.
| [`& .${autocompleteClasses.listbox}`]: { | ||
| backgroundColor: theme.palette.mode === 'light' ? '#fff' : '#1c2128', | ||
| backgroundColor: '#fff', | ||
|
|
| border: `1px solid ${'#eaecef'}`, | ||
| }), | ||
| }, | ||
| ...theme.applyStyles('dark', { |
There was a problem hiding this comment.
I feel like we should group light and dark values to be right next to each other, while we should think about light mode and dark mode standalone, in which world I find https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/light-dark a harmful API. I believe it's still more important to group dark/light style per selector, to so people can have a simple mental model.





Docs update
Before:
After:
The recommended approach for styling dark mode is to use
theme.applyStyles('dark', …)and stop usingtheme.palette.mode === 'dark'check to smoothly migrate to Pigment CSS.This PR includes the migration of the docs using codemods with manual adjustments. The changes are huge but I don't think we can avoid it.