@mui/system 5.10.7 → 5.10.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +117 -0
- package/Unstable_Grid/createGrid.js +1 -1
- package/Unstable_Grid/gridGenerator.d.ts +3 -1
- package/Unstable_Grid/gridGenerator.js +16 -2
- package/cssVars/createCssVarsProvider.d.ts +0 -5
- package/cssVars/createCssVarsProvider.js +45 -44
- package/cssVars/getInitColorSchemeScript.d.ts +0 -5
- package/cssVars/getInitColorSchemeScript.js +0 -4
- package/esm/Unstable_Grid/createGrid.js +2 -2
- package/esm/Unstable_Grid/gridGenerator.js +11 -0
- package/esm/cssVars/createCssVarsProvider.js +47 -45
- package/esm/cssVars/getInitColorSchemeScript.js +0 -4
- package/index.js +1 -1
- package/legacy/Unstable_Grid/createGrid.js +2 -2
- package/legacy/Unstable_Grid/gridGenerator.js +17 -0
- package/legacy/cssVars/createCssVarsProvider.js +45 -47
- package/legacy/cssVars/getInitColorSchemeScript.js +1 -3
- package/legacy/index.js +1 -1
- package/modern/Unstable_Grid/createGrid.js +2 -2
- package/modern/Unstable_Grid/gridGenerator.js +11 -0
- package/modern/cssVars/createCssVarsProvider.js +47 -45
- package/modern/cssVars/getInitColorSchemeScript.js +0 -4
- package/modern/index.js +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,122 @@
|
|
|
1
1
|
# [Versions](https://mui.com/versions/)
|
|
2
2
|
|
|
3
|
+
## 5.10.9
|
|
4
|
+
|
|
5
|
+
<!-- generated comparing v5.10.8..master -->
|
|
6
|
+
|
|
7
|
+
_Oct 10, 2022_
|
|
8
|
+
|
|
9
|
+
A big thanks to the 7 contributors who made this release possible. Here are some highlights ✨:
|
|
10
|
+
|
|
11
|
+
- 🚀 [Joy] Button loading functionality has been added by @kushagra010 (#34658)
|
|
12
|
+
- And more 🐛 bug fixes and 📚 documentation improvements.
|
|
13
|
+
|
|
14
|
+
### `@mui/material@5.10.9`
|
|
15
|
+
|
|
16
|
+
- ​<!-- 16 -->[Grid v2][system] Handle direction object prop for responsive design (#34574) @vanyaxk
|
|
17
|
+
- ​<!-- 03 -->[Slider] Fix unnecessary accessibility attribute in root element (#34610) @vanyaxk
|
|
18
|
+
|
|
19
|
+
### `@mui/system@5.10.9`
|
|
20
|
+
|
|
21
|
+
#### BREAKING CHANGE
|
|
22
|
+
|
|
23
|
+
- ​<!-- 17 -->[system] Fix color-scheme implementation (#34639) @siriwatknp
|
|
24
|
+
|
|
25
|
+
The `enableColorScheme` prop has been removed from `CssVarsProvider` and `getInitColorScheme` (both Material UI and Joy UI).
|
|
26
|
+
|
|
27
|
+
Migration:
|
|
28
|
+
|
|
29
|
+
- **Material UI**: you can enable the CSS color scheme via `<CssBaseline enableColorScheme />`.
|
|
30
|
+
- **Joy UI**: it is enabled automatically if you use `<CssBaseline />`, [see the docs](https://mui.com/joy-ui/react-css-baseline/).
|
|
31
|
+
|
|
32
|
+
#### Changes
|
|
33
|
+
|
|
34
|
+
- ​<!-- 02 -->[system] Fix typo in createCssVarsProvider (#34661) @HexM7
|
|
35
|
+
|
|
36
|
+
### `@mui/base@5.0.0-alpha.101`
|
|
37
|
+
|
|
38
|
+
- ​<!-- 01 -->[TrapFocus] Restore the previously exported type from @mui/material (#34601) @michaldudak
|
|
39
|
+
|
|
40
|
+
### `@mui/joy@5.0.0-alpha.49`
|
|
41
|
+
|
|
42
|
+
- ​<!-- 04 -->[Joy] Add button loading functionality (#34658) @kushagra010
|
|
43
|
+
|
|
44
|
+
### Docs
|
|
45
|
+
|
|
46
|
+
- ​<!-- 18 -->[docs] Revert #34541 (#34700) @michaldudak
|
|
47
|
+
- ​<!-- 15 -->[blog] Blog post for MUI X v6 alpha zero (#34424) @joserodolfofreitas
|
|
48
|
+
- ​<!-- 09 -->[docs] Improve Joy UI tutorial demo (#34653) @oliviertassinari
|
|
49
|
+
- ​<!-- 08 -->[docs] Explain how SelectUnstyled renders a hidden input (#34638) @michaldudak
|
|
50
|
+
- ​<!-- 07 -->[docs] Fix Taiwan description (#34611) @oliviertassinari
|
|
51
|
+
- ​<!-- 06 -->[docs] Fix codesandbox export with dayjs (#34619) @oliviertassinari
|
|
52
|
+
- ​<!-- 05 -->[docs] Explain the purpose of renderGroup prop (#34066) @michaldudak
|
|
53
|
+
|
|
54
|
+
### Core
|
|
55
|
+
|
|
56
|
+
- ​<!-- 14 -->[core] Make useForkRef variadic (#27939) @michaldudak
|
|
57
|
+
- ​<!-- 13 -->[core] Speedup of yarn install in the CI (#34632) @oliviertassinari
|
|
58
|
+
- ​<!-- 12 -->[core] Fix markdown loader on Windows (#34623) @michaldudak
|
|
59
|
+
- ​<!-- 11 -->[core] Update changelog for version v5.10.8 (#34593) @mnajdova
|
|
60
|
+
- ​<!-- 10 -->[core] Update root package.json version (#34592) @mnajdova
|
|
61
|
+
|
|
62
|
+
All contributors of this release in alphabetical order: @HexM7, @joserodolfofreitas, @kushagra010, @michaldudak, @mnajdova, @oliviertassinari, @vanyaxk
|
|
63
|
+
|
|
64
|
+
## 5.10.8
|
|
65
|
+
|
|
66
|
+
<!-- generated comparing v5.10.7..master -->
|
|
67
|
+
|
|
68
|
+
_Oct 3, 2022_
|
|
69
|
+
|
|
70
|
+
A big thanks to the 18 contributors who made this release possible. Here are some highlights ✨:
|
|
71
|
+
|
|
72
|
+
- 🚀 [SnackbarUnstyled](https://mui.com/base/react-snackbar/) component & headless hook are added to MUI Base (#33227) @ZeeshanTamboli
|
|
73
|
+
- 📚 [CSS variables documentation](https://mui.com/material-ui/experimental-api/css-theme-variables/overview/) for Material UI has been added by @siriwatknp (#33958)
|
|
74
|
+
- And more 🐛 bug fixes and 📚 documentation improvements.
|
|
75
|
+
|
|
76
|
+
### `@mui/material@5.10.8`
|
|
77
|
+
|
|
78
|
+
- ​<!-- 28 -->[Autocomplete] Skip filtering when list of options is loading (#33278) @ndebeiss
|
|
79
|
+
- ​<!-- 13 -->[Fab] Add `disabled` class to FAB button (#34245) @meenarama
|
|
80
|
+
- ​<!-- 09 -->[l10n] Add Arabic Saudi Arabia (ar-SA) locale (#33340) @rolule
|
|
81
|
+
- ​<!-- 08 -->[l10n] zhTW refinement (#33391) @Aporim2051
|
|
82
|
+
- ​<!-- 07 -->[Popover] Add `ownerState` on the paper slot (#34445) @kabernardes
|
|
83
|
+
- ​<!-- 05 -->[Slider] Fixed incorrect marks displayed due to duplicate keys in range (#33526) @kskd1804
|
|
84
|
+
- ​<!-- 03 -->[TextField] Fix typo in FormControlLabel declaration file (#34535) @hghmn
|
|
85
|
+
|
|
86
|
+
### `@mui/base@5.0.0-alpha.100`
|
|
87
|
+
|
|
88
|
+
- ​<!-- 04 -->[SnackbarUnstyled] Create component and `useSnackbar` hook (#33227) @ZeeshanTamboli
|
|
89
|
+
|
|
90
|
+
### `@mui/joy@5.0.0-alpha.48`
|
|
91
|
+
|
|
92
|
+
- ​<!-- 12 -->[Joy] Fix `variantPlain` classname missing in few components (#34534) @hbjORbj
|
|
93
|
+
- ​<!-- 11 -->[Joy] Fix input decorator color and list padding (#34586) @siriwatknp
|
|
94
|
+
- ​<!-- 10 -->[Joy] Miscellaneous fixes (#34492) @siriwatknp
|
|
95
|
+
|
|
96
|
+
### Docs
|
|
97
|
+
|
|
98
|
+
- ​<!-- 27 -->[blog] Fix 404 link in base introduction @oliviertassinari
|
|
99
|
+
- ​<!-- 21 -->[docs] Fix CI build (#34589) @mnajdova
|
|
100
|
+
- ​<!-- 20 -->[docs] Temporary remove date picker from home page (#34541) @siriwatknp
|
|
101
|
+
- ​<!-- 19 -->[docs] Revise and expand Joy UI "Tutorial" doc (#34569) @samuelsycamore
|
|
102
|
+
- ​<!-- 18 -->[docs] Fix SEO issues (#34537) @oliviertassinari
|
|
103
|
+
- ​<!-- 17 -->[docs] Add CSS variables documentation for Material UI (#33958) @siriwatknp
|
|
104
|
+
- ​<!-- 16 -->[docs] Capitalize Material Design on the Breakpoints page (#34481) @Dustin-Digitar
|
|
105
|
+
- ​<!-- 15 -->[docs] Able to load doc components inside markdown files (#34243) @flaviendelangle
|
|
106
|
+
- ​<!-- 14 -->[docs] Use mouse pointer on esc button in the search modal (#34485) @minkyngkm
|
|
107
|
+
- ​<!-- 02 -->[website] Fix typo in pricing FAQ @oliviertassinari
|
|
108
|
+
- ​<!-- 01 -->[website] Move the React Engineer role from open to next (#34494) @mnajdova
|
|
109
|
+
|
|
110
|
+
### Core
|
|
111
|
+
|
|
112
|
+
- ​<!-- 26 -->[core] Update root package.json version (#34592) @mnajdova
|
|
113
|
+
- ​<!-- 25 -->[core] Remove useless comment in fixtures (#34581) @Garz4
|
|
114
|
+
- ​<!-- 24 -->[core] Fix link to CODE_OF_CONDUCT.md (#34543) @peippo
|
|
115
|
+
- ​<!-- 23 -->[core] Remove outdated docsearch.js dependency (#34421) @oliviertassinari
|
|
116
|
+
- ​<!-- 22 -->[core] Add `newFeature` to the typing of MuiPage (#34511) @flaviendelangle
|
|
117
|
+
|
|
118
|
+
All contributors of this release in alphabetical order: @Aporim2051, @Dustin-Digitar, @flaviendelangle, @Garz4, @hbjORbj, @hghmn, @kabernardes, @kskd1804, @meenarama, @minkyngkm, @mnajdova, @ndebeiss, @oliviertassinari, @peippo, @rolule, @samuelsycamore, @siriwatknp, @ZeeshanTamboli
|
|
119
|
+
|
|
3
120
|
## 5.10.7
|
|
4
121
|
|
|
5
122
|
<!-- generated comparing v5.10.6..master -->
|
|
@@ -74,7 +74,7 @@ function createGrid(options = {}) {
|
|
|
74
74
|
gridSize
|
|
75
75
|
} = ownerState;
|
|
76
76
|
const slots = {
|
|
77
|
-
root: ['root', container && 'container',
|
|
77
|
+
root: ['root', container && 'container', wrap !== 'wrap' && `wrap-xs-${String(wrap)}`, ...(0, _gridGenerator.generateDirectionClasses)(direction), ...(0, _gridGenerator.generateSizeClassNames)(gridSize), ...(container ? (0, _gridGenerator.generateSpacingClassNames)(spacing, theme.breakpoints.keys[0]) : [])]
|
|
78
78
|
};
|
|
79
79
|
return (0, _utils.unstable_composeClasses)(slots, slot => (0, _utils.unstable_generateUtilityClass)(componentName, slot), {});
|
|
80
80
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Breakpoints } from '../createTheme/createBreakpoints';
|
|
2
2
|
import { Spacing } from '../createTheme/createSpacing';
|
|
3
|
-
import {
|
|
3
|
+
import { ResponsiveStyleValue } from '../styleFunctionSx';
|
|
4
|
+
import { GridDirection, GridOwnerState } from './GridProps';
|
|
4
5
|
interface Props {
|
|
5
6
|
theme: {
|
|
6
7
|
breakpoints: Breakpoints;
|
|
@@ -23,4 +24,5 @@ export declare const generateGridDirectionStyles: ({ theme, ownerState }: Props)
|
|
|
23
24
|
export declare const generateGridStyles: ({ ownerState }: Props) => {};
|
|
24
25
|
export declare const generateSizeClassNames: (gridSize: GridOwnerState['gridSize']) => string[];
|
|
25
26
|
export declare const generateSpacingClassNames: (spacing: GridOwnerState['spacing'], smallestBreakpoint?: string) => string[];
|
|
27
|
+
export declare const generateDirectionClasses: (direction: ResponsiveStyleValue<GridDirection> | undefined) => string[];
|
|
26
28
|
export {};
|
|
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.traverseBreakpoints = exports.generateSpacingClassNames = exports.generateSizeClassNames = exports.generateGridStyles = exports.generateGridSizeStyles = exports.generateGridRowSpacingStyles = exports.generateGridOffsetStyles = exports.generateGridDirectionStyles = exports.generateGridColumnsStyles = exports.generateGridColumnSpacingStyles = void 0;
|
|
8
|
+
exports.traverseBreakpoints = exports.generateSpacingClassNames = exports.generateSizeClassNames = exports.generateGridStyles = exports.generateGridSizeStyles = exports.generateGridRowSpacingStyles = exports.generateGridOffsetStyles = exports.generateGridDirectionStyles = exports.generateGridColumnsStyles = exports.generateGridColumnSpacingStyles = exports.generateDirectionClasses = void 0;
|
|
9
9
|
|
|
10
10
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
11
11
|
|
|
@@ -272,4 +272,18 @@ const generateSpacingClassNames = (spacing, smallestBreakpoint = 'xs') => {
|
|
|
272
272
|
return [];
|
|
273
273
|
};
|
|
274
274
|
|
|
275
|
-
exports.generateSpacingClassNames = generateSpacingClassNames;
|
|
275
|
+
exports.generateSpacingClassNames = generateSpacingClassNames;
|
|
276
|
+
|
|
277
|
+
const generateDirectionClasses = direction => {
|
|
278
|
+
if (direction === undefined) {
|
|
279
|
+
return [];
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
if (typeof direction === 'object') {
|
|
283
|
+
return Object.entries(direction).map(([key, value]) => `direction-${key}-${value}`);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
return [`direction-xs-${String(direction)}`];
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
exports.generateDirectionClasses = generateDirectionClasses;
|
|
@@ -39,11 +39,6 @@ export interface CssVarsProviderConfig<ColorScheme extends string> {
|
|
|
39
39
|
* @default false
|
|
40
40
|
*/
|
|
41
41
|
disableTransitionOnChange?: boolean;
|
|
42
|
-
/**
|
|
43
|
-
* Indicate to the browser which color scheme is used (light or dark) for rendering built-in UI
|
|
44
|
-
* @default true
|
|
45
|
-
*/
|
|
46
|
-
enableColorScheme?: boolean;
|
|
47
42
|
/**
|
|
48
43
|
* A function to determine if the key, value should be attached as CSS Variable
|
|
49
44
|
* `keys` is an array that represents the object path keys.
|
|
@@ -45,10 +45,9 @@ function createCssVarsProvider(options) {
|
|
|
45
45
|
attribute: defaultAttribute = _getInitColorSchemeScript.DEFAULT_ATTRIBUTE,
|
|
46
46
|
modeStorageKey: defaultModeStorageKey = _getInitColorSchemeScript.DEFAULT_MODE_STORAGE_KEY,
|
|
47
47
|
colorSchemeStorageKey: defaultColorSchemeStorageKey = _getInitColorSchemeScript.DEFAULT_COLOR_SCHEME_STORAGE_KEY,
|
|
48
|
-
defaultMode:
|
|
48
|
+
defaultMode: designSystemMode = 'light',
|
|
49
49
|
defaultColorScheme: designSystemColorScheme,
|
|
50
50
|
disableTransitionOnChange: designSystemTransitionOnChange = false,
|
|
51
|
-
enableColorScheme: designSystemEnableColorScheme = true,
|
|
52
51
|
shouldSkipGeneratingVar: designSystemShouldSkipGeneratingVar,
|
|
53
52
|
resolveTheme,
|
|
54
53
|
excludeVariablesFromRoot
|
|
@@ -76,10 +75,9 @@ function createCssVarsProvider(options) {
|
|
|
76
75
|
modeStorageKey = defaultModeStorageKey,
|
|
77
76
|
colorSchemeStorageKey = defaultColorSchemeStorageKey,
|
|
78
77
|
attribute = defaultAttribute,
|
|
79
|
-
defaultMode =
|
|
78
|
+
defaultMode = designSystemMode,
|
|
80
79
|
defaultColorScheme = designSystemColorScheme,
|
|
81
80
|
disableTransitionOnChange = designSystemTransitionOnChange,
|
|
82
|
-
enableColorScheme = designSystemEnableColorScheme,
|
|
83
81
|
storageWindow = typeof window === 'undefined' ? undefined : window,
|
|
84
82
|
documentNode = typeof document === 'undefined' ? undefined : document,
|
|
85
83
|
colorSchemeNode = typeof document === 'undefined' ? undefined : document.documentElement,
|
|
@@ -95,7 +93,8 @@ function createCssVarsProvider(options) {
|
|
|
95
93
|
restThemeProp = (0, _objectWithoutPropertiesLoose2.default)(themeProp, _excluded);
|
|
96
94
|
const allColorSchemes = Object.keys(colorSchemes);
|
|
97
95
|
const defaultLightColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.light;
|
|
98
|
-
const defaultDarkColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.dark;
|
|
96
|
+
const defaultDarkColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.dark; // 1. Get the data about the `mode`, `colorScheme`, and setter functions.
|
|
97
|
+
|
|
99
98
|
const {
|
|
100
99
|
mode,
|
|
101
100
|
setMode,
|
|
@@ -114,36 +113,53 @@ function createCssVarsProvider(options) {
|
|
|
114
113
|
storageWindow
|
|
115
114
|
});
|
|
116
115
|
|
|
117
|
-
const
|
|
116
|
+
const calculatedMode = (() => {
|
|
117
|
+
if (!mode) {
|
|
118
|
+
// This scope occurs on the server
|
|
119
|
+
if (defaultMode === 'system') {
|
|
120
|
+
return designSystemMode;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return defaultMode;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return mode;
|
|
127
|
+
})();
|
|
128
|
+
|
|
129
|
+
const calculatedColorScheme = (() => {
|
|
118
130
|
if (!colorScheme) {
|
|
119
131
|
// This scope occurs on the server
|
|
120
|
-
if (
|
|
132
|
+
if (calculatedMode === 'dark') {
|
|
121
133
|
return defaultDarkColorScheme;
|
|
122
|
-
} // use light color scheme, if default mode is 'light' | '
|
|
134
|
+
} // use light color scheme, if default mode is 'light' | 'system'
|
|
123
135
|
|
|
124
136
|
|
|
125
137
|
return defaultLightColorScheme;
|
|
126
138
|
}
|
|
127
139
|
|
|
128
140
|
return colorScheme;
|
|
129
|
-
})();
|
|
141
|
+
})(); // 2. Create CSS variables and store them in objects (to be generated in stylesheets in the final step)
|
|
142
|
+
|
|
130
143
|
|
|
131
|
-
let theme = restThemeProp;
|
|
132
144
|
const {
|
|
133
145
|
css: rootCss,
|
|
134
146
|
vars: rootVars,
|
|
135
147
|
parsedTheme
|
|
136
|
-
} = (0, _cssVarsParser.default)(
|
|
148
|
+
} = (0, _cssVarsParser.default)(restThemeProp, {
|
|
137
149
|
prefix: cssVarPrefix,
|
|
138
150
|
shouldSkipGeneratingVar
|
|
139
|
-
});
|
|
140
|
-
|
|
151
|
+
}); // 3. Start composing the theme object
|
|
152
|
+
|
|
153
|
+
let theme = (0, _extends2.default)({}, parsedTheme, {
|
|
141
154
|
components,
|
|
142
155
|
colorSchemes,
|
|
143
156
|
cssVarPrefix,
|
|
144
157
|
vars: rootVars,
|
|
145
158
|
getColorSchemeSelector: targetColorScheme => `[${attribute}="${targetColorScheme}"] &`
|
|
146
|
-
});
|
|
159
|
+
}); // 4. Create color CSS variables and store them in objects (to be generated in stylesheets in the final step)
|
|
160
|
+
// The default color scheme stylesheet is constructed to have the least CSS specificity.
|
|
161
|
+
// The other color schemes uses selector, default as data attribute, to increase the CSS specificity so that they can override the default color scheme stylesheet.
|
|
162
|
+
|
|
147
163
|
const defaultColorSchemeStyleSheet = {};
|
|
148
164
|
const otherColorSchemesStyleSheet = {};
|
|
149
165
|
Object.entries(colorSchemes).forEach(([key, scheme]) => {
|
|
@@ -157,13 +173,12 @@ function createCssVarsProvider(options) {
|
|
|
157
173
|
});
|
|
158
174
|
theme.vars = (0, _utils.deepmerge)(theme.vars, vars);
|
|
159
175
|
|
|
160
|
-
if (key ===
|
|
176
|
+
if (key === calculatedColorScheme) {
|
|
177
|
+
// 4.1 Merge the selected color scheme to the theme
|
|
161
178
|
theme = (0, _extends2.default)({}, theme, parsedScheme);
|
|
162
179
|
|
|
163
180
|
if (theme.palette) {
|
|
164
|
-
|
|
165
|
-
theme.palette.mode = mode;
|
|
166
|
-
theme.palette.colorScheme = resolvedColorScheme;
|
|
181
|
+
theme.palette.colorScheme = key;
|
|
167
182
|
}
|
|
168
183
|
}
|
|
169
184
|
|
|
@@ -193,35 +208,21 @@ function createCssVarsProvider(options) {
|
|
|
193
208
|
} else {
|
|
194
209
|
otherColorSchemesStyleSheet[`${colorSchemeSelector === ':root' ? '' : colorSchemeSelector}[${attribute}="${key}"]`] = css;
|
|
195
210
|
}
|
|
196
|
-
});
|
|
211
|
+
}); // 5. Declaring effects
|
|
212
|
+
// 5.1 Updates the selector value to use the current color scheme which tells CSS to use the proper stylesheet.
|
|
213
|
+
|
|
197
214
|
React.useEffect(() => {
|
|
198
215
|
if (colorScheme && colorSchemeNode) {
|
|
199
216
|
// attaches attribute to <html> because the css variables are attached to :root (html)
|
|
200
217
|
colorSchemeNode.setAttribute(attribute, colorScheme);
|
|
201
218
|
}
|
|
202
|
-
}, [colorScheme, attribute, colorSchemeNode]);
|
|
203
|
-
|
|
204
|
-
if (!mode || !enableColorScheme || !colorSchemeNode) {
|
|
205
|
-
return undefined;
|
|
206
|
-
}
|
|
219
|
+
}, [colorScheme, attribute, colorSchemeNode]); // 5.2 Remove the CSS transition when color scheme changes to create instant experience.
|
|
220
|
+
// credit: https://github.com/pacocoursey/next-themes/blob/b5c2bad50de2d61ad7b52a9c5cdc801a78507d7a/index.tsx#L313
|
|
207
221
|
|
|
208
|
-
const priorColorScheme = colorSchemeNode.style.getPropertyValue('color-scheme'); // `color-scheme` tells browser to render built-in elements according to its value: `light` or `dark`
|
|
209
|
-
|
|
210
|
-
if (mode === 'system') {
|
|
211
|
-
colorSchemeNode.style.setProperty('color-scheme', systemMode);
|
|
212
|
-
} else {
|
|
213
|
-
colorSchemeNode.style.setProperty('color-scheme', mode);
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
return () => {
|
|
217
|
-
colorSchemeNode.style.setProperty('color-scheme', priorColorScheme);
|
|
218
|
-
};
|
|
219
|
-
}, [mode, systemMode, enableColorScheme, colorSchemeNode]);
|
|
220
222
|
React.useEffect(() => {
|
|
221
223
|
let timer;
|
|
222
224
|
|
|
223
225
|
if (disableTransitionOnChange && hasMounted.current && documentNode) {
|
|
224
|
-
// credit: https://github.com/pacocoursey/next-themes/blob/b5c2bad50de2d61ad7b52a9c5cdc801a78507d7a/index.tsx#L313
|
|
225
226
|
const css = documentNode.createElement('style');
|
|
226
227
|
css.appendChild(documentNode.createTextNode(DISABLE_CSS_TRANSITION));
|
|
227
228
|
documentNode.head.appendChild(css); // Force browser repaint
|
|
@@ -246,6 +247,7 @@ function createCssVarsProvider(options) {
|
|
|
246
247
|
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(ColorSchemeContext.Provider, {
|
|
247
248
|
value: {
|
|
248
249
|
mode,
|
|
250
|
+
systemMode,
|
|
249
251
|
setMode,
|
|
250
252
|
lightColorScheme,
|
|
251
253
|
darkColorScheme,
|
|
@@ -314,11 +316,6 @@ function createCssVarsProvider(options) {
|
|
|
314
316
|
*/
|
|
315
317
|
documentNode: _propTypes.default.any,
|
|
316
318
|
|
|
317
|
-
/**
|
|
318
|
-
* Indicate to the browser which color scheme is used (light or dark) for rendering built-in UI
|
|
319
|
-
*/
|
|
320
|
-
enableColorScheme: _propTypes.default.bool,
|
|
321
|
-
|
|
322
319
|
/**
|
|
323
320
|
* The key in the local storage used to store current color scheme.
|
|
324
321
|
*/
|
|
@@ -340,12 +337,16 @@ function createCssVarsProvider(options) {
|
|
|
340
337
|
*/
|
|
341
338
|
theme: _propTypes.default.object
|
|
342
339
|
} : void 0;
|
|
340
|
+
const defaultLightColorScheme = typeof designSystemColorScheme === 'string' ? designSystemColorScheme : designSystemColorScheme.light;
|
|
341
|
+
const defaultDarkColorScheme = typeof designSystemColorScheme === 'string' ? designSystemColorScheme : designSystemColorScheme.dark;
|
|
343
342
|
|
|
344
343
|
const getInitColorSchemeScript = params => (0, _getInitColorSchemeScript.default)((0, _extends2.default)({
|
|
345
344
|
attribute: defaultAttribute,
|
|
346
345
|
colorSchemeStorageKey: defaultColorSchemeStorageKey,
|
|
347
|
-
|
|
348
|
-
|
|
346
|
+
defaultMode: designSystemMode,
|
|
347
|
+
defaultLightColorScheme,
|
|
348
|
+
defaultDarkColorScheme,
|
|
349
|
+
modeStorageKey: defaultModeStorageKey
|
|
349
350
|
}, params));
|
|
350
351
|
|
|
351
352
|
return {
|
|
@@ -3,11 +3,6 @@ export declare const DEFAULT_MODE_STORAGE_KEY = "mode";
|
|
|
3
3
|
export declare const DEFAULT_COLOR_SCHEME_STORAGE_KEY = "color-scheme";
|
|
4
4
|
export declare const DEFAULT_ATTRIBUTE = "data-color-scheme";
|
|
5
5
|
export interface GetInitColorSchemeScriptOptions {
|
|
6
|
-
/**
|
|
7
|
-
* Indicate to the browser which color scheme is used (light or dark) for rendering built-in UI
|
|
8
|
-
* @default true
|
|
9
|
-
*/
|
|
10
|
-
enableColorScheme?: boolean;
|
|
11
6
|
/**
|
|
12
7
|
* The mode to be used for the first visit
|
|
13
8
|
* @default 'light'
|
|
@@ -23,7 +23,6 @@ exports.DEFAULT_ATTRIBUTE = DEFAULT_ATTRIBUTE;
|
|
|
23
23
|
|
|
24
24
|
function getInitColorSchemeScript(options) {
|
|
25
25
|
const {
|
|
26
|
-
enableColorScheme = true,
|
|
27
26
|
defaultMode = 'light',
|
|
28
27
|
defaultLightColorScheme = 'light',
|
|
29
28
|
defaultDarkColorScheme = 'dark',
|
|
@@ -59,9 +58,6 @@ function getInitColorSchemeScript(options) {
|
|
|
59
58
|
if (colorScheme) {
|
|
60
59
|
${colorSchemeNode}.setAttribute('${attribute}', colorScheme);
|
|
61
60
|
}
|
|
62
|
-
if (${enableColorScheme} && !!cssColorScheme) {
|
|
63
|
-
${colorSchemeNode}.style.setProperty('color-scheme', cssColorScheme);
|
|
64
|
-
}
|
|
65
61
|
} catch (e) {} })();`
|
|
66
62
|
}
|
|
67
63
|
});
|
|
@@ -10,7 +10,7 @@ import useThemePropsSystem from '../useThemeProps';
|
|
|
10
10
|
import useTheme from '../useTheme';
|
|
11
11
|
import { extendSxProp } from '../styleFunctionSx';
|
|
12
12
|
import createTheme from '../createTheme';
|
|
13
|
-
import { generateGridStyles, generateGridSizeStyles, generateGridColumnsStyles, generateGridColumnSpacingStyles, generateGridRowSpacingStyles, generateGridDirectionStyles, generateGridOffsetStyles, generateSizeClassNames, generateSpacingClassNames } from './gridGenerator';
|
|
13
|
+
import { generateGridStyles, generateGridSizeStyles, generateGridColumnsStyles, generateGridColumnSpacingStyles, generateGridRowSpacingStyles, generateGridDirectionStyles, generateGridOffsetStyles, generateSizeClassNames, generateSpacingClassNames, generateDirectionClasses } from './gridGenerator';
|
|
14
14
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
15
15
|
const defaultTheme = createTheme(); // widening Theme to any so that the consumer can own the theme structure.
|
|
16
16
|
|
|
@@ -47,7 +47,7 @@ export default function createGrid(options = {}) {
|
|
|
47
47
|
gridSize
|
|
48
48
|
} = ownerState;
|
|
49
49
|
const slots = {
|
|
50
|
-
root: ['root', container && 'container',
|
|
50
|
+
root: ['root', container && 'container', wrap !== 'wrap' && `wrap-xs-${String(wrap)}`, ...generateDirectionClasses(direction), ...generateSizeClassNames(gridSize), ...(container ? generateSpacingClassNames(spacing, theme.breakpoints.keys[0]) : [])]
|
|
51
51
|
};
|
|
52
52
|
return composeClasses(slots, slot => generateUtilityClass(componentName, slot), {});
|
|
53
53
|
};
|
|
@@ -233,4 +233,15 @@ export const generateSpacingClassNames = (spacing, smallestBreakpoint = 'xs') =>
|
|
|
233
233
|
}
|
|
234
234
|
|
|
235
235
|
return [];
|
|
236
|
+
};
|
|
237
|
+
export const generateDirectionClasses = direction => {
|
|
238
|
+
if (direction === undefined) {
|
|
239
|
+
return [];
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
if (typeof direction === 'object') {
|
|
243
|
+
return Object.entries(direction).map(([key, value]) => `direction-${key}-${value}`);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
return [`direction-xs-${String(direction)}`];
|
|
236
247
|
};
|
|
@@ -4,7 +4,7 @@ import { formatMuiErrorMessage as _formatMuiErrorMessage } from "@mui/utils";
|
|
|
4
4
|
const _excluded = ["colorSchemes", "components", "cssVarPrefix"];
|
|
5
5
|
import * as React from 'react';
|
|
6
6
|
import PropTypes from 'prop-types';
|
|
7
|
-
import { deepmerge
|
|
7
|
+
import { deepmerge } from '@mui/utils';
|
|
8
8
|
import { GlobalStyles } from '@mui/styled-engine';
|
|
9
9
|
import cssVarsParser from './cssVarsParser';
|
|
10
10
|
import ThemeProvider from '../ThemeProvider';
|
|
@@ -19,10 +19,9 @@ export default function createCssVarsProvider(options) {
|
|
|
19
19
|
attribute: defaultAttribute = DEFAULT_ATTRIBUTE,
|
|
20
20
|
modeStorageKey: defaultModeStorageKey = DEFAULT_MODE_STORAGE_KEY,
|
|
21
21
|
colorSchemeStorageKey: defaultColorSchemeStorageKey = DEFAULT_COLOR_SCHEME_STORAGE_KEY,
|
|
22
|
-
defaultMode:
|
|
22
|
+
defaultMode: designSystemMode = 'light',
|
|
23
23
|
defaultColorScheme: designSystemColorScheme,
|
|
24
24
|
disableTransitionOnChange: designSystemTransitionOnChange = false,
|
|
25
|
-
enableColorScheme: designSystemEnableColorScheme = true,
|
|
26
25
|
shouldSkipGeneratingVar: designSystemShouldSkipGeneratingVar,
|
|
27
26
|
resolveTheme,
|
|
28
27
|
excludeVariablesFromRoot
|
|
@@ -50,10 +49,9 @@ export default function createCssVarsProvider(options) {
|
|
|
50
49
|
modeStorageKey = defaultModeStorageKey,
|
|
51
50
|
colorSchemeStorageKey = defaultColorSchemeStorageKey,
|
|
52
51
|
attribute = defaultAttribute,
|
|
53
|
-
defaultMode =
|
|
52
|
+
defaultMode = designSystemMode,
|
|
54
53
|
defaultColorScheme = designSystemColorScheme,
|
|
55
54
|
disableTransitionOnChange = designSystemTransitionOnChange,
|
|
56
|
-
enableColorScheme = designSystemEnableColorScheme,
|
|
57
55
|
storageWindow = typeof window === 'undefined' ? undefined : window,
|
|
58
56
|
documentNode = typeof document === 'undefined' ? undefined : document,
|
|
59
57
|
colorSchemeNode = typeof document === 'undefined' ? undefined : document.documentElement,
|
|
@@ -71,7 +69,8 @@ export default function createCssVarsProvider(options) {
|
|
|
71
69
|
|
|
72
70
|
const allColorSchemes = Object.keys(colorSchemes);
|
|
73
71
|
const defaultLightColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.light;
|
|
74
|
-
const defaultDarkColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.dark;
|
|
72
|
+
const defaultDarkColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.dark; // 1. Get the data about the `mode`, `colorScheme`, and setter functions.
|
|
73
|
+
|
|
75
74
|
const {
|
|
76
75
|
mode,
|
|
77
76
|
setMode,
|
|
@@ -90,36 +89,54 @@ export default function createCssVarsProvider(options) {
|
|
|
90
89
|
storageWindow
|
|
91
90
|
});
|
|
92
91
|
|
|
93
|
-
const
|
|
92
|
+
const calculatedMode = (() => {
|
|
93
|
+
if (!mode) {
|
|
94
|
+
// This scope occurs on the server
|
|
95
|
+
if (defaultMode === 'system') {
|
|
96
|
+
return designSystemMode;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return defaultMode;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return mode;
|
|
103
|
+
})();
|
|
104
|
+
|
|
105
|
+
const calculatedColorScheme = (() => {
|
|
94
106
|
if (!colorScheme) {
|
|
95
107
|
// This scope occurs on the server
|
|
96
|
-
if (
|
|
108
|
+
if (calculatedMode === 'dark') {
|
|
97
109
|
return defaultDarkColorScheme;
|
|
98
|
-
} // use light color scheme, if default mode is 'light' | '
|
|
110
|
+
} // use light color scheme, if default mode is 'light' | 'system'
|
|
99
111
|
|
|
100
112
|
|
|
101
113
|
return defaultLightColorScheme;
|
|
102
114
|
}
|
|
103
115
|
|
|
104
116
|
return colorScheme;
|
|
105
|
-
})();
|
|
117
|
+
})(); // 2. Create CSS variables and store them in objects (to be generated in stylesheets in the final step)
|
|
118
|
+
|
|
106
119
|
|
|
107
|
-
let theme = restThemeProp;
|
|
108
120
|
const {
|
|
109
121
|
css: rootCss,
|
|
110
122
|
vars: rootVars,
|
|
111
123
|
parsedTheme
|
|
112
|
-
} = cssVarsParser(
|
|
124
|
+
} = cssVarsParser(restThemeProp, {
|
|
113
125
|
prefix: cssVarPrefix,
|
|
114
126
|
shouldSkipGeneratingVar
|
|
115
|
-
});
|
|
116
|
-
|
|
127
|
+
}); // 3. Start composing the theme object
|
|
128
|
+
|
|
129
|
+
let theme = _extends({}, parsedTheme, {
|
|
117
130
|
components,
|
|
118
131
|
colorSchemes,
|
|
119
132
|
cssVarPrefix,
|
|
120
133
|
vars: rootVars,
|
|
121
134
|
getColorSchemeSelector: targetColorScheme => `[${attribute}="${targetColorScheme}"] &`
|
|
122
|
-
});
|
|
135
|
+
}); // 4. Create color CSS variables and store them in objects (to be generated in stylesheets in the final step)
|
|
136
|
+
// The default color scheme stylesheet is constructed to have the least CSS specificity.
|
|
137
|
+
// The other color schemes uses selector, default as data attribute, to increase the CSS specificity so that they can override the default color scheme stylesheet.
|
|
138
|
+
|
|
139
|
+
|
|
123
140
|
const defaultColorSchemeStyleSheet = {};
|
|
124
141
|
const otherColorSchemesStyleSheet = {};
|
|
125
142
|
Object.entries(colorSchemes).forEach(([key, scheme]) => {
|
|
@@ -133,13 +150,12 @@ export default function createCssVarsProvider(options) {
|
|
|
133
150
|
});
|
|
134
151
|
theme.vars = deepmerge(theme.vars, vars);
|
|
135
152
|
|
|
136
|
-
if (key ===
|
|
153
|
+
if (key === calculatedColorScheme) {
|
|
154
|
+
// 4.1 Merge the selected color scheme to the theme
|
|
137
155
|
theme = _extends({}, theme, parsedScheme);
|
|
138
156
|
|
|
139
157
|
if (theme.palette) {
|
|
140
|
-
|
|
141
|
-
theme.palette.mode = mode;
|
|
142
|
-
theme.palette.colorScheme = resolvedColorScheme;
|
|
158
|
+
theme.palette.colorScheme = key;
|
|
143
159
|
}
|
|
144
160
|
}
|
|
145
161
|
|
|
@@ -169,35 +185,21 @@ export default function createCssVarsProvider(options) {
|
|
|
169
185
|
} else {
|
|
170
186
|
otherColorSchemesStyleSheet[`${colorSchemeSelector === ':root' ? '' : colorSchemeSelector}[${attribute}="${key}"]`] = css;
|
|
171
187
|
}
|
|
172
|
-
});
|
|
188
|
+
}); // 5. Declaring effects
|
|
189
|
+
// 5.1 Updates the selector value to use the current color scheme which tells CSS to use the proper stylesheet.
|
|
190
|
+
|
|
173
191
|
React.useEffect(() => {
|
|
174
192
|
if (colorScheme && colorSchemeNode) {
|
|
175
193
|
// attaches attribute to <html> because the css variables are attached to :root (html)
|
|
176
194
|
colorSchemeNode.setAttribute(attribute, colorScheme);
|
|
177
195
|
}
|
|
178
|
-
}, [colorScheme, attribute, colorSchemeNode]);
|
|
179
|
-
|
|
180
|
-
if (!mode || !enableColorScheme || !colorSchemeNode) {
|
|
181
|
-
return undefined;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
const priorColorScheme = colorSchemeNode.style.getPropertyValue('color-scheme'); // `color-scheme` tells browser to render built-in elements according to its value: `light` or `dark`
|
|
185
|
-
|
|
186
|
-
if (mode === 'system') {
|
|
187
|
-
colorSchemeNode.style.setProperty('color-scheme', systemMode);
|
|
188
|
-
} else {
|
|
189
|
-
colorSchemeNode.style.setProperty('color-scheme', mode);
|
|
190
|
-
}
|
|
196
|
+
}, [colorScheme, attribute, colorSchemeNode]); // 5.2 Remove the CSS transition when color scheme changes to create instant experience.
|
|
197
|
+
// credit: https://github.com/pacocoursey/next-themes/blob/b5c2bad50de2d61ad7b52a9c5cdc801a78507d7a/index.tsx#L313
|
|
191
198
|
|
|
192
|
-
return () => {
|
|
193
|
-
colorSchemeNode.style.setProperty('color-scheme', priorColorScheme);
|
|
194
|
-
};
|
|
195
|
-
}, [mode, systemMode, enableColorScheme, colorSchemeNode]);
|
|
196
199
|
React.useEffect(() => {
|
|
197
200
|
let timer;
|
|
198
201
|
|
|
199
202
|
if (disableTransitionOnChange && hasMounted.current && documentNode) {
|
|
200
|
-
// credit: https://github.com/pacocoursey/next-themes/blob/b5c2bad50de2d61ad7b52a9c5cdc801a78507d7a/index.tsx#L313
|
|
201
203
|
const css = documentNode.createElement('style');
|
|
202
204
|
css.appendChild(documentNode.createTextNode(DISABLE_CSS_TRANSITION));
|
|
203
205
|
documentNode.head.appendChild(css); // Force browser repaint
|
|
@@ -222,6 +224,7 @@ export default function createCssVarsProvider(options) {
|
|
|
222
224
|
return /*#__PURE__*/_jsxs(ColorSchemeContext.Provider, {
|
|
223
225
|
value: {
|
|
224
226
|
mode,
|
|
227
|
+
systemMode,
|
|
225
228
|
setMode,
|
|
226
229
|
lightColorScheme,
|
|
227
230
|
darkColorScheme,
|
|
@@ -290,11 +293,6 @@ export default function createCssVarsProvider(options) {
|
|
|
290
293
|
*/
|
|
291
294
|
documentNode: PropTypes.any,
|
|
292
295
|
|
|
293
|
-
/**
|
|
294
|
-
* Indicate to the browser which color scheme is used (light or dark) for rendering built-in UI
|
|
295
|
-
*/
|
|
296
|
-
enableColorScheme: PropTypes.bool,
|
|
297
|
-
|
|
298
296
|
/**
|
|
299
297
|
* The key in the local storage used to store current color scheme.
|
|
300
298
|
*/
|
|
@@ -316,12 +314,16 @@ export default function createCssVarsProvider(options) {
|
|
|
316
314
|
*/
|
|
317
315
|
theme: PropTypes.object
|
|
318
316
|
} : void 0;
|
|
317
|
+
const defaultLightColorScheme = typeof designSystemColorScheme === 'string' ? designSystemColorScheme : designSystemColorScheme.light;
|
|
318
|
+
const defaultDarkColorScheme = typeof designSystemColorScheme === 'string' ? designSystemColorScheme : designSystemColorScheme.dark;
|
|
319
319
|
|
|
320
320
|
const getInitColorSchemeScript = params => systemGetInitColorSchemeScript(_extends({
|
|
321
321
|
attribute: defaultAttribute,
|
|
322
322
|
colorSchemeStorageKey: defaultColorSchemeStorageKey,
|
|
323
|
-
|
|
324
|
-
|
|
323
|
+
defaultMode: designSystemMode,
|
|
324
|
+
defaultLightColorScheme,
|
|
325
|
+
defaultDarkColorScheme,
|
|
326
|
+
modeStorageKey: defaultModeStorageKey
|
|
325
327
|
}, params));
|
|
326
328
|
|
|
327
329
|
return {
|
|
@@ -5,7 +5,6 @@ export const DEFAULT_COLOR_SCHEME_STORAGE_KEY = 'color-scheme';
|
|
|
5
5
|
export const DEFAULT_ATTRIBUTE = 'data-color-scheme';
|
|
6
6
|
export default function getInitColorSchemeScript(options) {
|
|
7
7
|
const {
|
|
8
|
-
enableColorScheme = true,
|
|
9
8
|
defaultMode = 'light',
|
|
10
9
|
defaultLightColorScheme = 'light',
|
|
11
10
|
defaultDarkColorScheme = 'dark',
|
|
@@ -41,9 +40,6 @@ export default function getInitColorSchemeScript(options) {
|
|
|
41
40
|
if (colorScheme) {
|
|
42
41
|
${colorSchemeNode}.setAttribute('${attribute}', colorScheme);
|
|
43
42
|
}
|
|
44
|
-
if (${enableColorScheme} && !!cssColorScheme) {
|
|
45
|
-
${colorSchemeNode}.style.setProperty('color-scheme', cssColorScheme);
|
|
46
|
-
}
|
|
47
43
|
} catch (e) {} })();`
|
|
48
44
|
}
|
|
49
45
|
});
|
package/index.js
CHANGED
|
@@ -11,7 +11,7 @@ import useThemePropsSystem from '../useThemeProps';
|
|
|
11
11
|
import useTheme from '../useTheme';
|
|
12
12
|
import { extendSxProp } from '../styleFunctionSx';
|
|
13
13
|
import createTheme from '../createTheme';
|
|
14
|
-
import { generateGridStyles, generateGridSizeStyles, generateGridColumnsStyles, generateGridColumnSpacingStyles, generateGridRowSpacingStyles, generateGridDirectionStyles, generateGridOffsetStyles, generateSizeClassNames, generateSpacingClassNames } from './gridGenerator';
|
|
14
|
+
import { generateGridStyles, generateGridSizeStyles, generateGridColumnsStyles, generateGridColumnSpacingStyles, generateGridRowSpacingStyles, generateGridDirectionStyles, generateGridOffsetStyles, generateSizeClassNames, generateSpacingClassNames, generateDirectionClasses } from './gridGenerator';
|
|
15
15
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
16
16
|
var defaultTheme = createTheme(); // widening Theme to any so that the consumer can own the theme structure.
|
|
17
17
|
|
|
@@ -49,7 +49,7 @@ export default function createGrid() {
|
|
|
49
49
|
wrap = ownerState.wrap,
|
|
50
50
|
gridSize = ownerState.gridSize;
|
|
51
51
|
var slots = {
|
|
52
|
-
root: ['root', container && 'container',
|
|
52
|
+
root: ['root', container && 'container', wrap !== 'wrap' && "wrap-xs-".concat(String(wrap))].concat(_toConsumableArray(generateDirectionClasses(direction)), _toConsumableArray(generateSizeClassNames(gridSize)), _toConsumableArray(container ? generateSpacingClassNames(spacing, theme.breakpoints.keys[0]) : []))
|
|
53
53
|
};
|
|
54
54
|
return composeClasses(slots, function (slot) {
|
|
55
55
|
return generateUtilityClass(componentName, slot);
|
|
@@ -242,4 +242,21 @@ export var generateSpacingClassNames = function generateSpacingClassNames(spacin
|
|
|
242
242
|
}
|
|
243
243
|
|
|
244
244
|
return [];
|
|
245
|
+
};
|
|
246
|
+
export var generateDirectionClasses = function generateDirectionClasses(direction) {
|
|
247
|
+
if (direction === undefined) {
|
|
248
|
+
return [];
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
if (_typeof(direction) === 'object') {
|
|
252
|
+
return Object.entries(direction).map(function (_ref12) {
|
|
253
|
+
var _ref13 = _slicedToArray(_ref12, 2),
|
|
254
|
+
key = _ref13[0],
|
|
255
|
+
value = _ref13[1];
|
|
256
|
+
|
|
257
|
+
return "direction-".concat(key, "-").concat(value);
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
return ["direction-xs-".concat(String(direction))];
|
|
245
262
|
};
|
|
@@ -6,7 +6,7 @@ import _typeof from "@babel/runtime/helpers/esm/typeof";
|
|
|
6
6
|
import { formatMuiErrorMessage as _formatMuiErrorMessage } from "@mui/utils";
|
|
7
7
|
import * as React from 'react';
|
|
8
8
|
import PropTypes from 'prop-types';
|
|
9
|
-
import { deepmerge
|
|
9
|
+
import { deepmerge } from '@mui/utils';
|
|
10
10
|
import { GlobalStyles } from '@mui/styled-engine';
|
|
11
11
|
import cssVarsParser from './cssVarsParser';
|
|
12
12
|
import ThemeProvider from '../ThemeProvider';
|
|
@@ -25,12 +25,10 @@ export default function createCssVarsProvider(options) {
|
|
|
25
25
|
_options$colorSchemeS = options.colorSchemeStorageKey,
|
|
26
26
|
defaultColorSchemeStorageKey = _options$colorSchemeS === void 0 ? DEFAULT_COLOR_SCHEME_STORAGE_KEY : _options$colorSchemeS,
|
|
27
27
|
_options$defaultMode = options.defaultMode,
|
|
28
|
-
|
|
28
|
+
designSystemMode = _options$defaultMode === void 0 ? 'light' : _options$defaultMode,
|
|
29
29
|
designSystemColorScheme = options.defaultColorScheme,
|
|
30
30
|
_options$disableTrans = options.disableTransitionOnChange,
|
|
31
31
|
designSystemTransitionOnChange = _options$disableTrans === void 0 ? false : _options$disableTrans,
|
|
32
|
-
_options$enableColorS = options.enableColorScheme,
|
|
33
|
-
designSystemEnableColorScheme = _options$enableColorS === void 0 ? true : _options$enableColorS,
|
|
34
32
|
designSystemShouldSkipGeneratingVar = options.shouldSkipGeneratingVar,
|
|
35
33
|
resolveTheme = options.resolveTheme,
|
|
36
34
|
excludeVariablesFromRoot = options.excludeVariablesFromRoot;
|
|
@@ -62,13 +60,11 @@ export default function createCssVarsProvider(options) {
|
|
|
62
60
|
_ref$attribute = _ref.attribute,
|
|
63
61
|
attribute = _ref$attribute === void 0 ? defaultAttribute : _ref$attribute,
|
|
64
62
|
_ref$defaultMode = _ref.defaultMode,
|
|
65
|
-
defaultMode = _ref$defaultMode === void 0 ?
|
|
63
|
+
defaultMode = _ref$defaultMode === void 0 ? designSystemMode : _ref$defaultMode,
|
|
66
64
|
_ref$defaultColorSche = _ref.defaultColorScheme,
|
|
67
65
|
defaultColorScheme = _ref$defaultColorSche === void 0 ? designSystemColorScheme : _ref$defaultColorSche,
|
|
68
66
|
_ref$disableTransitio = _ref.disableTransitionOnChange,
|
|
69
67
|
disableTransitionOnChange = _ref$disableTransitio === void 0 ? designSystemTransitionOnChange : _ref$disableTransitio,
|
|
70
|
-
_ref$enableColorSchem = _ref.enableColorScheme,
|
|
71
|
-
enableColorScheme = _ref$enableColorSchem === void 0 ? designSystemEnableColorScheme : _ref$enableColorSchem,
|
|
72
68
|
_ref$storageWindow = _ref.storageWindow,
|
|
73
69
|
storageWindow = _ref$storageWindow === void 0 ? typeof window === 'undefined' ? undefined : window : _ref$storageWindow,
|
|
74
70
|
_ref$documentNode = _ref.documentNode,
|
|
@@ -90,7 +86,7 @@ export default function createCssVarsProvider(options) {
|
|
|
90
86
|
|
|
91
87
|
var allColorSchemes = Object.keys(colorSchemes);
|
|
92
88
|
var defaultLightColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.light;
|
|
93
|
-
var defaultDarkColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.dark;
|
|
89
|
+
var defaultDarkColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.dark; // 1. Get the data about the `mode`, `colorScheme`, and setter functions.
|
|
94
90
|
|
|
95
91
|
var _useCurrentColorSchem = useCurrentColorScheme({
|
|
96
92
|
supportedColorSchemes: allColorSchemes,
|
|
@@ -109,31 +105,44 @@ export default function createCssVarsProvider(options) {
|
|
|
109
105
|
colorScheme = _useCurrentColorSchem.colorScheme,
|
|
110
106
|
setColorScheme = _useCurrentColorSchem.setColorScheme;
|
|
111
107
|
|
|
112
|
-
var
|
|
108
|
+
var calculatedMode = function () {
|
|
109
|
+
if (!mode) {
|
|
110
|
+
// This scope occurs on the server
|
|
111
|
+
if (defaultMode === 'system') {
|
|
112
|
+
return designSystemMode;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return defaultMode;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return mode;
|
|
119
|
+
}();
|
|
120
|
+
|
|
121
|
+
var calculatedColorScheme = function () {
|
|
113
122
|
if (!colorScheme) {
|
|
114
123
|
// This scope occurs on the server
|
|
115
|
-
if (
|
|
124
|
+
if (calculatedMode === 'dark') {
|
|
116
125
|
return defaultDarkColorScheme;
|
|
117
|
-
} // use light color scheme, if default mode is 'light' | '
|
|
126
|
+
} // use light color scheme, if default mode is 'light' | 'system'
|
|
118
127
|
|
|
119
128
|
|
|
120
129
|
return defaultLightColorScheme;
|
|
121
130
|
}
|
|
122
131
|
|
|
123
132
|
return colorScheme;
|
|
124
|
-
}();
|
|
133
|
+
}(); // 2. Create CSS variables and store them in objects (to be generated in stylesheets in the final step)
|
|
125
134
|
|
|
126
|
-
var theme = restThemeProp;
|
|
127
135
|
|
|
128
|
-
var _cssVarsParser = cssVarsParser(
|
|
136
|
+
var _cssVarsParser = cssVarsParser(restThemeProp, {
|
|
129
137
|
prefix: cssVarPrefix,
|
|
130
138
|
shouldSkipGeneratingVar: shouldSkipGeneratingVar
|
|
131
139
|
}),
|
|
132
140
|
rootCss = _cssVarsParser.css,
|
|
133
141
|
rootVars = _cssVarsParser.vars,
|
|
134
|
-
parsedTheme = _cssVarsParser.parsedTheme;
|
|
142
|
+
parsedTheme = _cssVarsParser.parsedTheme; // 3. Start composing the theme object
|
|
135
143
|
|
|
136
|
-
|
|
144
|
+
|
|
145
|
+
var theme = _extends({}, parsedTheme, {
|
|
137
146
|
components: components,
|
|
138
147
|
colorSchemes: colorSchemes,
|
|
139
148
|
cssVarPrefix: cssVarPrefix,
|
|
@@ -141,7 +150,11 @@ export default function createCssVarsProvider(options) {
|
|
|
141
150
|
getColorSchemeSelector: function getColorSchemeSelector(targetColorScheme) {
|
|
142
151
|
return "[".concat(attribute, "=\"").concat(targetColorScheme, "\"] &");
|
|
143
152
|
}
|
|
144
|
-
});
|
|
153
|
+
}); // 4. Create color CSS variables and store them in objects (to be generated in stylesheets in the final step)
|
|
154
|
+
// The default color scheme stylesheet is constructed to have the least CSS specificity.
|
|
155
|
+
// The other color schemes uses selector, default as data attribute, to increase the CSS specificity so that they can override the default color scheme stylesheet.
|
|
156
|
+
|
|
157
|
+
|
|
145
158
|
var defaultColorSchemeStyleSheet = {};
|
|
146
159
|
var otherColorSchemesStyleSheet = {};
|
|
147
160
|
Object.entries(colorSchemes).forEach(function (_ref2) {
|
|
@@ -159,13 +172,12 @@ export default function createCssVarsProvider(options) {
|
|
|
159
172
|
|
|
160
173
|
theme.vars = deepmerge(theme.vars, vars);
|
|
161
174
|
|
|
162
|
-
if (key ===
|
|
175
|
+
if (key === calculatedColorScheme) {
|
|
176
|
+
// 4.1 Merge the selected color scheme to the theme
|
|
163
177
|
theme = _extends({}, theme, parsedScheme);
|
|
164
178
|
|
|
165
179
|
if (theme.palette) {
|
|
166
|
-
|
|
167
|
-
theme.palette.mode = mode;
|
|
168
|
-
theme.palette.colorScheme = resolvedColorScheme;
|
|
180
|
+
theme.palette.colorScheme = key;
|
|
169
181
|
}
|
|
170
182
|
}
|
|
171
183
|
|
|
@@ -195,35 +207,21 @@ export default function createCssVarsProvider(options) {
|
|
|
195
207
|
} else {
|
|
196
208
|
otherColorSchemesStyleSheet["".concat(colorSchemeSelector === ':root' ? '' : colorSchemeSelector, "[").concat(attribute, "=\"").concat(key, "\"]")] = css;
|
|
197
209
|
}
|
|
198
|
-
});
|
|
210
|
+
}); // 5. Declaring effects
|
|
211
|
+
// 5.1 Updates the selector value to use the current color scheme which tells CSS to use the proper stylesheet.
|
|
212
|
+
|
|
199
213
|
React.useEffect(function () {
|
|
200
214
|
if (colorScheme && colorSchemeNode) {
|
|
201
215
|
// attaches attribute to <html> because the css variables are attached to :root (html)
|
|
202
216
|
colorSchemeNode.setAttribute(attribute, colorScheme);
|
|
203
217
|
}
|
|
204
|
-
}, [colorScheme, attribute, colorSchemeNode]);
|
|
205
|
-
|
|
206
|
-
if (!mode || !enableColorScheme || !colorSchemeNode) {
|
|
207
|
-
return undefined;
|
|
208
|
-
}
|
|
218
|
+
}, [colorScheme, attribute, colorSchemeNode]); // 5.2 Remove the CSS transition when color scheme changes to create instant experience.
|
|
219
|
+
// credit: https://github.com/pacocoursey/next-themes/blob/b5c2bad50de2d61ad7b52a9c5cdc801a78507d7a/index.tsx#L313
|
|
209
220
|
|
|
210
|
-
var priorColorScheme = colorSchemeNode.style.getPropertyValue('color-scheme'); // `color-scheme` tells browser to render built-in elements according to its value: `light` or `dark`
|
|
211
|
-
|
|
212
|
-
if (mode === 'system') {
|
|
213
|
-
colorSchemeNode.style.setProperty('color-scheme', systemMode);
|
|
214
|
-
} else {
|
|
215
|
-
colorSchemeNode.style.setProperty('color-scheme', mode);
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
return function () {
|
|
219
|
-
colorSchemeNode.style.setProperty('color-scheme', priorColorScheme);
|
|
220
|
-
};
|
|
221
|
-
}, [mode, systemMode, enableColorScheme, colorSchemeNode]);
|
|
222
221
|
React.useEffect(function () {
|
|
223
222
|
var timer;
|
|
224
223
|
|
|
225
224
|
if (disableTransitionOnChange && hasMounted.current && documentNode) {
|
|
226
|
-
// credit: https://github.com/pacocoursey/next-themes/blob/b5c2bad50de2d61ad7b52a9c5cdc801a78507d7a/index.tsx#L313
|
|
227
225
|
var css = documentNode.createElement('style');
|
|
228
226
|
css.appendChild(documentNode.createTextNode(DISABLE_CSS_TRANSITION));
|
|
229
227
|
documentNode.head.appendChild(css); // Force browser repaint
|
|
@@ -250,6 +248,7 @@ export default function createCssVarsProvider(options) {
|
|
|
250
248
|
return /*#__PURE__*/_jsxs(ColorSchemeContext.Provider, {
|
|
251
249
|
value: {
|
|
252
250
|
mode: mode,
|
|
251
|
+
systemMode: systemMode,
|
|
253
252
|
setMode: setMode,
|
|
254
253
|
lightColorScheme: lightColorScheme,
|
|
255
254
|
darkColorScheme: darkColorScheme,
|
|
@@ -316,11 +315,6 @@ export default function createCssVarsProvider(options) {
|
|
|
316
315
|
*/
|
|
317
316
|
documentNode: PropTypes.any,
|
|
318
317
|
|
|
319
|
-
/**
|
|
320
|
-
* Indicate to the browser which color scheme is used (light or dark) for rendering built-in UI
|
|
321
|
-
*/
|
|
322
|
-
enableColorScheme: PropTypes.bool,
|
|
323
|
-
|
|
324
318
|
/**
|
|
325
319
|
* The key in the local storage used to store current color scheme.
|
|
326
320
|
*/
|
|
@@ -342,13 +336,17 @@ export default function createCssVarsProvider(options) {
|
|
|
342
336
|
*/
|
|
343
337
|
theme: PropTypes.object
|
|
344
338
|
} : void 0;
|
|
339
|
+
var defaultLightColorScheme = typeof designSystemColorScheme === 'string' ? designSystemColorScheme : designSystemColorScheme.light;
|
|
340
|
+
var defaultDarkColorScheme = typeof designSystemColorScheme === 'string' ? designSystemColorScheme : designSystemColorScheme.dark;
|
|
345
341
|
|
|
346
342
|
var getInitColorSchemeScript = function getInitColorSchemeScript(params) {
|
|
347
343
|
return systemGetInitColorSchemeScript(_extends({
|
|
348
344
|
attribute: defaultAttribute,
|
|
349
345
|
colorSchemeStorageKey: defaultColorSchemeStorageKey,
|
|
350
|
-
|
|
351
|
-
|
|
346
|
+
defaultMode: designSystemMode,
|
|
347
|
+
defaultLightColorScheme: defaultLightColorScheme,
|
|
348
|
+
defaultDarkColorScheme: defaultDarkColorScheme,
|
|
349
|
+
modeStorageKey: defaultModeStorageKey
|
|
352
350
|
}, params));
|
|
353
351
|
};
|
|
354
352
|
|
|
@@ -5,8 +5,6 @@ export var DEFAULT_COLOR_SCHEME_STORAGE_KEY = 'color-scheme';
|
|
|
5
5
|
export var DEFAULT_ATTRIBUTE = 'data-color-scheme';
|
|
6
6
|
export default function getInitColorSchemeScript(options) {
|
|
7
7
|
var _ref = options || {},
|
|
8
|
-
_ref$enableColorSchem = _ref.enableColorScheme,
|
|
9
|
-
enableColorScheme = _ref$enableColorSchem === void 0 ? true : _ref$enableColorSchem,
|
|
10
8
|
_ref$defaultMode = _ref.defaultMode,
|
|
11
9
|
defaultMode = _ref$defaultMode === void 0 ? 'light' : _ref$defaultMode,
|
|
12
10
|
_ref$defaultLightColo = _ref.defaultLightColorScheme,
|
|
@@ -25,7 +23,7 @@ export default function getInitColorSchemeScript(options) {
|
|
|
25
23
|
return /*#__PURE__*/_jsx("script", {
|
|
26
24
|
// eslint-disable-next-line react/no-danger
|
|
27
25
|
dangerouslySetInnerHTML: {
|
|
28
|
-
__html: "(function() { try {\n var mode = localStorage.getItem('".concat(modeStorageKey, "') || '").concat(defaultMode, "';\n var cssColorScheme = mode;\n var colorScheme = '';\n if (mode === 'system') {\n // handle system mode\n var mql = window.matchMedia('(prefers-color-scheme: dark)');\n if (mql.matches) {\n cssColorScheme = 'dark';\n colorScheme = localStorage.getItem('").concat(colorSchemeStorageKey, "-dark') || '").concat(defaultDarkColorScheme, "';\n } else {\n cssColorScheme = 'light';\n colorScheme = localStorage.getItem('").concat(colorSchemeStorageKey, "-light') || '").concat(defaultLightColorScheme, "';\n }\n }\n if (mode === 'light') {\n colorScheme = localStorage.getItem('").concat(colorSchemeStorageKey, "-light') || '").concat(defaultLightColorScheme, "';\n }\n if (mode === 'dark') {\n colorScheme = localStorage.getItem('").concat(colorSchemeStorageKey, "-dark') || '").concat(defaultDarkColorScheme, "';\n }\n if (colorScheme) {\n ").concat(colorSchemeNode, ".setAttribute('").concat(attribute, "', colorScheme);\n }\n
|
|
26
|
+
__html: "(function() { try {\n var mode = localStorage.getItem('".concat(modeStorageKey, "') || '").concat(defaultMode, "';\n var cssColorScheme = mode;\n var colorScheme = '';\n if (mode === 'system') {\n // handle system mode\n var mql = window.matchMedia('(prefers-color-scheme: dark)');\n if (mql.matches) {\n cssColorScheme = 'dark';\n colorScheme = localStorage.getItem('").concat(colorSchemeStorageKey, "-dark') || '").concat(defaultDarkColorScheme, "';\n } else {\n cssColorScheme = 'light';\n colorScheme = localStorage.getItem('").concat(colorSchemeStorageKey, "-light') || '").concat(defaultLightColorScheme, "';\n }\n }\n if (mode === 'light') {\n colorScheme = localStorage.getItem('").concat(colorSchemeStorageKey, "-light') || '").concat(defaultLightColorScheme, "';\n }\n if (mode === 'dark') {\n colorScheme = localStorage.getItem('").concat(colorSchemeStorageKey, "-dark') || '").concat(defaultDarkColorScheme, "';\n }\n if (colorScheme) {\n ").concat(colorSchemeNode, ".setAttribute('").concat(attribute, "', colorScheme);\n }\n } catch (e) {} })();")
|
|
29
27
|
}
|
|
30
28
|
});
|
|
31
29
|
}
|
package/legacy/index.js
CHANGED
|
@@ -10,7 +10,7 @@ import useThemePropsSystem from '../useThemeProps';
|
|
|
10
10
|
import useTheme from '../useTheme';
|
|
11
11
|
import { extendSxProp } from '../styleFunctionSx';
|
|
12
12
|
import createTheme from '../createTheme';
|
|
13
|
-
import { generateGridStyles, generateGridSizeStyles, generateGridColumnsStyles, generateGridColumnSpacingStyles, generateGridRowSpacingStyles, generateGridDirectionStyles, generateGridOffsetStyles, generateSizeClassNames, generateSpacingClassNames } from './gridGenerator';
|
|
13
|
+
import { generateGridStyles, generateGridSizeStyles, generateGridColumnsStyles, generateGridColumnSpacingStyles, generateGridRowSpacingStyles, generateGridDirectionStyles, generateGridOffsetStyles, generateSizeClassNames, generateSpacingClassNames, generateDirectionClasses } from './gridGenerator';
|
|
14
14
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
15
15
|
const defaultTheme = createTheme(); // widening Theme to any so that the consumer can own the theme structure.
|
|
16
16
|
|
|
@@ -47,7 +47,7 @@ export default function createGrid(options = {}) {
|
|
|
47
47
|
gridSize
|
|
48
48
|
} = ownerState;
|
|
49
49
|
const slots = {
|
|
50
|
-
root: ['root', container && 'container',
|
|
50
|
+
root: ['root', container && 'container', wrap !== 'wrap' && `wrap-xs-${String(wrap)}`, ...generateDirectionClasses(direction), ...generateSizeClassNames(gridSize), ...(container ? generateSpacingClassNames(spacing, theme.breakpoints.keys[0]) : [])]
|
|
51
51
|
};
|
|
52
52
|
return composeClasses(slots, slot => generateUtilityClass(componentName, slot), {});
|
|
53
53
|
};
|
|
@@ -229,4 +229,15 @@ export const generateSpacingClassNames = (spacing, smallestBreakpoint = 'xs') =>
|
|
|
229
229
|
}
|
|
230
230
|
|
|
231
231
|
return [];
|
|
232
|
+
};
|
|
233
|
+
export const generateDirectionClasses = direction => {
|
|
234
|
+
if (direction === undefined) {
|
|
235
|
+
return [];
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
if (typeof direction === 'object') {
|
|
239
|
+
return Object.entries(direction).map(([key, value]) => `direction-${key}-${value}`);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
return [`direction-xs-${String(direction)}`];
|
|
232
243
|
};
|
|
@@ -4,7 +4,7 @@ import { formatMuiErrorMessage as _formatMuiErrorMessage } from "@mui/utils";
|
|
|
4
4
|
const _excluded = ["colorSchemes", "components", "cssVarPrefix"];
|
|
5
5
|
import * as React from 'react';
|
|
6
6
|
import PropTypes from 'prop-types';
|
|
7
|
-
import { deepmerge
|
|
7
|
+
import { deepmerge } from '@mui/utils';
|
|
8
8
|
import { GlobalStyles } from '@mui/styled-engine';
|
|
9
9
|
import cssVarsParser from './cssVarsParser';
|
|
10
10
|
import ThemeProvider from '../ThemeProvider';
|
|
@@ -19,10 +19,9 @@ export default function createCssVarsProvider(options) {
|
|
|
19
19
|
attribute: defaultAttribute = DEFAULT_ATTRIBUTE,
|
|
20
20
|
modeStorageKey: defaultModeStorageKey = DEFAULT_MODE_STORAGE_KEY,
|
|
21
21
|
colorSchemeStorageKey: defaultColorSchemeStorageKey = DEFAULT_COLOR_SCHEME_STORAGE_KEY,
|
|
22
|
-
defaultMode:
|
|
22
|
+
defaultMode: designSystemMode = 'light',
|
|
23
23
|
defaultColorScheme: designSystemColorScheme,
|
|
24
24
|
disableTransitionOnChange: designSystemTransitionOnChange = false,
|
|
25
|
-
enableColorScheme: designSystemEnableColorScheme = true,
|
|
26
25
|
shouldSkipGeneratingVar: designSystemShouldSkipGeneratingVar,
|
|
27
26
|
resolveTheme,
|
|
28
27
|
excludeVariablesFromRoot
|
|
@@ -50,10 +49,9 @@ export default function createCssVarsProvider(options) {
|
|
|
50
49
|
modeStorageKey = defaultModeStorageKey,
|
|
51
50
|
colorSchemeStorageKey = defaultColorSchemeStorageKey,
|
|
52
51
|
attribute = defaultAttribute,
|
|
53
|
-
defaultMode =
|
|
52
|
+
defaultMode = designSystemMode,
|
|
54
53
|
defaultColorScheme = designSystemColorScheme,
|
|
55
54
|
disableTransitionOnChange = designSystemTransitionOnChange,
|
|
56
|
-
enableColorScheme = designSystemEnableColorScheme,
|
|
57
55
|
storageWindow = typeof window === 'undefined' ? undefined : window,
|
|
58
56
|
documentNode = typeof document === 'undefined' ? undefined : document,
|
|
59
57
|
colorSchemeNode = typeof document === 'undefined' ? undefined : document.documentElement,
|
|
@@ -71,7 +69,8 @@ export default function createCssVarsProvider(options) {
|
|
|
71
69
|
|
|
72
70
|
const allColorSchemes = Object.keys(colorSchemes);
|
|
73
71
|
const defaultLightColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.light;
|
|
74
|
-
const defaultDarkColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.dark;
|
|
72
|
+
const defaultDarkColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.dark; // 1. Get the data about the `mode`, `colorScheme`, and setter functions.
|
|
73
|
+
|
|
75
74
|
const {
|
|
76
75
|
mode,
|
|
77
76
|
setMode,
|
|
@@ -90,36 +89,54 @@ export default function createCssVarsProvider(options) {
|
|
|
90
89
|
storageWindow
|
|
91
90
|
});
|
|
92
91
|
|
|
93
|
-
const
|
|
92
|
+
const calculatedMode = (() => {
|
|
93
|
+
if (!mode) {
|
|
94
|
+
// This scope occurs on the server
|
|
95
|
+
if (defaultMode === 'system') {
|
|
96
|
+
return designSystemMode;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return defaultMode;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return mode;
|
|
103
|
+
})();
|
|
104
|
+
|
|
105
|
+
const calculatedColorScheme = (() => {
|
|
94
106
|
if (!colorScheme) {
|
|
95
107
|
// This scope occurs on the server
|
|
96
|
-
if (
|
|
108
|
+
if (calculatedMode === 'dark') {
|
|
97
109
|
return defaultDarkColorScheme;
|
|
98
|
-
} // use light color scheme, if default mode is 'light' | '
|
|
110
|
+
} // use light color scheme, if default mode is 'light' | 'system'
|
|
99
111
|
|
|
100
112
|
|
|
101
113
|
return defaultLightColorScheme;
|
|
102
114
|
}
|
|
103
115
|
|
|
104
116
|
return colorScheme;
|
|
105
|
-
})();
|
|
117
|
+
})(); // 2. Create CSS variables and store them in objects (to be generated in stylesheets in the final step)
|
|
118
|
+
|
|
106
119
|
|
|
107
|
-
let theme = restThemeProp;
|
|
108
120
|
const {
|
|
109
121
|
css: rootCss,
|
|
110
122
|
vars: rootVars,
|
|
111
123
|
parsedTheme
|
|
112
|
-
} = cssVarsParser(
|
|
124
|
+
} = cssVarsParser(restThemeProp, {
|
|
113
125
|
prefix: cssVarPrefix,
|
|
114
126
|
shouldSkipGeneratingVar
|
|
115
|
-
});
|
|
116
|
-
|
|
127
|
+
}); // 3. Start composing the theme object
|
|
128
|
+
|
|
129
|
+
let theme = _extends({}, parsedTheme, {
|
|
117
130
|
components,
|
|
118
131
|
colorSchemes,
|
|
119
132
|
cssVarPrefix,
|
|
120
133
|
vars: rootVars,
|
|
121
134
|
getColorSchemeSelector: targetColorScheme => `[${attribute}="${targetColorScheme}"] &`
|
|
122
|
-
});
|
|
135
|
+
}); // 4. Create color CSS variables and store them in objects (to be generated in stylesheets in the final step)
|
|
136
|
+
// The default color scheme stylesheet is constructed to have the least CSS specificity.
|
|
137
|
+
// The other color schemes uses selector, default as data attribute, to increase the CSS specificity so that they can override the default color scheme stylesheet.
|
|
138
|
+
|
|
139
|
+
|
|
123
140
|
const defaultColorSchemeStyleSheet = {};
|
|
124
141
|
const otherColorSchemesStyleSheet = {};
|
|
125
142
|
Object.entries(colorSchemes).forEach(([key, scheme]) => {
|
|
@@ -133,13 +150,12 @@ export default function createCssVarsProvider(options) {
|
|
|
133
150
|
});
|
|
134
151
|
theme.vars = deepmerge(theme.vars, vars);
|
|
135
152
|
|
|
136
|
-
if (key ===
|
|
153
|
+
if (key === calculatedColorScheme) {
|
|
154
|
+
// 4.1 Merge the selected color scheme to the theme
|
|
137
155
|
theme = _extends({}, theme, parsedScheme);
|
|
138
156
|
|
|
139
157
|
if (theme.palette) {
|
|
140
|
-
|
|
141
|
-
theme.palette.mode = mode;
|
|
142
|
-
theme.palette.colorScheme = resolvedColorScheme;
|
|
158
|
+
theme.palette.colorScheme = key;
|
|
143
159
|
}
|
|
144
160
|
}
|
|
145
161
|
|
|
@@ -169,35 +185,21 @@ export default function createCssVarsProvider(options) {
|
|
|
169
185
|
} else {
|
|
170
186
|
otherColorSchemesStyleSheet[`${colorSchemeSelector === ':root' ? '' : colorSchemeSelector}[${attribute}="${key}"]`] = css;
|
|
171
187
|
}
|
|
172
|
-
});
|
|
188
|
+
}); // 5. Declaring effects
|
|
189
|
+
// 5.1 Updates the selector value to use the current color scheme which tells CSS to use the proper stylesheet.
|
|
190
|
+
|
|
173
191
|
React.useEffect(() => {
|
|
174
192
|
if (colorScheme && colorSchemeNode) {
|
|
175
193
|
// attaches attribute to <html> because the css variables are attached to :root (html)
|
|
176
194
|
colorSchemeNode.setAttribute(attribute, colorScheme);
|
|
177
195
|
}
|
|
178
|
-
}, [colorScheme, attribute, colorSchemeNode]);
|
|
179
|
-
|
|
180
|
-
if (!mode || !enableColorScheme || !colorSchemeNode) {
|
|
181
|
-
return undefined;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
const priorColorScheme = colorSchemeNode.style.getPropertyValue('color-scheme'); // `color-scheme` tells browser to render built-in elements according to its value: `light` or `dark`
|
|
185
|
-
|
|
186
|
-
if (mode === 'system') {
|
|
187
|
-
colorSchemeNode.style.setProperty('color-scheme', systemMode);
|
|
188
|
-
} else {
|
|
189
|
-
colorSchemeNode.style.setProperty('color-scheme', mode);
|
|
190
|
-
}
|
|
196
|
+
}, [colorScheme, attribute, colorSchemeNode]); // 5.2 Remove the CSS transition when color scheme changes to create instant experience.
|
|
197
|
+
// credit: https://github.com/pacocoursey/next-themes/blob/b5c2bad50de2d61ad7b52a9c5cdc801a78507d7a/index.tsx#L313
|
|
191
198
|
|
|
192
|
-
return () => {
|
|
193
|
-
colorSchemeNode.style.setProperty('color-scheme', priorColorScheme);
|
|
194
|
-
};
|
|
195
|
-
}, [mode, systemMode, enableColorScheme, colorSchemeNode]);
|
|
196
199
|
React.useEffect(() => {
|
|
197
200
|
let timer;
|
|
198
201
|
|
|
199
202
|
if (disableTransitionOnChange && hasMounted.current && documentNode) {
|
|
200
|
-
// credit: https://github.com/pacocoursey/next-themes/blob/b5c2bad50de2d61ad7b52a9c5cdc801a78507d7a/index.tsx#L313
|
|
201
203
|
const css = documentNode.createElement('style');
|
|
202
204
|
css.appendChild(documentNode.createTextNode(DISABLE_CSS_TRANSITION));
|
|
203
205
|
documentNode.head.appendChild(css); // Force browser repaint
|
|
@@ -222,6 +224,7 @@ export default function createCssVarsProvider(options) {
|
|
|
222
224
|
return /*#__PURE__*/_jsxs(ColorSchemeContext.Provider, {
|
|
223
225
|
value: {
|
|
224
226
|
mode,
|
|
227
|
+
systemMode,
|
|
225
228
|
setMode,
|
|
226
229
|
lightColorScheme,
|
|
227
230
|
darkColorScheme,
|
|
@@ -290,11 +293,6 @@ export default function createCssVarsProvider(options) {
|
|
|
290
293
|
*/
|
|
291
294
|
documentNode: PropTypes.any,
|
|
292
295
|
|
|
293
|
-
/**
|
|
294
|
-
* Indicate to the browser which color scheme is used (light or dark) for rendering built-in UI
|
|
295
|
-
*/
|
|
296
|
-
enableColorScheme: PropTypes.bool,
|
|
297
|
-
|
|
298
296
|
/**
|
|
299
297
|
* The key in the local storage used to store current color scheme.
|
|
300
298
|
*/
|
|
@@ -316,12 +314,16 @@ export default function createCssVarsProvider(options) {
|
|
|
316
314
|
*/
|
|
317
315
|
theme: PropTypes.object
|
|
318
316
|
} : void 0;
|
|
317
|
+
const defaultLightColorScheme = typeof designSystemColorScheme === 'string' ? designSystemColorScheme : designSystemColorScheme.light;
|
|
318
|
+
const defaultDarkColorScheme = typeof designSystemColorScheme === 'string' ? designSystemColorScheme : designSystemColorScheme.dark;
|
|
319
319
|
|
|
320
320
|
const getInitColorSchemeScript = params => systemGetInitColorSchemeScript(_extends({
|
|
321
321
|
attribute: defaultAttribute,
|
|
322
322
|
colorSchemeStorageKey: defaultColorSchemeStorageKey,
|
|
323
|
-
|
|
324
|
-
|
|
323
|
+
defaultMode: designSystemMode,
|
|
324
|
+
defaultLightColorScheme,
|
|
325
|
+
defaultDarkColorScheme,
|
|
326
|
+
modeStorageKey: defaultModeStorageKey
|
|
325
327
|
}, params));
|
|
326
328
|
|
|
327
329
|
return {
|
|
@@ -5,7 +5,6 @@ export const DEFAULT_COLOR_SCHEME_STORAGE_KEY = 'color-scheme';
|
|
|
5
5
|
export const DEFAULT_ATTRIBUTE = 'data-color-scheme';
|
|
6
6
|
export default function getInitColorSchemeScript(options) {
|
|
7
7
|
const {
|
|
8
|
-
enableColorScheme = true,
|
|
9
8
|
defaultMode = 'light',
|
|
10
9
|
defaultLightColorScheme = 'light',
|
|
11
10
|
defaultDarkColorScheme = 'dark',
|
|
@@ -41,9 +40,6 @@ export default function getInitColorSchemeScript(options) {
|
|
|
41
40
|
if (colorScheme) {
|
|
42
41
|
${colorSchemeNode}.setAttribute('${attribute}', colorScheme);
|
|
43
42
|
}
|
|
44
|
-
if (${enableColorScheme} && !!cssColorScheme) {
|
|
45
|
-
${colorSchemeNode}.style.setProperty('color-scheme', cssColorScheme);
|
|
46
|
-
}
|
|
47
43
|
} catch (e) {} })();`
|
|
48
44
|
}
|
|
49
45
|
});
|
package/modern/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mui/system",
|
|
3
|
-
"version": "5.10.
|
|
3
|
+
"version": "5.10.9",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": "MUI Team",
|
|
6
6
|
"description": "CSS utilities for rapidly laying out custom designs.",
|
|
@@ -44,10 +44,10 @@
|
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"@babel/runtime": "^7.19.0",
|
|
47
|
-
"@mui/private-theming": "^5.10.
|
|
48
|
-
"@mui/styled-engine": "^5.10.
|
|
47
|
+
"@mui/private-theming": "^5.10.9",
|
|
48
|
+
"@mui/styled-engine": "^5.10.8",
|
|
49
49
|
"@mui/types": "^7.2.0",
|
|
50
|
-
"@mui/utils": "^5.10.
|
|
50
|
+
"@mui/utils": "^5.10.9",
|
|
51
51
|
"clsx": "^1.2.1",
|
|
52
52
|
"csstype": "^3.1.1",
|
|
53
53
|
"prop-types": "^15.8.1"
|