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

[website] Migrate blog pages to use CSS theme variables #34976

Merged
merged 13 commits into from Nov 11, 2022

Conversation

siriwatknp
Copy link
Member

@siriwatknp siriwatknp commented Nov 1, 2022

part of #34880

How to check?

✅ In development, the page does not throw class names mismatch between server and client.

Changes

  • use applyDarkStyles in the blog page
  • For reusable components like MarkdownElement that is used in the docs, refactor the styles to use CSS variables with fallbacks to the branding light & dark theme.

Before: https://master--material-ui.netlify.app/blog/date-pickers-stable-v5/
After: https://deploy-preview-34976--material-ui.netlify.app/blog/date-pickers-stable-v5/

@siriwatknp siriwatknp added website Pages that are not documentation-related, marketing-focused. enhancement This is not a bug, nor a new feature labels Nov 1, 2022
@mui-bot
Copy link

mui-bot commented Nov 1, 2022

Messages
📖 Netlify deploy preview: https://deploy-preview-34976--material-ui.netlify.app/

No bundle size changes

Generated by 🚫 dangerJS against cc8821b

@siriwatknp siriwatknp marked this pull request as draft November 1, 2022 13:13
@siriwatknp siriwatknp marked this pull request as ready for review November 2, 2022 05:54
@siriwatknp
Copy link
Member Author

siriwatknp commented Nov 2, 2022

@oliviertassinari The code font changes because of #34954, Are you sure about this?

Before:
Screen Shot 2565-11-02 at 13 33 59

After:
Screen Shot 2565-11-02 at 13 33 39

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Nov 2, 2022
Signed-off-by: Siriwat K <siriwatkunaporn@gmail.com>
@github-actions github-actions bot added PR: out-of-date The pull request has merge conflicts and can't be merged and removed PR: out-of-date The pull request has merge conflicts and can't be merged labels Nov 3, 2022
@oliviertassinari
Copy link
Member

oliviertassinari commented Nov 7, 2022

Are you sure about this?

@siriwatknp I didn't intend this change. I have created #35027 to improve the situation. Visual regression tests could have helped avoid this regression.

@siriwatknp
Copy link
Member Author

Are you sure about this?

@siriwatknp I didn't intend this change, visual regression tests could have helped spot this. I have created #35027 to improve the situation.

Got it, then this PR should help spot the change in the visual regression.

@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Nov 8, 2022
@oliviertassinari oliviertassinari removed their request for review November 11, 2022 00:40
@oliviertassinari oliviertassinari added blog and removed enhancement This is not a bug, nor a new feature labels Nov 11, 2022
textDecoration: 'none',
const Root = styled('div')(
({ theme }) => ({
...lightTheme.typography.body1,
Copy link
Member

Choose a reason for hiding this comment

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

Would this be better?

Suggested change
...lightTheme.typography.body1,
...theme.typography.body1,

Comment on lines +24 to +26
borderRadius: `var(--muidocs-shape-borderRadius, ${
theme.shape?.borderRadius ?? lightTheme.shape.borderRadius
}px)`,
Copy link
Member

Choose a reason for hiding this comment

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

Why would theme.shape be undefined a valid case? Should we have expected?

Suggested change
borderRadius: `var(--muidocs-shape-borderRadius, ${
theme.shape?.borderRadius ?? lightTheme.shape.borderRadius
}px)`,
borderRadius: `var(--muidocs-shape-borderRadius, ${theme.shape.borderRadius}px)`,

Copy link
Member

Choose a reason for hiding this comment

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

But this seems to hide something else. Should we have expected?

Suggested change
borderRadius: `var(--muidocs-shape-borderRadius, ${
theme.shape?.borderRadius ?? lightTheme.shape.borderRadius
}px)`,
borderRadius: theme.vars.shape.borderRadius,

Copy link
Member

Choose a reason for hiding this comment

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

It feels like this component's parent infrastructure wasn't ready to allow MarkdownElement.js to be migrated to CSS vars.

...lightTheme.typography.body1,
color: `var(--muidocs-palette-text-primary, ${lightTheme.palette.text.primary})`,
'& strong': {
color: `var(--muidocs-palette-text-primary, ${lightTheme.palette.text.primary})`,
Copy link
Member

Choose a reason for hiding this comment

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

Would this be better?

Suggested change
color: `var(--muidocs-palette-text-primary, ${lightTheme.palette.text.primary})`,
color: `var(--muidocs-palette-text-primary, ${theme.colorScheme.light.palette.text.primary})`,

the coupling with the imports of lightTheme and darkTheme seems unhealthy for design consistency because the Material UI components don't use these values.

@siriwatknp
Copy link
Member Author

@oliviertassinari My intention is to move MarkdownElement out of the theme context so that the component can render anywhere.

I think the docs component should not be altered by the theme context. It is very hard to reason and we have seen a lot of crashes based on the theme context.

This also allows the component to be rendered on the pages that haven't migrated to CSS variables.

@oliviertassinari
Copy link
Member

oliviertassinari commented Nov 14, 2022

so that the component can render anywhere.

@siriwatknp The end goal sounds great.

I'm not sure about the implementation. Would this be simpler/work?

  1. Update all the codebase so that Material UI's brandingTheme is always present and unaltered when a docs-infra component is used, e.g. MarkdownElement.
  2. Move the ThemeProvider from _app.js to the Next.js pages. For example, this would allow using the playground with the default theme behavior.
  3. Move the CssVarsProvider from MarkdownDocs.js to the DemoSandbox.js file. This would remove the need to use all the "Wrapper" components in Joy UI. We would make 1. simpler to execute as the emotion theme context stacking would be a lot flatter in Joy UI pages.
  4. Before migrating any of the pages to CSS variables, add the CSS providers to all the pages.
  5. Do the migration, dogfooding the DX of the same API as we recommend it for the community: theme.vars.

@oliviertassinari
Copy link
Member

oliviertassinari commented Nov 16, 2022

the-mgi pushed a commit to the-mgi/material-ui that referenced this pull request Nov 17, 2022
daniel-rabe pushed a commit to daniel-rabe/material-ui that referenced this pull request Nov 29, 2022
feliperli pushed a commit to jesrodri/material-ui that referenced this pull request Dec 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blog website Pages that are not documentation-related, marketing-focused.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants