-
-
Notifications
You must be signed in to change notification settings - Fork 32.8k
[material-ui] Support Pigment CSS for CssBaseline, ScopedCssBaseline and Popper
#42640
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
Changes from 7 commits
e0f8534
a2eeb20
32a69a9
64042cd
92f2a8f
9f90b29
d87e9b7
61ca07d
ce07f2e
17dd474
1d7cc3b
7c630ad
a5b8290
bf96c73
525a4c9
f3075f6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,12 @@ | ||
| 'use client'; | ||
| import * as React from 'react'; | ||
| import PropTypes from 'prop-types'; | ||
| import useThemeProps from '../styles/useThemeProps'; | ||
| import GlobalStyles from '../GlobalStyles'; | ||
| import { createUseThemeProps, globalCss } from '../zero-styled'; | ||
|
|
||
| const useThemeProps = createUseThemeProps('MuiCssBaseline'); | ||
|
|
||
| // `ecs` stands for enableColorScheme. This is internal logic to make it work with Pigment CSS, so shorter is better. | ||
| const SELECTOR = 'mui-ecs'; | ||
|
|
||
| export const html = (theme, enableColorScheme) => ({ | ||
| WebkitFontSmoothing: 'antialiased', // Antialiasing. | ||
|
|
@@ -13,7 +17,8 @@ export const html = (theme, enableColorScheme) => ({ | |
| // Fix font resize problem in iOS | ||
| WebkitTextSizeAdjust: '100%', | ||
| // When used under CssVarsProvider, colorScheme should not be applied dynamically because it will generate the stylesheet twice for server-rendered applications. | ||
| ...(enableColorScheme && !theme.vars && { colorScheme: theme.palette.mode }), | ||
| ...(enableColorScheme && | ||
| !theme.vars && { [`&:has(.${SELECTOR})`]: { colorScheme: theme.palette.mode } }), | ||
| }); | ||
|
|
||
| export const body = (theme) => ({ | ||
|
|
@@ -26,17 +31,19 @@ export const body = (theme) => ({ | |
| }, | ||
| }); | ||
|
|
||
| export const styles = (theme, enableColorScheme = false) => { | ||
| export const styles = (theme) => { | ||
| const colorSchemeStyles = {}; | ||
| if (enableColorScheme && theme.colorSchemes) { | ||
| if (theme.colorSchemes) { | ||
| Object.entries(theme.colorSchemes).forEach(([key, scheme]) => { | ||
| colorSchemeStyles[theme.getColorSchemeSelector(key).replace(/\s*&/, '')] = { | ||
| colorScheme: scheme.palette?.mode, | ||
| [`&:has(.${SELECTOR})`]: { | ||
| colorScheme: scheme.palette?.mode, | ||
| }, | ||
| }; | ||
| }); | ||
| } | ||
| let defaultStyles = { | ||
| html: html(theme, enableColorScheme), | ||
| html: html(theme, true), | ||
| '*, *::before, *::after': { | ||
| boxSizing: 'inherit', | ||
| }, | ||
|
|
@@ -63,6 +70,8 @@ export const styles = (theme, enableColorScheme = false) => { | |
| return defaultStyles; | ||
| }; | ||
|
|
||
| const GlobalStyles = globalCss(({ theme }) => styles(theme)); | ||
|
|
||
| /** | ||
| * Kickstart an elegant, consistent, and simple baseline to build upon. | ||
| */ | ||
|
|
@@ -71,7 +80,8 @@ function CssBaseline(inProps) { | |
| const { children, enableColorScheme = false } = props; | ||
| return ( | ||
| <React.Fragment> | ||
| <GlobalStyles styles={(theme) => styles(theme, enableColorScheme)} /> | ||
| <GlobalStyles /> | ||
| {enableColorScheme && <span className={SELECTOR} style={{ display: 'none' }} />} | ||
|
||
| {children} | ||
| </React.Fragment> | ||
| ); | ||
|
|
||
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.
Glad we bump safari to 15.4, otherwise I have no clue how to make it work 😊