-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
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
[material-ui] Refine extendTheme
and CssVarsProvider
API
#42839
Conversation
Netlify deploy preview
@material-ui/core: parsed: +0.32% , gzip: +0.44% Bundle size reportDetails of bundle changes (Toolpad) |
Thanks, I'll go with The PR is ready for another review. Argos changes are expected. |
Signed-off-by: Siriwat K <siriwatkunaporn@gmail.com>
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.
Nice work @siriwatknp, I only have one question regarding the docs
import { CssVarsProvider, extendTheme } from '@mui/material/styles'; | ||
|
||
const theme = extendTheme({ | ||
colorSchemeSelector: 'media', |
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.
If I understand correctly, you either provide
colorSchemes: { light: true, dark: true }
or
colorSchemeSelector: 'media'
right?
If this is the case, then I would show colorSchemes: { light: true, dark: true }
for this example and leave colorSchemeSelector
for the advanced section. I think colorSchemes: { light: true, dark: true }
is more beginner friendly. What do you think?
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.
Opps, this is my mistake.
colorSchemeSelector: 'media'
alone won't work because the there is only light
color scheme by default, so colorSchemes: { light: true, dark: true }
is required.
I will update the docs and add a warning in development.
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.
Done!
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.
Two final minor improvements to the guide, but otherwise LGTM 😊
Nice job @siriwatknp
docs/data/material/customization/css-theme-variables/configuration.md
Outdated
Show resolved
Hide resolved
); | ||
} | ||
``` | ||
In the example below, we're using a `Select` component that calls `setMode` from the `useColorSchemes()` hook to handle the mode switching. |
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.
"we"
In the example below, we're using a `Select` component that calls `setMode` from the `useColorSchemes()` hook to handle the mode switching. | |
The example below uses a `Select` component that calls `setMode` from the `useColorSchemes()` hook to handle the mode switching. |
closes #42887, closes #41070
📖 docs: Basic usage and Advanced config
Motivation
The experimental API was lacking some of the behaviors
light
anddark
modes by default. This is not a good behavior for apps with only light or dark mode. The way it should be is to start with light by default and let users configure params based on their usage.@media prefers-color-scheme
Changes
Start with light by default
When using
CssVarsProvider
without a custom theme, the behavior is the same asThemeProvider
except that the theme CSS variables are generated.See docs.
Switch to dark application
Light and Dark
When light and dark are enable, the
@media (prefers-color-scheme)
is used.To customize the selector, set
colorSchemeSelector: 'class' | 'data'
:media
option.System preference
System preference is enabled by default regardless of the selector. So, for light and dark apps, the mode will be
system
by default.color-scheme
Css color-scheme is enable by default to use the right scheme based on the generated style-sheet, user can disable it with:
Removed APIs