@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.
Files changed (67) hide show
  1. package/Box/Box.spec.d.ts +1 -1
  2. package/CHANGELOG.md +238 -0
  3. package/Container/Container.d.ts +13 -0
  4. package/Container/Container.js +81 -0
  5. package/Container/ContainerProps.d.ts +40 -0
  6. package/Container/ContainerProps.js +5 -0
  7. package/Container/containerClasses.d.ts +22 -0
  8. package/Container/containerClasses.js +17 -0
  9. package/Container/createContainer.d.ts +18 -0
  10. package/Container/createContainer.js +172 -0
  11. package/Container/index.d.ts +5 -0
  12. package/Container/index.js +42 -0
  13. package/Container/package.json +6 -0
  14. package/ThemeProvider/ThemeProvider.d.ts +1 -1
  15. package/createBox.spec.d.ts +1 -1
  16. package/createStyled.js +3 -1
  17. package/createTheme/createBreakpoints.d.ts +5 -0
  18. package/createTheme/createSpacing.d.ts +10 -10
  19. package/cssVars/createCssVarsProvider.d.ts +25 -0
  20. package/cssVars/createCssVarsProvider.js +74 -57
  21. package/cssVars/createCssVarsProvider.spec.d.ts +1 -1
  22. package/cssVars/createGetCssVar.d.ts +5 -5
  23. package/cssVars/cssVarsParser.d.ts +70 -70
  24. package/cssVars/cssVarsParser.js +11 -9
  25. package/cssVars/getInitColorSchemeScript.d.ts +40 -12
  26. package/cssVars/getInitColorSchemeScript.js +4 -3
  27. package/cssVars/index.d.ts +2 -2
  28. package/cssVars/useCurrentColorScheme.d.ts +53 -50
  29. package/cssVars/useCurrentColorScheme.js +17 -7
  30. package/esm/Container/Container.js +70 -0
  31. package/esm/Container/ContainerProps.js +1 -0
  32. package/esm/Container/containerClasses.js +6 -0
  33. package/esm/Container/createContainer.js +151 -0
  34. package/esm/Container/index.js +3 -0
  35. package/esm/createStyled.js +3 -1
  36. package/esm/cssVars/createCssVarsProvider.js +76 -57
  37. package/esm/cssVars/cssVarsParser.js +11 -9
  38. package/esm/cssVars/getInitColorSchemeScript.js +4 -3
  39. package/esm/cssVars/useCurrentColorScheme.js +17 -7
  40. package/esm/index.js +4 -1
  41. package/index.d.ts +6 -0
  42. package/index.js +32 -2
  43. package/index.spec.d.ts +1 -1
  44. package/legacy/Container/Container.js +70 -0
  45. package/legacy/Container/ContainerProps.js +1 -0
  46. package/legacy/Container/containerClasses.js +6 -0
  47. package/legacy/Container/createContainer.js +148 -0
  48. package/legacy/Container/index.js +3 -0
  49. package/legacy/createStyled.js +3 -1
  50. package/legacy/cssVars/createCssVarsProvider.js +83 -55
  51. package/legacy/cssVars/cssVarsParser.js +11 -7
  52. package/legacy/cssVars/getInitColorSchemeScript.js +6 -3
  53. package/legacy/cssVars/useCurrentColorScheme.js +20 -9
  54. package/legacy/index.js +5 -2
  55. package/modern/Container/Container.js +70 -0
  56. package/modern/Container/ContainerProps.js +1 -0
  57. package/modern/Container/containerClasses.js +6 -0
  58. package/modern/Container/createContainer.js +151 -0
  59. package/modern/Container/index.js +3 -0
  60. package/modern/createStyled.js +3 -1
  61. package/modern/cssVars/createCssVarsProvider.js +76 -55
  62. package/modern/cssVars/cssVarsParser.js +11 -9
  63. package/modern/cssVars/getInitColorSchemeScript.js +4 -3
  64. package/modern/cssVars/useCurrentColorScheme.js +17 -7
  65. package/modern/index.js +5 -2
  66. package/package.json +5 -5
  67. package/styleFunctionSx/styleFunctionSx.spec.d.ts +1 -1
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ var _exportNames = {
9
+ containerClasses: true
10
+ };
11
+ Object.defineProperty(exports, "containerClasses", {
12
+ enumerable: true,
13
+ get: function () {
14
+ return _containerClasses.default;
15
+ }
16
+ });
17
+ Object.defineProperty(exports, "default", {
18
+ enumerable: true,
19
+ get: function () {
20
+ return _Container.default;
21
+ }
22
+ });
23
+
24
+ var _Container = _interopRequireDefault(require("./Container"));
25
+
26
+ var _containerClasses = _interopRequireWildcard(require("./containerClasses"));
27
+
28
+ Object.keys(_containerClasses).forEach(function (key) {
29
+ if (key === "default" || key === "__esModule") return;
30
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
31
+ if (key in exports && exports[key] === _containerClasses[key]) return;
32
+ Object.defineProperty(exports, key, {
33
+ enumerable: true,
34
+ get: function () {
35
+ return _containerClasses[key];
36
+ }
37
+ });
38
+ });
39
+
40
+ 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); }
41
+
42
+ 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; }
@@ -0,0 +1,6 @@
1
+ {
2
+ "sideEffects": false,
3
+ "module": "../esm/Container/index.js",
4
+ "main": "./index.js",
5
+ "types": "./index.d.ts"
6
+ }
@@ -16,7 +16,7 @@ export interface ThemeProviderProps<Theme = DefaultTheme> {
16
16
  * It should preferably be used at **the root of your component tree**.
17
17
  * API:
18
18
  *
19
- * - [ThemeProvider API](/material-ui/customization/theming/#themeprovider)
19
+ * - [ThemeProvider API](https://mui.com/material-ui/customization/theming/#themeprovider)
20
20
  */
21
21
  export default function ThemeProvider<T = DefaultTheme>(
22
22
  props: ThemeProviderProps<T>,
@@ -1 +1 @@
1
- export {};
1
+ export {};
package/createStyled.js CHANGED
@@ -160,7 +160,9 @@ function createStyled(input = {}) {
160
160
  if (styleOverrides) {
161
161
  const resolvedStyleOverrides = {};
162
162
  Object.entries(styleOverrides).forEach(([slotKey, slotStyle]) => {
163
- resolvedStyleOverrides[slotKey] = typeof slotStyle === 'function' ? slotStyle(props) : slotStyle;
163
+ resolvedStyleOverrides[slotKey] = typeof slotStyle === 'function' ? slotStyle((0, _extends2.default)({}, props, {
164
+ theme
165
+ })) : slotStyle;
164
166
  });
165
167
  return overridesResolver(props, resolvedStyleOverrides);
166
168
  }
@@ -61,6 +61,11 @@ export interface Breakpoints {
61
61
  * the screen size given by the breakpoint key (exclusive) and starting at the screen size given by the next breakpoint key (inclusive).
62
62
  */
63
63
  not: (key: Breakpoint) => string;
64
+ /**
65
+ * The unit used for the breakpoint's values.
66
+ * @default 'px'
67
+ */
68
+ unit?: string | undefined;
64
69
  }
65
70
 
66
71
  export interface BreakpointsOptions extends Partial<Breakpoints> {
@@ -1,10 +1,10 @@
1
- export declare type SpacingOptions = number | Spacing | ((abs: number) => number | string) | ((abs: number | string) => number | string) | ReadonlyArray<string | number>;
2
- export declare type SpacingArgument = number | string;
3
- export interface Spacing {
4
- (): string;
5
- (value: number): string;
6
- (topBottom: SpacingArgument, rightLeft: SpacingArgument): string;
7
- (top: SpacingArgument, rightLeft: SpacingArgument, bottom: SpacingArgument): string;
8
- (top: SpacingArgument, right: SpacingArgument, bottom: SpacingArgument, left: SpacingArgument): string;
9
- }
10
- export default function createSpacing(spacingInput?: SpacingOptions): Spacing;
1
+ export declare type SpacingOptions = number | Spacing | ((abs: number) => number | string) | ((abs: number | string) => number | string) | ReadonlyArray<string | number>;
2
+ export declare type SpacingArgument = number | string;
3
+ export interface Spacing {
4
+ (): string;
5
+ (value: number): string;
6
+ (topBottom: SpacingArgument, rightLeft: SpacingArgument): string;
7
+ (top: SpacingArgument, rightLeft: SpacingArgument, bottom: SpacingArgument): string;
8
+ (top: SpacingArgument, right: SpacingArgument, bottom: SpacingArgument, left: SpacingArgument): string;
9
+ }
10
+ export default function createSpacing(spacingInput?: SpacingOptions): Spacing;
@@ -51,6 +51,31 @@ export interface CreateCssVarsProviderResult<ColorScheme extends string, ThemeIn
51
51
  * @default 'data-mui-color-scheme'
52
52
  */
53
53
  attribute?: string;
54
+ /**
55
+ * The document used to perform `disableTransitionOnChange` feature
56
+ * @default document
57
+ */
58
+ documentNode?: Document | null;
59
+ /**
60
+ * The node used to attach the color-scheme attribute
61
+ * @default document
62
+ */
63
+ colorSchemeNode?: Document | HTMLElement | null;
64
+ /**
65
+ * The CSS selector for attaching the generated custom properties
66
+ * @default ':root'
67
+ */
68
+ colorSchemeSelector?: string;
69
+ /**
70
+ * localStorage key used to store `colorScheme`
71
+ * @default 'mui-color-scheme'
72
+ */
73
+ colorSchemeStorageKey?: string;
74
+ /**
75
+ * The window that attaches the 'storage' event listener
76
+ * @default window
77
+ */
78
+ storageWindow?: Window | null;
54
79
  }
55
80
  >,
56
81
  ) => React.ReactElement;
@@ -20,10 +20,6 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
20
20
 
21
21
  var _styledEngine = require("@mui/styled-engine");
22
22
 
23
- var _createSpacing = _interopRequireDefault(require("../createTheme/createSpacing"));
24
-
25
- var _createBreakpoints = _interopRequireDefault(require("../createTheme/createBreakpoints"));
26
-
27
23
  var _cssVarsParser = _interopRequireDefault(require("./cssVarsParser"));
28
24
 
29
25
  var _ThemeProvider = _interopRequireDefault(require("../ThemeProvider"));
@@ -36,9 +32,7 @@ var _createGetCssVar = _interopRequireDefault(require("./createGetCssVar"));
36
32
 
37
33
  var _jsxRuntime = require("react/jsx-runtime");
38
34
 
39
- const _excluded = ["colorSchemes"],
40
- _excluded2 = ["colorSchemes"],
41
- _excluded3 = ["components"];
35
+ const _excluded = ["colorSchemes", "components"];
42
36
 
43
37
  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); }
44
38
 
@@ -48,10 +42,8 @@ const DISABLE_CSS_TRANSITION = '*{-webkit-transition:none!important;-moz-transit
48
42
  exports.DISABLE_CSS_TRANSITION = DISABLE_CSS_TRANSITION;
49
43
 
50
44
  function createCssVarsProvider(options) {
51
- var _baseTheme$breakpoint;
52
-
53
45
  const {
54
- theme: baseTheme = {},
46
+ theme: defaultTheme = {},
55
47
  defaultMode: desisgnSystemMode = 'light',
56
48
  defaultColorScheme: designSystemColorScheme,
57
49
  disableTransitionOnChange: designSystemTransitionOnChange = false,
@@ -60,10 +52,8 @@ function createCssVarsProvider(options) {
60
52
  shouldSkipGeneratingVar,
61
53
  resolveTheme
62
54
  } = options;
63
- const systemSpacing = (0, _createSpacing.default)(baseTheme.spacing);
64
- const systemBreakpoints = (0, _createBreakpoints.default)((_baseTheme$breakpoint = baseTheme.breakpoints) != null ? _baseTheme$breakpoint : {});
65
55
 
66
- if (!baseTheme.colorSchemes || typeof designSystemColorScheme === 'string' && !baseTheme.colorSchemes[designSystemColorScheme] || typeof designSystemColorScheme === 'object' && !baseTheme.colorSchemes[designSystemColorScheme == null ? void 0 : designSystemColorScheme.light] || typeof designSystemColorScheme === 'object' && !baseTheme.colorSchemes[designSystemColorScheme == null ? void 0 : designSystemColorScheme.dark]) {
56
+ 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]) {
67
57
  console.error(`MUI: \`${designSystemColorScheme}\` does not exist in \`theme.colorSchemes\`.`);
68
58
  }
69
59
 
@@ -81,32 +71,26 @@ function createCssVarsProvider(options) {
81
71
 
82
72
  function CssVarsProvider({
83
73
  children,
84
- theme: themeProp = {},
74
+ theme: themeProp = defaultTheme,
85
75
  prefix = designSystemPrefix,
86
76
  modeStorageKey = _getInitColorSchemeScript.DEFAULT_MODE_STORAGE_KEY,
77
+ colorSchemeStorageKey = _getInitColorSchemeScript.DEFAULT_COLOR_SCHEME_STORAGE_KEY,
87
78
  attribute = _getInitColorSchemeScript.DEFAULT_ATTRIBUTE,
88
79
  defaultMode = desisgnSystemMode,
89
80
  defaultColorScheme = designSystemColorScheme,
90
81
  disableTransitionOnChange = designSystemTransitionOnChange,
91
- enableColorScheme = designSystemEnableColorScheme
82
+ enableColorScheme = designSystemEnableColorScheme,
83
+ storageWindow = typeof window === 'undefined' ? undefined : window,
84
+ documentNode = typeof document === 'undefined' ? undefined : document,
85
+ colorSchemeNode = typeof document === 'undefined' ? undefined : document.documentElement,
86
+ colorSchemeSelector = ':root'
92
87
  }) {
88
+ const hasMounted = React.useRef(false);
93
89
  const {
94
- colorSchemes: baseColorSchemes = {}
95
- } = baseTheme,
96
- restBaseTheme = (0, _objectWithoutPropertiesLoose2.default)(baseTheme, _excluded);
97
- const {
98
- colorSchemes: colorSchemesProp = {}
99
- } = themeProp,
100
- restThemeProp = (0, _objectWithoutPropertiesLoose2.default)(themeProp, _excluded2);
101
- const hasMounted = React.useRef(false); // eslint-disable-next-line prefer-const
102
-
103
- let _deepmerge = (0, _utils.deepmerge)(restBaseTheme, restThemeProp),
104
- {
90
+ colorSchemes = {},
105
91
  components = {}
106
- } = _deepmerge,
107
- mergedTheme = (0, _objectWithoutPropertiesLoose2.default)(_deepmerge, _excluded3);
108
-
109
- const colorSchemes = (0, _utils.deepmerge)(baseColorSchemes, colorSchemesProp);
92
+ } = themeProp,
93
+ restThemeProp = (0, _objectWithoutPropertiesLoose2.default)(themeProp, _excluded);
110
94
  const allColorSchemes = Object.keys(colorSchemes);
111
95
  const defaultLightColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.light;
112
96
  const defaultDarkColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.dark;
@@ -123,7 +107,9 @@ function createCssVarsProvider(options) {
123
107
  defaultLightColorScheme,
124
108
  defaultDarkColorScheme,
125
109
  modeStorageKey,
126
- defaultMode
110
+ colorSchemeStorageKey,
111
+ defaultMode,
112
+ storageWindow
127
113
  });
128
114
 
129
115
  const resolvedColorScheme = (() => {
@@ -140,22 +126,21 @@ function createCssVarsProvider(options) {
140
126
  return colorScheme;
141
127
  })();
142
128
 
129
+ let theme = restThemeProp;
143
130
  const {
144
131
  css: rootCss,
145
132
  vars: rootVars,
146
133
  parsedTheme
147
- } = (0, _cssVarsParser.default)(mergedTheme, {
134
+ } = (0, _cssVarsParser.default)(theme, {
148
135
  prefix,
149
136
  basePrefix: designSystemPrefix,
150
137
  shouldSkipGeneratingVar
151
138
  });
152
- mergedTheme = (0, _extends2.default)({}, parsedTheme, {
139
+ theme = (0, _extends2.default)({}, parsedTheme, {
153
140
  components,
154
141
  colorSchemes,
155
142
  prefix,
156
143
  vars: rootVars,
157
- spacing: themeProp.spacing ? (0, _createSpacing.default)(themeProp.spacing) : systemSpacing,
158
- breakpoints: themeProp.breakpoints ? (0, _createBreakpoints.default)(themeProp.breakpoints) : systemBreakpoints,
159
144
  getCssVar: (0, _createGetCssVar.default)(prefix)
160
145
  });
161
146
  const styleSheet = {};
@@ -169,10 +154,16 @@ function createCssVarsProvider(options) {
169
154
  basePrefix: designSystemPrefix,
170
155
  shouldSkipGeneratingVar
171
156
  });
172
- mergedTheme.vars = (0, _utils.deepmerge)(mergedTheme.vars, vars);
157
+ theme.vars = (0, _utils.deepmerge)(theme.vars, vars);
173
158
 
174
159
  if (key === resolvedColorScheme) {
175
- mergedTheme = (0, _extends2.default)({}, mergedTheme, parsedScheme);
160
+ theme = (0, _extends2.default)({}, theme, parsedScheme);
161
+
162
+ if (theme.palette) {
163
+ // assign runtime mode & colorScheme
164
+ theme.palette.mode = mode;
165
+ theme.palette.colorScheme = resolvedColorScheme;
166
+ }
176
167
  }
177
168
 
178
169
  const resolvedDefaultColorScheme = (() => {
@@ -188,54 +179,54 @@ function createCssVarsProvider(options) {
188
179
  })();
189
180
 
190
181
  if (key === resolvedDefaultColorScheme) {
191
- styleSheet[':root'] = css;
182
+ styleSheet[colorSchemeSelector] = css;
192
183
  } else {
193
- styleSheet[`[${attribute}="${key}"]`] = css;
184
+ styleSheet[`${colorSchemeSelector === ':root' ? '' : colorSchemeSelector}[${attribute}="${key}"]`] = css;
194
185
  }
195
186
  });
196
187
  React.useEffect(() => {
197
- if (colorScheme) {
188
+ if (colorScheme && colorSchemeNode) {
198
189
  // attaches attribute to <html> because the css variables are attached to :root (html)
199
- document.documentElement.setAttribute(attribute, colorScheme);
190
+ colorSchemeNode.setAttribute(attribute, colorScheme);
200
191
  }
201
- }, [colorScheme, attribute]);
192
+ }, [colorScheme, attribute, colorSchemeNode]);
202
193
  (0, _utils.unstable_useEnhancedEffect)(() => {
203
- if (!mode || !enableColorScheme) {
194
+ if (!mode || !enableColorScheme || !colorSchemeNode) {
204
195
  return undefined;
205
196
  }
206
197
 
207
- const priorColorScheme = document.documentElement.style.getPropertyValue('color-scheme'); // `color-scheme` tells browser to render built-in elements according to its value: `light` or `dark`
198
+ const priorColorScheme = colorSchemeNode.style.getPropertyValue('color-scheme'); // `color-scheme` tells browser to render built-in elements according to its value: `light` or `dark`
208
199
 
209
200
  if (mode === 'system') {
210
- document.documentElement.style.setProperty('color-scheme', systemMode);
201
+ colorSchemeNode.style.setProperty('color-scheme', systemMode);
211
202
  } else {
212
- document.documentElement.style.setProperty('color-scheme', mode);
203
+ colorSchemeNode.style.setProperty('color-scheme', mode);
213
204
  }
214
205
 
215
206
  return () => {
216
- document.documentElement.style.setProperty('color-scheme', priorColorScheme);
207
+ colorSchemeNode.style.setProperty('color-scheme', priorColorScheme);
217
208
  };
218
- }, [mode, systemMode, enableColorScheme]);
209
+ }, [mode, systemMode, enableColorScheme, colorSchemeNode]);
219
210
  React.useEffect(() => {
220
211
  let timer;
221
212
 
222
- if (disableTransitionOnChange && hasMounted.current) {
213
+ if (disableTransitionOnChange && hasMounted.current && documentNode) {
223
214
  // credit: https://github.com/pacocoursey/next-themes/blob/b5c2bad50de2d61ad7b52a9c5cdc801a78507d7a/index.tsx#L313
224
- const css = document.createElement('style');
225
- css.appendChild(document.createTextNode(DISABLE_CSS_TRANSITION));
226
- document.head.appendChild(css); // Force browser repaint
215
+ const css = documentNode.createElement('style');
216
+ css.appendChild(documentNode.createTextNode(DISABLE_CSS_TRANSITION));
217
+ documentNode.head.appendChild(css); // Force browser repaint
227
218
 
228
- (() => window.getComputedStyle(document.body))();
219
+ (() => window.getComputedStyle(documentNode.body))();
229
220
 
230
221
  timer = setTimeout(() => {
231
- document.head.removeChild(css);
222
+ documentNode.head.removeChild(css);
232
223
  }, 1);
233
224
  }
234
225
 
235
226
  return () => {
236
227
  clearTimeout(timer);
237
228
  };
238
- }, [colorScheme, disableTransitionOnChange]);
229
+ }, [colorScheme, disableTransitionOnChange, documentNode]);
239
230
  React.useEffect(() => {
240
231
  hasMounted.current = true;
241
232
  return () => {
@@ -254,12 +245,12 @@ function createCssVarsProvider(options) {
254
245
  },
255
246
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_styledEngine.GlobalStyles, {
256
247
  styles: {
257
- ':root': rootCss
248
+ [colorSchemeSelector]: rootCss
258
249
  }
259
250
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_styledEngine.GlobalStyles, {
260
251
  styles: styleSheet
261
252
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ThemeProvider.default, {
262
- theme: resolveTheme ? resolveTheme(mergedTheme) : mergedTheme,
253
+ theme: resolveTheme ? resolveTheme(theme) : theme,
263
254
  children: children
264
255
  })]
265
256
  });
@@ -276,6 +267,21 @@ function createCssVarsProvider(options) {
276
267
  */
277
268
  children: _propTypes.default.node,
278
269
 
270
+ /**
271
+ * The node used to attach the color-scheme attribute
272
+ */
273
+ colorSchemeNode: _propTypes.default.any,
274
+
275
+ /**
276
+ * The CSS selector for attaching the generated custom properties
277
+ */
278
+ colorSchemeSelector: _propTypes.default.string,
279
+
280
+ /**
281
+ * localStorage key used to store `colorScheme`
282
+ */
283
+ colorSchemeStorageKey: _propTypes.default.string,
284
+
279
285
  /**
280
286
  * The initial color scheme used.
281
287
  */
@@ -291,6 +297,11 @@ function createCssVarsProvider(options) {
291
297
  */
292
298
  disableTransitionOnChange: _propTypes.default.bool,
293
299
 
300
+ /**
301
+ * The document to attach the attribute to
302
+ */
303
+ documentNode: _propTypes.default.any,
304
+
294
305
  /**
295
306
  * Indicate to the browser which color scheme is used (light or dark) for rendering built-in UI
296
307
  */
@@ -306,6 +317,12 @@ function createCssVarsProvider(options) {
306
317
  */
307
318
  prefix: _propTypes.default.string,
308
319
 
320
+ /**
321
+ * The window that attaches the 'storage' event listener
322
+ * @default window
323
+ */
324
+ storageWindow: _propTypes.default.any,
325
+
309
326
  /**
310
327
  * The calculated theme object that will be passed through context.
311
328
  */
@@ -1 +1 @@
1
- export {};
1
+ export {};
@@ -1,5 +1,5 @@
1
- /**
2
- * The benefit of this function is to help developers get CSS var from theme without specifying the whole variable
3
- * and they does not need to remember the prefix (defined once).
4
- */
5
- export default function createGetCssVar<T extends string = string>(prefix?: string): <AdditionalVars extends string = never>(field: T | AdditionalVars, ...vars: (T | AdditionalVars)[]) => string;
1
+ /**
2
+ * The benefit of this function is to help developers get CSS var from theme without specifying the whole variable
3
+ * and they does not need to remember the prefix (defined once).
4
+ */
5
+ export default function createGetCssVar<T extends string = string>(prefix?: string): <AdditionalVars extends string = never>(field: T | AdditionalVars, ...vars: (T | AdditionalVars)[]) => string;
@@ -1,70 +1,70 @@
1
- declare type NestedRecord<V = any> = {
2
- [k: string | number]: NestedRecord<V> | V;
3
- };
4
- /**
5
- * This function create an object from keys, value and then assign to target
6
- *
7
- * @param {Object} obj : the target object to be assigned
8
- * @param {string[]} keys
9
- * @param {string | number} value
10
- *
11
- * @example
12
- * const source = {}
13
- * assignNestedKeys(source, ['palette', 'primary'], 'var(--palette-primary)')
14
- * console.log(source) // { palette: { primary: 'var(--palette-primary)' } }
15
- *
16
- * @example
17
- * const source = { palette: { primary: 'var(--palette-primary)' } }
18
- * assignNestedKeys(source, ['palette', 'secondary'], 'var(--palette-secondary)')
19
- * console.log(source) // { palette: { primary: 'var(--palette-primary)', secondary: 'var(--palette-secondary)' } }
20
- */
21
- export declare const assignNestedKeys: <Object_1 = NestedRecord<any>, Value = any>(obj: Object_1, keys: Array<string>, value: Value) => void;
22
- /**
23
- *
24
- * @param {Object} obj : source object
25
- * @param {Function} callback : a function that will be called when
26
- * - the deepest key in source object is reached
27
- * - the value of the deepest key is NOT `undefined` | `null`
28
- *
29
- * @example
30
- * walkObjectDeep({ palette: { primary: { main: '#000000' } } }, console.log)
31
- * // ['palette', 'primary', 'main'] '#000000'
32
- */
33
- export declare const walkObjectDeep: <Value, T = Record<string, any>>(obj: T, callback: (keys: Array<string>, value: Value, scope: Record<string, string | number>) => void, shouldSkipPaths?: ((keys: Array<string>) => boolean) | undefined) => void;
34
- /**
35
- * a function that parse theme and return { css, vars }
36
- *
37
- * @param {Object} theme
38
- * @param {{
39
- * prefix?: string,
40
- * basePrefix?: string,
41
- * shouldSkipGeneratingVar?: (objectPathKeys: Array<string>, value: string | number) => boolean
42
- * }} options.
43
- * `basePrefix`: defined by design system.
44
- * `prefix`: defined by application
45
- *
46
- * the CSS variable value will be adjusted based on the provided `basePrefix` & `prefix` which can be found in `parsedTheme`.
47
- *
48
- * @returns {{ css: Object, vars: Object, parsedTheme: typeof theme }} `css` is the stylesheet, `vars` is an object to get css variable (same structure as theme), and `parsedTheme` is the cloned version of theme.
49
- *
50
- * @example
51
- * const { css, vars, parsedTheme } = parser({
52
- * fontSize: 12,
53
- * lineHeight: 1.2,
54
- * palette: { primary: { 500: 'var(--color)' } }
55
- * }, { prefix: 'foo' })
56
- *
57
- * console.log(css) // { '--foo-fontSize': '12px', '--foo-lineHeight': 1.2, '--foo-palette-primary-500': 'var(--foo-color)' }
58
- * console.log(vars) // { fontSize: '--foo-fontSize', lineHeight: '--foo-lineHeight', palette: { primary: { 500: 'var(--foo-palette-primary-500)' } } }
59
- * console.log(parsedTheme) // { fontSize: 12, lineHeight: 1.2, palette: { primary: { 500: 'var(--foo-color)' } } }
60
- */
61
- export default function cssVarsParser<T extends Record<string, any>>(theme: T, options?: {
62
- prefix?: string;
63
- basePrefix?: string;
64
- shouldSkipGeneratingVar?: (objectPathKeys: Array<string>, value: string | number) => boolean;
65
- }): {
66
- css: NestedRecord<string>;
67
- vars: NestedRecord<string>;
68
- parsedTheme: T;
69
- };
70
- export {};
1
+ declare type NestedRecord<V = any> = {
2
+ [k: string | number]: NestedRecord<V> | V;
3
+ };
4
+ /**
5
+ * This function create an object from keys, value and then assign to target
6
+ *
7
+ * @param {Object} obj : the target object to be assigned
8
+ * @param {string[]} keys
9
+ * @param {string | number} value
10
+ *
11
+ * @example
12
+ * const source = {}
13
+ * assignNestedKeys(source, ['palette', 'primary'], 'var(--palette-primary)')
14
+ * console.log(source) // { palette: { primary: 'var(--palette-primary)' } }
15
+ *
16
+ * @example
17
+ * const source = { palette: { primary: 'var(--palette-primary)' } }
18
+ * assignNestedKeys(source, ['palette', 'secondary'], 'var(--palette-secondary)')
19
+ * console.log(source) // { palette: { primary: 'var(--palette-primary)', secondary: 'var(--palette-secondary)' } }
20
+ */
21
+ export declare const assignNestedKeys: <Object_1 = NestedRecord<any>, Value = any>(obj: Object_1, keys: Array<string>, value: Value, arrayKeys?: Array<string>) => void;
22
+ /**
23
+ *
24
+ * @param {Object} obj : source object
25
+ * @param {Function} callback : a function that will be called when
26
+ * - the deepest key in source object is reached
27
+ * - the value of the deepest key is NOT `undefined` | `null`
28
+ *
29
+ * @example
30
+ * walkObjectDeep({ palette: { primary: { main: '#000000' } } }, console.log)
31
+ * // ['palette', 'primary', 'main'] '#000000'
32
+ */
33
+ export declare const walkObjectDeep: <Value, T = Record<string, any>>(obj: T, callback: (keys: Array<string>, value: Value, arrayKeys: Array<string>) => void, shouldSkipPaths?: ((keys: Array<string>) => boolean) | undefined) => void;
34
+ /**
35
+ * a function that parse theme and return { css, vars }
36
+ *
37
+ * @param {Object} theme
38
+ * @param {{
39
+ * prefix?: string,
40
+ * basePrefix?: string,
41
+ * shouldSkipGeneratingVar?: (objectPathKeys: Array<string>, value: string | number) => boolean
42
+ * }} options.
43
+ * `basePrefix`: defined by design system.
44
+ * `prefix`: defined by application
45
+ *
46
+ * the CSS variable value will be adjusted based on the provided `basePrefix` & `prefix` which can be found in `parsedTheme`.
47
+ *
48
+ * @returns {{ css: Object, vars: Object, parsedTheme: typeof theme }} `css` is the stylesheet, `vars` is an object to get css variable (same structure as theme), and `parsedTheme` is the cloned version of theme.
49
+ *
50
+ * @example
51
+ * const { css, vars, parsedTheme } = parser({
52
+ * fontSize: 12,
53
+ * lineHeight: 1.2,
54
+ * palette: { primary: { 500: 'var(--color)' } }
55
+ * }, { prefix: 'foo' })
56
+ *
57
+ * console.log(css) // { '--foo-fontSize': '12px', '--foo-lineHeight': 1.2, '--foo-palette-primary-500': 'var(--foo-color)' }
58
+ * console.log(vars) // { fontSize: '--foo-fontSize', lineHeight: '--foo-lineHeight', palette: { primary: { 500: 'var(--foo-palette-primary-500)' } } }
59
+ * console.log(parsedTheme) // { fontSize: 12, lineHeight: 1.2, palette: { primary: { 500: 'var(--foo-color)' } } }
60
+ */
61
+ export default function cssVarsParser<T extends Record<string, any>>(theme: T, options?: {
62
+ prefix?: string;
63
+ basePrefix?: string;
64
+ shouldSkipGeneratingVar?: (objectPathKeys: Array<string>, value: string | number) => boolean;
65
+ }): {
66
+ css: NestedRecord<string>;
67
+ vars: NestedRecord<string>;
68
+ parsedTheme: T;
69
+ };
70
+ export {};
@@ -24,16 +24,18 @@ exports.walkObjectDeep = void 0;
24
24
  * assignNestedKeys(source, ['palette', 'secondary'], 'var(--palette-secondary)')
25
25
  * console.log(source) // { palette: { primary: 'var(--palette-primary)', secondary: 'var(--palette-secondary)' } }
26
26
  */
27
- const assignNestedKeys = (obj, keys, value) => {
27
+ const assignNestedKeys = (obj, keys, value, arrayKeys = []) => {
28
28
  let temp = obj;
29
29
  keys.forEach((k, index) => {
30
30
  if (index === keys.length - 1) {
31
- if (temp && typeof temp === 'object') {
31
+ if (Array.isArray(temp)) {
32
+ temp[Number(k)] = value;
33
+ } else if (temp && typeof temp === 'object') {
32
34
  temp[k] = value;
33
35
  }
34
36
  } else if (temp && typeof temp === 'object') {
35
37
  if (!temp[k]) {
36
- temp[k] = {};
38
+ temp[k] = arrayKeys.includes(k) ? [] : {};
37
39
  }
38
40
 
39
41
  temp = temp[k];
@@ -56,14 +58,14 @@ const assignNestedKeys = (obj, keys, value) => {
56
58
  exports.assignNestedKeys = assignNestedKeys;
57
59
 
58
60
  const walkObjectDeep = (obj, callback, shouldSkipPaths) => {
59
- function recurse(object, parentKeys = []) {
61
+ function recurse(object, parentKeys = [], arrayKeys = []) {
60
62
  Object.entries(object).forEach(([key, value]) => {
61
63
  if (!shouldSkipPaths || shouldSkipPaths && !shouldSkipPaths([...parentKeys, key])) {
62
64
  if (value !== undefined && value !== null) {
63
65
  if (typeof value === 'object' && Object.keys(value).length > 0) {
64
- recurse(value, [...parentKeys, key]);
66
+ recurse(value, [...parentKeys, key], Array.isArray(value) ? [...arrayKeys, key] : arrayKeys);
65
67
  } else {
66
- callback([...parentKeys, key], value, object);
68
+ callback([...parentKeys, key], value, arrayKeys);
67
69
  }
68
70
  }
69
71
  }
@@ -132,7 +134,7 @@ function cssVarsParser(theme, options) {
132
134
  const css = {};
133
135
  const vars = {};
134
136
  const parsedTheme = {};
135
- walkObjectDeep(theme, (keys, value) => {
137
+ walkObjectDeep(theme, (keys, value, arrayKeys) => {
136
138
  if (typeof value === 'string' || typeof value === 'number') {
137
139
  if (typeof value === 'string' && value.match(/var\(\s*--/)) {
138
140
  // for CSS variable, apply prefix or remove basePrefix from the variable
@@ -150,11 +152,11 @@ function cssVarsParser(theme, options) {
150
152
  Object.assign(css, {
151
153
  [cssVar]: getCssValue(keys, value)
152
154
  });
153
- assignNestedKeys(vars, keys, `var(${cssVar})`);
155
+ assignNestedKeys(vars, keys, `var(${cssVar})`, arrayKeys);
154
156
  }
155
157
  }
156
158
 
157
- assignNestedKeys(parsedTheme, keys, value);
159
+ assignNestedKeys(parsedTheme, keys, value, arrayKeys);
158
160
  }, keys => keys[0] === 'vars' // skip 'vars/*' paths
159
161
  );
160
162
  return {