-
-
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
[system] Add defaultMode
to InitColorSchemeScript
#44139
Changes from all commits
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 | ||||
---|---|---|---|---|---|---|
|
@@ -8,6 +8,11 @@ export const DEFAULT_COLOR_SCHEME_STORAGE_KEY = 'color-scheme'; | |||||
export const DEFAULT_ATTRIBUTE = 'data-color-scheme'; | ||||||
|
||||||
export interface InitColorSchemeScriptProps { | ||||||
/** | ||||||
* The default mode when the storage is empty (user's first visit) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
x al the others on this file. Edit. Fixed in #44187. |
||||||
* @default 'system' | ||||||
*/ | ||||||
defaultMode?: 'system' | 'light' | 'dark'; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure about the prop name: "default"? It sounds more like "initial" as there is a notion of session. Should we rename it? |
||||||
/** | ||||||
* The default color scheme to be used on the light mode | ||||||
* @default 'light' | ||||||
|
@@ -49,6 +54,7 @@ export interface InitColorSchemeScriptProps { | |||||
|
||||||
export default function InitColorSchemeScript(options?: InitColorSchemeScriptProps) { | ||||||
const { | ||||||
defaultMode = 'system', | ||||||
defaultLightColorScheme = 'light', | ||||||
defaultDarkColorScheme = 'dark', | ||||||
modeStorageKey = DEFAULT_MODE_STORAGE_KEY, | ||||||
|
@@ -93,7 +99,7 @@ export default function InitColorSchemeScript(options?: InitColorSchemeScriptPro | |||||
__html: `(function() { | ||||||
try { | ||||||
let colorScheme = ''; | ||||||
const mode = localStorage.getItem('${modeStorageKey}') || 'system'; | ||||||
const mode = localStorage.getItem('${modeStorageKey}') || '${defaultMode}'; | ||||||
const dark = localStorage.getItem('${colorSchemeStorageKey}-dark') || '${defaultDarkColorScheme}'; | ||||||
const light = localStorage.getItem('${colorSchemeStorageKey}-light') || '${defaultLightColorScheme}'; | ||||||
if (mode === 'system') { | ||||||
|
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.
Should we inverse the docs order? It looks like if
<InitColorSchemeScript defaultMode="dark">
is used,<ThemeProvider defaultMode="dark">
is a no-op.It would make sense to document this as well?
Now, developers need to set both because the initial load might not have InitColorSchemeScript or System based components while the next page has. If all pages have InitColorSchemeScript, then I guess it's a 100% no-op.
Actually, It seems that the whole page is wrong. This is MUI System docs no? so it shouldn't be documented in Material UI.
We are also missing the API table page for InitColorSchemeScript.