@mui/system 5.6.3 → 5.8.0
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/Box/Box.spec.d.ts +1 -1
- package/CHANGELOG.md +238 -0
- package/Container/Container.d.ts +13 -0
- package/Container/Container.js +81 -0
- package/Container/ContainerProps.d.ts +40 -0
- package/Container/ContainerProps.js +5 -0
- package/Container/containerClasses.d.ts +22 -0
- package/Container/containerClasses.js +17 -0
- package/Container/createContainer.d.ts +18 -0
- package/Container/createContainer.js +172 -0
- package/Container/index.d.ts +5 -0
- package/Container/index.js +42 -0
- package/Container/package.json +6 -0
- package/ThemeProvider/ThemeProvider.d.ts +1 -1
- package/createBox.spec.d.ts +1 -1
- package/createStyled.js +3 -1
- package/createTheme/createBreakpoints.d.ts +5 -0
- package/createTheme/createSpacing.d.ts +10 -10
- package/cssVars/createCssVarsProvider.d.ts +25 -0
- package/cssVars/createCssVarsProvider.js +74 -57
- package/cssVars/createCssVarsProvider.spec.d.ts +1 -1
- package/cssVars/createGetCssVar.d.ts +5 -5
- package/cssVars/cssVarsParser.d.ts +70 -70
- package/cssVars/cssVarsParser.js +11 -9
- package/cssVars/getInitColorSchemeScript.d.ts +40 -12
- package/cssVars/getInitColorSchemeScript.js +4 -3
- package/cssVars/index.d.ts +2 -2
- package/cssVars/useCurrentColorScheme.d.ts +53 -50
- package/cssVars/useCurrentColorScheme.js +17 -7
- package/esm/Container/Container.js +70 -0
- package/esm/Container/ContainerProps.js +1 -0
- package/esm/Container/containerClasses.js +6 -0
- package/esm/Container/createContainer.js +151 -0
- package/esm/Container/index.js +3 -0
- package/esm/createStyled.js +3 -1
- package/esm/cssVars/createCssVarsProvider.js +76 -57
- package/esm/cssVars/cssVarsParser.js +11 -9
- package/esm/cssVars/getInitColorSchemeScript.js +4 -3
- package/esm/cssVars/useCurrentColorScheme.js +17 -7
- package/esm/index.js +4 -1
- package/index.d.ts +6 -0
- package/index.js +32 -2
- package/index.spec.d.ts +1 -1
- package/legacy/Container/Container.js +70 -0
- package/legacy/Container/ContainerProps.js +1 -0
- package/legacy/Container/containerClasses.js +6 -0
- package/legacy/Container/createContainer.js +148 -0
- package/legacy/Container/index.js +3 -0
- package/legacy/createStyled.js +3 -1
- package/legacy/cssVars/createCssVarsProvider.js +83 -55
- package/legacy/cssVars/cssVarsParser.js +11 -7
- package/legacy/cssVars/getInitColorSchemeScript.js +6 -3
- package/legacy/cssVars/useCurrentColorScheme.js +20 -9
- package/legacy/index.js +5 -2
- package/modern/Container/Container.js +70 -0
- package/modern/Container/ContainerProps.js +1 -0
- package/modern/Container/containerClasses.js +6 -0
- package/modern/Container/createContainer.js +151 -0
- package/modern/Container/index.js +3 -0
- package/modern/createStyled.js +3 -1
- package/modern/cssVars/createCssVarsProvider.js +76 -55
- package/modern/cssVars/cssVarsParser.js +11 -9
- package/modern/cssVars/getInitColorSchemeScript.js +4 -3
- package/modern/cssVars/useCurrentColorScheme.js +17 -7
- package/modern/index.js +5 -2
- package/package.json +5 -5
- package/styleFunctionSx/styleFunctionSx.spec.d.ts +1 -1
|
@@ -1,28 +1,22 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
3
|
import { formatMuiErrorMessage as _formatMuiErrorMessage } from "@mui/utils";
|
|
4
|
-
const _excluded = ["colorSchemes"]
|
|
5
|
-
_excluded2 = ["colorSchemes"],
|
|
6
|
-
_excluded3 = ["components"];
|
|
4
|
+
const _excluded = ["colorSchemes", "components"];
|
|
7
5
|
import * as React from 'react';
|
|
8
6
|
import PropTypes from 'prop-types';
|
|
9
|
-
import { GlobalStyles } from '@mui/styled-engine';
|
|
10
7
|
import { deepmerge, unstable_useEnhancedEffect as useEnhancedEffect } from '@mui/utils';
|
|
11
|
-
import
|
|
12
|
-
import createBreakpoints from '../createTheme/createBreakpoints';
|
|
8
|
+
import { GlobalStyles } from '@mui/styled-engine';
|
|
13
9
|
import cssVarsParser from './cssVarsParser';
|
|
14
10
|
import ThemeProvider from '../ThemeProvider';
|
|
15
|
-
import getInitColorSchemeScript, { DEFAULT_ATTRIBUTE, DEFAULT_MODE_STORAGE_KEY } from './getInitColorSchemeScript';
|
|
11
|
+
import getInitColorSchemeScript, { DEFAULT_ATTRIBUTE, DEFAULT_COLOR_SCHEME_STORAGE_KEY, DEFAULT_MODE_STORAGE_KEY } from './getInitColorSchemeScript';
|
|
16
12
|
import useCurrentColorScheme from './useCurrentColorScheme';
|
|
17
13
|
import createGetCssVar from './createGetCssVar';
|
|
18
14
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
19
15
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
20
16
|
export const DISABLE_CSS_TRANSITION = '*{-webkit-transition:none!important;-moz-transition:none!important;-o-transition:none!important;-ms-transition:none!important;transition:none!important}';
|
|
21
17
|
export default function createCssVarsProvider(options) {
|
|
22
|
-
var _baseTheme$breakpoint;
|
|
23
|
-
|
|
24
18
|
const {
|
|
25
|
-
theme:
|
|
19
|
+
theme: defaultTheme = {},
|
|
26
20
|
defaultMode: desisgnSystemMode = 'light',
|
|
27
21
|
defaultColorScheme: designSystemColorScheme,
|
|
28
22
|
disableTransitionOnChange: designSystemTransitionOnChange = false,
|
|
@@ -31,10 +25,8 @@ export default function createCssVarsProvider(options) {
|
|
|
31
25
|
shouldSkipGeneratingVar,
|
|
32
26
|
resolveTheme
|
|
33
27
|
} = options;
|
|
34
|
-
const systemSpacing = createSpacing(baseTheme.spacing);
|
|
35
|
-
const systemBreakpoints = createBreakpoints((_baseTheme$breakpoint = baseTheme.breakpoints) != null ? _baseTheme$breakpoint : {});
|
|
36
28
|
|
|
37
|
-
if (!
|
|
29
|
+
if (!defaultTheme.colorSchemes || typeof designSystemColorScheme === 'string' && !defaultTheme.colorSchemes[designSystemColorScheme] || typeof designSystemColorScheme === 'object' && !defaultTheme.colorSchemes[designSystemColorScheme == null ? void 0 : designSystemColorScheme.light] || typeof designSystemColorScheme === 'object' && !defaultTheme.colorSchemes[designSystemColorScheme == null ? void 0 : designSystemColorScheme.dark]) {
|
|
38
30
|
console.error(`MUI: \`${designSystemColorScheme}\` does not exist in \`theme.colorSchemes\`.`);
|
|
39
31
|
}
|
|
40
32
|
|
|
@@ -52,34 +44,28 @@ export default function createCssVarsProvider(options) {
|
|
|
52
44
|
|
|
53
45
|
function CssVarsProvider({
|
|
54
46
|
children,
|
|
55
|
-
theme: themeProp =
|
|
47
|
+
theme: themeProp = defaultTheme,
|
|
56
48
|
prefix = designSystemPrefix,
|
|
57
49
|
modeStorageKey = DEFAULT_MODE_STORAGE_KEY,
|
|
50
|
+
colorSchemeStorageKey = DEFAULT_COLOR_SCHEME_STORAGE_KEY,
|
|
58
51
|
attribute = DEFAULT_ATTRIBUTE,
|
|
59
52
|
defaultMode = desisgnSystemMode,
|
|
60
53
|
defaultColorScheme = designSystemColorScheme,
|
|
61
54
|
disableTransitionOnChange = designSystemTransitionOnChange,
|
|
62
|
-
enableColorScheme = designSystemEnableColorScheme
|
|
55
|
+
enableColorScheme = designSystemEnableColorScheme,
|
|
56
|
+
storageWindow = typeof window === 'undefined' ? undefined : window,
|
|
57
|
+
documentNode = typeof document === 'undefined' ? undefined : document,
|
|
58
|
+
colorSchemeNode = typeof document === 'undefined' ? undefined : document.documentElement,
|
|
59
|
+
colorSchemeSelector = ':root'
|
|
63
60
|
}) {
|
|
64
|
-
const
|
|
65
|
-
colorSchemes: baseColorSchemes = {}
|
|
66
|
-
} = baseTheme,
|
|
67
|
-
restBaseTheme = _objectWithoutPropertiesLoose(baseTheme, _excluded);
|
|
61
|
+
const hasMounted = React.useRef(false);
|
|
68
62
|
|
|
69
63
|
const {
|
|
70
|
-
colorSchemes
|
|
71
|
-
} = themeProp,
|
|
72
|
-
restThemeProp = _objectWithoutPropertiesLoose(themeProp, _excluded2);
|
|
73
|
-
|
|
74
|
-
const hasMounted = React.useRef(false); // eslint-disable-next-line prefer-const
|
|
75
|
-
|
|
76
|
-
let _deepmerge = deepmerge(restBaseTheme, restThemeProp),
|
|
77
|
-
{
|
|
64
|
+
colorSchemes = {},
|
|
78
65
|
components = {}
|
|
79
|
-
} =
|
|
80
|
-
|
|
66
|
+
} = themeProp,
|
|
67
|
+
restThemeProp = _objectWithoutPropertiesLoose(themeProp, _excluded);
|
|
81
68
|
|
|
82
|
-
const colorSchemes = deepmerge(baseColorSchemes, colorSchemesProp);
|
|
83
69
|
const allColorSchemes = Object.keys(colorSchemes);
|
|
84
70
|
const defaultLightColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.light;
|
|
85
71
|
const defaultDarkColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.dark;
|
|
@@ -96,7 +82,9 @@ export default function createCssVarsProvider(options) {
|
|
|
96
82
|
defaultLightColorScheme,
|
|
97
83
|
defaultDarkColorScheme,
|
|
98
84
|
modeStorageKey,
|
|
99
|
-
|
|
85
|
+
colorSchemeStorageKey,
|
|
86
|
+
defaultMode,
|
|
87
|
+
storageWindow
|
|
100
88
|
});
|
|
101
89
|
|
|
102
90
|
const resolvedColorScheme = (() => {
|
|
@@ -113,22 +101,21 @@ export default function createCssVarsProvider(options) {
|
|
|
113
101
|
return colorScheme;
|
|
114
102
|
})();
|
|
115
103
|
|
|
104
|
+
let theme = restThemeProp;
|
|
116
105
|
const {
|
|
117
106
|
css: rootCss,
|
|
118
107
|
vars: rootVars,
|
|
119
108
|
parsedTheme
|
|
120
|
-
} = cssVarsParser(
|
|
109
|
+
} = cssVarsParser(theme, {
|
|
121
110
|
prefix,
|
|
122
111
|
basePrefix: designSystemPrefix,
|
|
123
112
|
shouldSkipGeneratingVar
|
|
124
113
|
});
|
|
125
|
-
|
|
114
|
+
theme = _extends({}, parsedTheme, {
|
|
126
115
|
components,
|
|
127
116
|
colorSchemes,
|
|
128
117
|
prefix,
|
|
129
118
|
vars: rootVars,
|
|
130
|
-
spacing: themeProp.spacing ? createSpacing(themeProp.spacing) : systemSpacing,
|
|
131
|
-
breakpoints: themeProp.breakpoints ? createBreakpoints(themeProp.breakpoints) : systemBreakpoints,
|
|
132
119
|
getCssVar: createGetCssVar(prefix)
|
|
133
120
|
});
|
|
134
121
|
const styleSheet = {};
|
|
@@ -142,10 +129,16 @@ export default function createCssVarsProvider(options) {
|
|
|
142
129
|
basePrefix: designSystemPrefix,
|
|
143
130
|
shouldSkipGeneratingVar
|
|
144
131
|
});
|
|
145
|
-
|
|
132
|
+
theme.vars = deepmerge(theme.vars, vars);
|
|
146
133
|
|
|
147
134
|
if (key === resolvedColorScheme) {
|
|
148
|
-
|
|
135
|
+
theme = _extends({}, theme, parsedScheme);
|
|
136
|
+
|
|
137
|
+
if (theme.palette) {
|
|
138
|
+
// assign runtime mode & colorScheme
|
|
139
|
+
theme.palette.mode = mode;
|
|
140
|
+
theme.palette.colorScheme = resolvedColorScheme;
|
|
141
|
+
}
|
|
149
142
|
}
|
|
150
143
|
|
|
151
144
|
const resolvedDefaultColorScheme = (() => {
|
|
@@ -161,54 +154,54 @@ export default function createCssVarsProvider(options) {
|
|
|
161
154
|
})();
|
|
162
155
|
|
|
163
156
|
if (key === resolvedDefaultColorScheme) {
|
|
164
|
-
styleSheet[
|
|
157
|
+
styleSheet[colorSchemeSelector] = css;
|
|
165
158
|
} else {
|
|
166
|
-
styleSheet[
|
|
159
|
+
styleSheet[`${colorSchemeSelector === ':root' ? '' : colorSchemeSelector}[${attribute}="${key}"]`] = css;
|
|
167
160
|
}
|
|
168
161
|
});
|
|
169
162
|
React.useEffect(() => {
|
|
170
|
-
if (colorScheme) {
|
|
163
|
+
if (colorScheme && colorSchemeNode) {
|
|
171
164
|
// attaches attribute to <html> because the css variables are attached to :root (html)
|
|
172
|
-
|
|
165
|
+
colorSchemeNode.setAttribute(attribute, colorScheme);
|
|
173
166
|
}
|
|
174
|
-
}, [colorScheme, attribute]);
|
|
167
|
+
}, [colorScheme, attribute, colorSchemeNode]);
|
|
175
168
|
useEnhancedEffect(() => {
|
|
176
|
-
if (!mode || !enableColorScheme) {
|
|
169
|
+
if (!mode || !enableColorScheme || !colorSchemeNode) {
|
|
177
170
|
return undefined;
|
|
178
171
|
}
|
|
179
172
|
|
|
180
|
-
const priorColorScheme =
|
|
173
|
+
const priorColorScheme = colorSchemeNode.style.getPropertyValue('color-scheme'); // `color-scheme` tells browser to render built-in elements according to its value: `light` or `dark`
|
|
181
174
|
|
|
182
175
|
if (mode === 'system') {
|
|
183
|
-
|
|
176
|
+
colorSchemeNode.style.setProperty('color-scheme', systemMode);
|
|
184
177
|
} else {
|
|
185
|
-
|
|
178
|
+
colorSchemeNode.style.setProperty('color-scheme', mode);
|
|
186
179
|
}
|
|
187
180
|
|
|
188
181
|
return () => {
|
|
189
|
-
|
|
182
|
+
colorSchemeNode.style.setProperty('color-scheme', priorColorScheme);
|
|
190
183
|
};
|
|
191
|
-
}, [mode, systemMode, enableColorScheme]);
|
|
184
|
+
}, [mode, systemMode, enableColorScheme, colorSchemeNode]);
|
|
192
185
|
React.useEffect(() => {
|
|
193
186
|
let timer;
|
|
194
187
|
|
|
195
|
-
if (disableTransitionOnChange && hasMounted.current) {
|
|
188
|
+
if (disableTransitionOnChange && hasMounted.current && documentNode) {
|
|
196
189
|
// credit: https://github.com/pacocoursey/next-themes/blob/b5c2bad50de2d61ad7b52a9c5cdc801a78507d7a/index.tsx#L313
|
|
197
|
-
const css =
|
|
198
|
-
css.appendChild(
|
|
199
|
-
|
|
190
|
+
const css = documentNode.createElement('style');
|
|
191
|
+
css.appendChild(documentNode.createTextNode(DISABLE_CSS_TRANSITION));
|
|
192
|
+
documentNode.head.appendChild(css); // Force browser repaint
|
|
200
193
|
|
|
201
|
-
(() => window.getComputedStyle(
|
|
194
|
+
(() => window.getComputedStyle(documentNode.body))();
|
|
202
195
|
|
|
203
196
|
timer = setTimeout(() => {
|
|
204
|
-
|
|
197
|
+
documentNode.head.removeChild(css);
|
|
205
198
|
}, 1);
|
|
206
199
|
}
|
|
207
200
|
|
|
208
201
|
return () => {
|
|
209
202
|
clearTimeout(timer);
|
|
210
203
|
};
|
|
211
|
-
}, [colorScheme, disableTransitionOnChange]);
|
|
204
|
+
}, [colorScheme, disableTransitionOnChange, documentNode]);
|
|
212
205
|
React.useEffect(() => {
|
|
213
206
|
hasMounted.current = true;
|
|
214
207
|
return () => {
|
|
@@ -227,12 +220,12 @@ export default function createCssVarsProvider(options) {
|
|
|
227
220
|
},
|
|
228
221
|
children: [/*#__PURE__*/_jsx(GlobalStyles, {
|
|
229
222
|
styles: {
|
|
230
|
-
|
|
223
|
+
[colorSchemeSelector]: rootCss
|
|
231
224
|
}
|
|
232
225
|
}), /*#__PURE__*/_jsx(GlobalStyles, {
|
|
233
226
|
styles: styleSheet
|
|
234
227
|
}), /*#__PURE__*/_jsx(ThemeProvider, {
|
|
235
|
-
theme: resolveTheme ? resolveTheme(
|
|
228
|
+
theme: resolveTheme ? resolveTheme(theme) : theme,
|
|
236
229
|
children: children
|
|
237
230
|
})]
|
|
238
231
|
});
|
|
@@ -249,6 +242,21 @@ export default function createCssVarsProvider(options) {
|
|
|
249
242
|
*/
|
|
250
243
|
children: PropTypes.node,
|
|
251
244
|
|
|
245
|
+
/**
|
|
246
|
+
* The node used to attach the color-scheme attribute
|
|
247
|
+
*/
|
|
248
|
+
colorSchemeNode: PropTypes.any,
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* The CSS selector for attaching the generated custom properties
|
|
252
|
+
*/
|
|
253
|
+
colorSchemeSelector: PropTypes.string,
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* localStorage key used to store `colorScheme`
|
|
257
|
+
*/
|
|
258
|
+
colorSchemeStorageKey: PropTypes.string,
|
|
259
|
+
|
|
252
260
|
/**
|
|
253
261
|
* The initial color scheme used.
|
|
254
262
|
*/
|
|
@@ -264,6 +272,11 @@ export default function createCssVarsProvider(options) {
|
|
|
264
272
|
*/
|
|
265
273
|
disableTransitionOnChange: PropTypes.bool,
|
|
266
274
|
|
|
275
|
+
/**
|
|
276
|
+
* The document to attach the attribute to
|
|
277
|
+
*/
|
|
278
|
+
documentNode: PropTypes.any,
|
|
279
|
+
|
|
267
280
|
/**
|
|
268
281
|
* Indicate to the browser which color scheme is used (light or dark) for rendering built-in UI
|
|
269
282
|
*/
|
|
@@ -279,6 +292,12 @@ export default function createCssVarsProvider(options) {
|
|
|
279
292
|
*/
|
|
280
293
|
prefix: PropTypes.string,
|
|
281
294
|
|
|
295
|
+
/**
|
|
296
|
+
* The window that attaches the 'storage' event listener
|
|
297
|
+
* @default window
|
|
298
|
+
*/
|
|
299
|
+
storageWindow: PropTypes.any,
|
|
300
|
+
|
|
282
301
|
/**
|
|
283
302
|
* The calculated theme object that will be passed through context.
|
|
284
303
|
*/
|
|
@@ -15,16 +15,18 @@
|
|
|
15
15
|
* assignNestedKeys(source, ['palette', 'secondary'], 'var(--palette-secondary)')
|
|
16
16
|
* console.log(source) // { palette: { primary: 'var(--palette-primary)', secondary: 'var(--palette-secondary)' } }
|
|
17
17
|
*/
|
|
18
|
-
export const assignNestedKeys = (obj, keys, value) => {
|
|
18
|
+
export const assignNestedKeys = (obj, keys, value, arrayKeys = []) => {
|
|
19
19
|
let temp = obj;
|
|
20
20
|
keys.forEach((k, index) => {
|
|
21
21
|
if (index === keys.length - 1) {
|
|
22
|
-
if (temp
|
|
22
|
+
if (Array.isArray(temp)) {
|
|
23
|
+
temp[Number(k)] = value;
|
|
24
|
+
} else if (temp && typeof temp === 'object') {
|
|
23
25
|
temp[k] = value;
|
|
24
26
|
}
|
|
25
27
|
} else if (temp && typeof temp === 'object') {
|
|
26
28
|
if (!temp[k]) {
|
|
27
|
-
temp[k] = {};
|
|
29
|
+
temp[k] = arrayKeys.includes(k) ? [] : {};
|
|
28
30
|
}
|
|
29
31
|
|
|
30
32
|
temp = temp[k];
|
|
@@ -44,14 +46,14 @@ export const assignNestedKeys = (obj, keys, value) => {
|
|
|
44
46
|
*/
|
|
45
47
|
|
|
46
48
|
export const walkObjectDeep = (obj, callback, shouldSkipPaths) => {
|
|
47
|
-
function recurse(object, parentKeys = []) {
|
|
49
|
+
function recurse(object, parentKeys = [], arrayKeys = []) {
|
|
48
50
|
Object.entries(object).forEach(([key, value]) => {
|
|
49
51
|
if (!shouldSkipPaths || shouldSkipPaths && !shouldSkipPaths([...parentKeys, key])) {
|
|
50
52
|
if (value !== undefined && value !== null) {
|
|
51
53
|
if (typeof value === 'object' && Object.keys(value).length > 0) {
|
|
52
|
-
recurse(value, [...parentKeys, key]);
|
|
54
|
+
recurse(value, [...parentKeys, key], Array.isArray(value) ? [...arrayKeys, key] : arrayKeys);
|
|
53
55
|
} else {
|
|
54
|
-
callback([...parentKeys, key], value,
|
|
56
|
+
callback([...parentKeys, key], value, arrayKeys);
|
|
55
57
|
}
|
|
56
58
|
}
|
|
57
59
|
}
|
|
@@ -118,7 +120,7 @@ export default function cssVarsParser(theme, options) {
|
|
|
118
120
|
const css = {};
|
|
119
121
|
const vars = {};
|
|
120
122
|
const parsedTheme = {};
|
|
121
|
-
walkObjectDeep(theme, (keys, value) => {
|
|
123
|
+
walkObjectDeep(theme, (keys, value, arrayKeys) => {
|
|
122
124
|
if (typeof value === 'string' || typeof value === 'number') {
|
|
123
125
|
if (typeof value === 'string' && value.match(/var\(\s*--/)) {
|
|
124
126
|
// for CSS variable, apply prefix or remove basePrefix from the variable
|
|
@@ -136,11 +138,11 @@ export default function cssVarsParser(theme, options) {
|
|
|
136
138
|
Object.assign(css, {
|
|
137
139
|
[cssVar]: getCssValue(keys, value)
|
|
138
140
|
});
|
|
139
|
-
assignNestedKeys(vars, keys, `var(${cssVar})
|
|
141
|
+
assignNestedKeys(vars, keys, `var(${cssVar})`, arrayKeys);
|
|
140
142
|
}
|
|
141
143
|
}
|
|
142
144
|
|
|
143
|
-
assignNestedKeys(parsedTheme, keys, value);
|
|
145
|
+
assignNestedKeys(parsedTheme, keys, value, arrayKeys);
|
|
144
146
|
}, keys => keys[0] === 'vars' // skip 'vars/*' paths
|
|
145
147
|
);
|
|
146
148
|
return {
|
|
@@ -5,12 +5,13 @@ export const DEFAULT_COLOR_SCHEME_STORAGE_KEY = 'mui-color-scheme';
|
|
|
5
5
|
export const DEFAULT_ATTRIBUTE = 'data-mui-color-scheme';
|
|
6
6
|
export default function getInitColorSchemeScript(options) {
|
|
7
7
|
const {
|
|
8
|
-
enableSystem,
|
|
8
|
+
enableSystem = false,
|
|
9
9
|
defaultLightColorScheme = 'light',
|
|
10
10
|
defaultDarkColorScheme = 'dark',
|
|
11
11
|
modeStorageKey = DEFAULT_MODE_STORAGE_KEY,
|
|
12
12
|
colorSchemeStorageKey = DEFAULT_COLOR_SCHEME_STORAGE_KEY,
|
|
13
|
-
attribute = DEFAULT_ATTRIBUTE
|
|
13
|
+
attribute = DEFAULT_ATTRIBUTE,
|
|
14
|
+
colorSchemeNode = 'document.documentElement'
|
|
14
15
|
} = options || {};
|
|
15
16
|
return /*#__PURE__*/_jsx("script", {
|
|
16
17
|
// eslint-disable-next-line react/no-danger
|
|
@@ -34,7 +35,7 @@ export default function getInitColorSchemeScript(options) {
|
|
|
34
35
|
colorScheme = localStorage.getItem('${colorSchemeStorageKey}-dark') || '${defaultDarkColorScheme}';
|
|
35
36
|
}
|
|
36
37
|
if (colorScheme) {
|
|
37
|
-
|
|
38
|
+
${colorSchemeNode}.setAttribute('${attribute}', colorScheme);
|
|
38
39
|
}
|
|
39
40
|
} catch (e) {} })();`
|
|
40
41
|
}
|
|
@@ -63,7 +63,8 @@ export default function useCurrentColorScheme(options) {
|
|
|
63
63
|
defaultDarkColorScheme,
|
|
64
64
|
supportedColorSchemes = [],
|
|
65
65
|
modeStorageKey = DEFAULT_MODE_STORAGE_KEY,
|
|
66
|
-
colorSchemeStorageKey = DEFAULT_COLOR_SCHEME_STORAGE_KEY
|
|
66
|
+
colorSchemeStorageKey = DEFAULT_COLOR_SCHEME_STORAGE_KEY,
|
|
67
|
+
storageWindow = typeof window === 'undefined' ? undefined : window
|
|
67
68
|
} = options;
|
|
68
69
|
const joinedColorSchemes = supportedColorSchemes.join(',');
|
|
69
70
|
const [state, setState] = React.useState(() => {
|
|
@@ -80,6 +81,10 @@ export default function useCurrentColorScheme(options) {
|
|
|
80
81
|
setState(currentState => {
|
|
81
82
|
const newMode = !mode ? defaultMode : mode;
|
|
82
83
|
|
|
84
|
+
if (mode === currentState.mode) {
|
|
85
|
+
return currentState;
|
|
86
|
+
}
|
|
87
|
+
|
|
83
88
|
if (typeof localStorage !== 'undefined') {
|
|
84
89
|
localStorage.setItem(modeStorageKey, newMode);
|
|
85
90
|
}
|
|
@@ -92,7 +97,7 @@ export default function useCurrentColorScheme(options) {
|
|
|
92
97
|
}, [modeStorageKey, defaultMode]);
|
|
93
98
|
const setColorScheme = React.useCallback(value => {
|
|
94
99
|
if (!value || typeof value === 'string') {
|
|
95
|
-
if (value && !
|
|
100
|
+
if (value && !joinedColorSchemes.includes(value)) {
|
|
96
101
|
console.error(`\`${value}\` does not exist in \`theme.colorSchemes\`.`);
|
|
97
102
|
} else {
|
|
98
103
|
setState(currentState => {
|
|
@@ -119,7 +124,7 @@ export default function useCurrentColorScheme(options) {
|
|
|
119
124
|
return newState;
|
|
120
125
|
});
|
|
121
126
|
}
|
|
122
|
-
} else if (value.light && !
|
|
127
|
+
} else if (value.light && !joinedColorSchemes.includes(value.light) || value.dark && !joinedColorSchemes.includes(value.dark)) {
|
|
123
128
|
console.error(`\`${value}\` does not exist in \`theme.colorSchemes\`.`);
|
|
124
129
|
} else {
|
|
125
130
|
setState(currentState => {
|
|
@@ -144,7 +149,7 @@ export default function useCurrentColorScheme(options) {
|
|
|
144
149
|
localStorage.setItem(`${colorSchemeStorageKey}-dark`, value.dark);
|
|
145
150
|
}
|
|
146
151
|
}
|
|
147
|
-
}, [
|
|
152
|
+
}, [joinedColorSchemes, colorSchemeStorageKey, defaultLightColorScheme, defaultDarkColorScheme]);
|
|
148
153
|
const handleMediaQuery = React.useCallback(e => {
|
|
149
154
|
if (state.mode === 'system') {
|
|
150
155
|
setState(currentState => _extends({}, currentState, {
|
|
@@ -206,9 +211,14 @@ export default function useCurrentColorScheme(options) {
|
|
|
206
211
|
}
|
|
207
212
|
};
|
|
208
213
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
214
|
+
if (storageWindow) {
|
|
215
|
+
// For syncing color-scheme changes between iframes
|
|
216
|
+
storageWindow.addEventListener('storage', handleStorage);
|
|
217
|
+
return () => storageWindow.removeEventListener('storage', handleStorage);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
return undefined;
|
|
221
|
+
}, [setColorScheme, setMode, modeStorageKey, colorSchemeStorageKey, joinedColorSchemes, defaultMode, storageWindow]);
|
|
212
222
|
return _extends({}, state, {
|
|
213
223
|
colorScheme,
|
|
214
224
|
setMode,
|
package/esm/index.js
CHANGED
|
@@ -39,4 +39,7 @@ export { default as useThemeWithoutDefault } from './useThemeWithoutDefault';
|
|
|
39
39
|
export * from './colorManipulator';
|
|
40
40
|
export { default as ThemeProvider } from './ThemeProvider';
|
|
41
41
|
export { default as unstable_createCssVarsProvider } from './cssVars/createCssVarsProvider';
|
|
42
|
-
export { default as unstable_createGetCssVar } from './cssVars/createGetCssVar';
|
|
42
|
+
export { default as unstable_createGetCssVar } from './cssVars/createGetCssVar';
|
|
43
|
+
export { default as createContainer } from './Container/createContainer';
|
|
44
|
+
export { default as Container } from './Container';
|
|
45
|
+
export * from './Container';
|
package/index.d.ts
CHANGED
|
@@ -169,3 +169,9 @@ export * from './ThemeProvider';
|
|
|
169
169
|
export { default as unstable_createCssVarsProvider, CreateCssVarsProviderResult } from './cssVars';
|
|
170
170
|
export { default as unstable_createGetCssVar } from './cssVars/createGetCssVar';
|
|
171
171
|
export * from './cssVars';
|
|
172
|
+
|
|
173
|
+
export { default as createContainer } from './Container/createContainer';
|
|
174
|
+
export * from './Container/createContainer';
|
|
175
|
+
|
|
176
|
+
export { default as Container } from './Container';
|
|
177
|
+
export * from './Container';
|
package/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** @license MUI v5.
|
|
1
|
+
/** @license MUI v5.8.0
|
|
2
2
|
*
|
|
3
3
|
* This source code is licensed under the MIT license found in the
|
|
4
4
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -51,7 +51,9 @@ var _exportNames = {
|
|
|
51
51
|
useThemeWithoutDefault: true,
|
|
52
52
|
ThemeProvider: true,
|
|
53
53
|
unstable_createCssVarsProvider: true,
|
|
54
|
-
unstable_createGetCssVar: true
|
|
54
|
+
unstable_createGetCssVar: true,
|
|
55
|
+
createContainer: true,
|
|
56
|
+
Container: true
|
|
55
57
|
};
|
|
56
58
|
Object.defineProperty(exports, "Box", {
|
|
57
59
|
enumerable: true,
|
|
@@ -59,6 +61,12 @@ Object.defineProperty(exports, "Box", {
|
|
|
59
61
|
return _Box.default;
|
|
60
62
|
}
|
|
61
63
|
});
|
|
64
|
+
Object.defineProperty(exports, "Container", {
|
|
65
|
+
enumerable: true,
|
|
66
|
+
get: function () {
|
|
67
|
+
return _Container.default;
|
|
68
|
+
}
|
|
69
|
+
});
|
|
62
70
|
Object.defineProperty(exports, "GlobalStyles", {
|
|
63
71
|
enumerable: true,
|
|
64
72
|
get: function () {
|
|
@@ -107,6 +115,12 @@ Object.defineProperty(exports, "createBreakpoints", {
|
|
|
107
115
|
return _createBreakpoints.default;
|
|
108
116
|
}
|
|
109
117
|
});
|
|
118
|
+
Object.defineProperty(exports, "createContainer", {
|
|
119
|
+
enumerable: true,
|
|
120
|
+
get: function () {
|
|
121
|
+
return _createContainer.default;
|
|
122
|
+
}
|
|
123
|
+
});
|
|
110
124
|
Object.defineProperty(exports, "createSpacing", {
|
|
111
125
|
enumerable: true,
|
|
112
126
|
get: function () {
|
|
@@ -484,6 +498,22 @@ var _createCssVarsProvider = _interopRequireDefault(require("./cssVars/createCss
|
|
|
484
498
|
|
|
485
499
|
var _createGetCssVar = _interopRequireDefault(require("./cssVars/createGetCssVar"));
|
|
486
500
|
|
|
501
|
+
var _createContainer = _interopRequireDefault(require("./Container/createContainer"));
|
|
502
|
+
|
|
503
|
+
var _Container = _interopRequireWildcard(require("./Container"));
|
|
504
|
+
|
|
505
|
+
Object.keys(_Container).forEach(function (key) {
|
|
506
|
+
if (key === "default" || key === "__esModule") return;
|
|
507
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
508
|
+
if (key in exports && exports[key] === _Container[key]) return;
|
|
509
|
+
Object.defineProperty(exports, key, {
|
|
510
|
+
enumerable: true,
|
|
511
|
+
get: function () {
|
|
512
|
+
return _Container[key];
|
|
513
|
+
}
|
|
514
|
+
});
|
|
515
|
+
});
|
|
516
|
+
|
|
487
517
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
488
518
|
|
|
489
519
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
package/index.spec.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import PropTypes from 'prop-types';
|
|
2
|
+
import createContainer from './createContainer';
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* Demos:
|
|
6
|
+
*
|
|
7
|
+
* - [Container (Material UI)](https://mui.com/material-ui/react-container/)
|
|
8
|
+
* - [Container (MUI System)](https://mui.com/system/react-container/)
|
|
9
|
+
*
|
|
10
|
+
* API:
|
|
11
|
+
*
|
|
12
|
+
* - [Container API](https://mui.com/system/api/container/)
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
var Container = createContainer();
|
|
16
|
+
process.env.NODE_ENV !== "production" ? Container.propTypes
|
|
17
|
+
/* remove-proptypes */
|
|
18
|
+
= {
|
|
19
|
+
// ----------------------------- Warning --------------------------------
|
|
20
|
+
// | These PropTypes are generated from the TypeScript type definitions |
|
|
21
|
+
// | To update them edit TypeScript types and run "yarn proptypes" |
|
|
22
|
+
// ----------------------------------------------------------------------
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @ignore
|
|
26
|
+
*/
|
|
27
|
+
children: PropTypes.node,
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Override or extend the styles applied to the component.
|
|
31
|
+
*/
|
|
32
|
+
classes: PropTypes.object,
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The component used for the root node.
|
|
36
|
+
* Either a string to use a HTML element or a component.
|
|
37
|
+
*/
|
|
38
|
+
component: PropTypes.elementType,
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* If `true`, the left and right padding is removed.
|
|
42
|
+
* @default false
|
|
43
|
+
*/
|
|
44
|
+
disableGutters: PropTypes.bool,
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Set the max-width to match the min-width of the current breakpoint.
|
|
48
|
+
* This is useful if you'd prefer to design for a fixed set of sizes
|
|
49
|
+
* instead of trying to accommodate a fully fluid viewport.
|
|
50
|
+
* It's fluid by default.
|
|
51
|
+
* @default false
|
|
52
|
+
*/
|
|
53
|
+
fixed: PropTypes.bool,
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Determine the max-width of the container.
|
|
57
|
+
* The container width grows with the size of the screen.
|
|
58
|
+
* Set to `false` to disable `maxWidth`.
|
|
59
|
+
* @default 'lg'
|
|
60
|
+
*/
|
|
61
|
+
maxWidth: PropTypes
|
|
62
|
+
/* @typescript-to-proptypes-ignore */
|
|
63
|
+
.oneOfType([PropTypes.oneOf(['xs', 'sm', 'md', 'lg', 'xl', false]), PropTypes.string]),
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* The system prop that allows defining system overrides as well as additional CSS styles.
|
|
67
|
+
*/
|
|
68
|
+
sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
|
|
69
|
+
} : void 0;
|
|
70
|
+
export default Container;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { unstable_generateUtilityClass as generateUtilityClass, unstable_generateUtilityClasses as generateUtilityClasses } from '@mui/utils';
|
|
2
|
+
export function getContainerUtilityClass(slot) {
|
|
3
|
+
return generateUtilityClass('MuiContainer', slot);
|
|
4
|
+
}
|
|
5
|
+
var containerClasses = generateUtilityClasses('MuiContainer', ['root', 'disableGutters', 'fixed', 'maxWidthXs', 'maxWidthSm', 'maxWidthMd', 'maxWidthLg', 'maxWidthXl']);
|
|
6
|
+
export default containerClasses;
|