-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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
Migrate all website pages to use CSS theme variables #34880
Comments
It looks great. I guess we could also cover the docs pages. |
I think the docs pages should be separated (there are architecture decisions that need to be decided) because they contain nested providers to show the default theme. |
@siriwatknp ok 👍.
Regarding the theme providers structure, I would be in favor of simplifying the structure:
|
Hi, I'd like to help. Can I be assigned to the |
Hey, I would also like to help! Can you assign me a page? |
@EduardoSCosta Thanks! Feel free to submit a PR and tag me @siriwatknp for review. |
@siriwatknp , I'd love to help. Can you assign me the "Pricing" page? 😄 |
@siriwatknp I would like to contribute too. Can you assign me the "About" page? |
@trizotti @brianlu2610 Done! feel free to submit a PR. |
Hello folks, I would like to take on careers page. |
#34908 @siriwatknp brother, here is a draft PR for /careers/ page, but still there's a bug that Next Roles part is not showing the right colors while in light mode. if you can point me in the right direction, it'll be very helpful. as can be seen in mui.com/templates page here in testimonials section |
Hi, me, @jesrodri and @trizotti are facing some errors, so I openned a draft PR and commented about these errors. |
@EduardoSCosta @the-mgi For the section that is wrapped with diff --git a/docs/pages/careers.tsx b/docs/pages/careers.tsx
index b06294da66..1ae0709c22 100644
--- a/docs/pages/careers.tsx
+++ b/docs/pages/careers.tsx
@@ -476,8 +476,7 @@ function CareersContent() {
</Container>
{/* Next roles */}
{nextRolesData.length > 0 ? (
- <ThemeProvider theme={brandingDarkTheme}>
- <Box sx={{ bgcolor: 'primaryDark.700' }}>
+ <Box data-mui-color-scheme="dark" sx={{ bgcolor: 'primaryDark.700' }}>
<Container sx={{ py: { xs: 4, md: 8 } }}>
<Box
sx={{
@@ -531,7 +530,6 @@ function CareersContent() {
</Stack>
</Container>
</Box>
- </ThemeProvider>
) : null}
{/* Frequently asked questions */}
<Container sx={{ py: { xs: 4, sm: 6, md: 8 } }}> |
thanks a lot brother. it is now good 🙌🏼 |
Thanks, everyone for the help! |
We need your help!
Help us migrate the website to start using CSS theme variables!
Progress
If you are interested to contribute, check out the How-to and add your name at the end of the bullet to let us know that you are working on it.
Once you have done the migration, open a PR with the title
[website] Migrate xxx page to use CSS theme variables
/
) [website] Fix home page dark mode flicker #33545/core/
) [website] Migrate/core
page to use CSS variables #35366/x/
) [website] Migrate X page to use CSS theme variables #34922/templates/
) @EduardoSCosta [website] Migrate Product-Templates page to use CSS theme variables #34913/design-kits/
) @jesrodri [website] Migrate Design-kits page to use CSS theme variables #34920Product-Toolpad (this should be done in the Toolpad repo/toolpad/
)/pricing/
) @trizotti [website] Migrate Pricing page to use CSS theme variables #34917/about/
) @brianlu2610 [website] Migrate about-us page to use CSS theme variables #34919/careers/
) @the-mgi [website] Migrate career page to use CSS theme variables #34908/blog/*
) [website] Migrate blog pages to use CSS theme variables #34976How-to
go to the page (in
docs/pages/
folder) that you want to work on. Let's takedocs/pages/templates.tsx
as an example.Replace
BrandingProvider
withBrandingCssVarsProvider
Start the development server via
yarn docs:dev
and goto/templates/
, you are likely to encounterWarning: Prop "className" did not match. Server:
or something similar. This is because some components in the page is relying on the runtime calculation to change the styles based on the color mode. Those conditions must be fixed as explained in the next step!Look at each component imported on the page, e.g.
TemplateHero.tsx
, and find the conditional expression like this:Then, replace the condition with
theme.applyDarkStyles()
:theme.applyDarkStyles
.Refresh the page, you should not see a warning coming from the
TemplateHero.tsx
(you might still see the warning but coming from other components on the page).Once you have fixed all the components, open a PR with the title
[website] Migrate xxx page to use CSS theme variables
and tag @siriwatknp as a reviewer.Migration patterns
Here are some use cases that you might encounter in the migration process.
1. Conditional expression in the prop that's not
sx
Example code:
Migrated code: Move the logic to
sx
prop:2. Usage from
theme.palette.*
Example code:
Migrated code: attach
(theme.vars || theme).*
:3. Conditional expression in
sx
propExample code:
Migrated code: Remove the condition and group into dark styles:
4. Conditional expression in
sx
prop (with nested selectors)Example code:
Migrated code: use array:
5.
img
switch between color modesFrom
StoreTemplatesBanner.tsx
.Example code:
Migrated code: use CSS
content: url(...)
:6. Section wrapped with
<ThemeProvider theme={darkTheme}>
Remove the
ThemeProvider
and adddata-mui-color-scheme="dark"
to the next div instead.Implementation details
We want to migrate the website page by page, so we create a new provider
BrandingCssVarsProvider.tsx
as a replacement for the existingBrandingProvider
. It is built on top of the publicCssVarsProvider
API specific for mui.com which contains custom theme tokens. Once a page is wrapped with the new provider, the components under it will start using CSS theme variables immediately which causes server-client inconsistency due to conditional expressions like thistheme.palette.mode === 'dark' ? theme.palette.grey[300] : theme.palette.grey[700]
The
applyDarkStyles()
util is added to the theme (this is specific to mui.com, not Material UI) to ease the migration because some components need to be backward compatible for some pages that haven't been migrated. This util is straightforward as the name implies. It will decide the approach to use based on the theme, so you don't have to know if the components are rendered in which provider. All you need to do is put the styles for dark mode to the util after the default styles.if the component is under the new BrandingCssVarsProvider:
if the component is under the old BrandingProvider:
We have added a workaround to make the
:where()
selector works.The text was updated successfully, but these errors were encountered: