@mui/system 5.3.0 → 5.4.3

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 (61) hide show
  1. package/Box/Box.d.ts +1 -1
  2. package/Box/Box.spec.d.ts +1 -1
  3. package/CHANGELOG.md +347 -28
  4. package/ThemeProvider/ThemeProvider.d.ts +1 -1
  5. package/createBox.d.ts +2 -0
  6. package/createBox.js +3 -2
  7. package/createBox.spec.d.ts +1 -1
  8. package/createStyled.d.ts +2 -1
  9. package/createStyled.js +7 -5
  10. package/createTheme/createBreakpoints.js +21 -6
  11. package/createTheme/createSpacing.d.ts +10 -10
  12. package/cssVars/createCssVarsProvider.d.ts +34 -94
  13. package/cssVars/createCssVarsProvider.js +4 -2
  14. package/cssVars/createCssVarsProvider.spec.d.ts +1 -1
  15. package/cssVars/createGetCssVar.d.ts +5 -5
  16. package/cssVars/createGetCssVar.js +7 -1
  17. package/cssVars/cssVarsParser.d.ts +68 -68
  18. package/cssVars/cssVarsParser.js +4 -3
  19. package/cssVars/getInitColorSchemeScript.d.ts +12 -12
  20. package/cssVars/index.d.ts +1 -2
  21. package/cssVars/useCurrentColorScheme.d.ts +50 -50
  22. package/esm/createBox.js +3 -2
  23. package/esm/createStyled.js +5 -3
  24. package/esm/createTheme/createBreakpoints.js +20 -4
  25. package/esm/cssVars/createCssVarsProvider.js +4 -2
  26. package/esm/cssVars/createGetCssVar.js +7 -1
  27. package/esm/cssVars/cssVarsParser.js +4 -3
  28. package/esm/getThemeValue.js +1 -1
  29. package/esm/index.js +1 -1
  30. package/esm/styleFunctionSx/index.js +1 -0
  31. package/esm/styleFunctionSx/styleFunctionSx.js +78 -51
  32. package/getThemeValue.js +2 -1
  33. package/index.d.ts +1 -0
  34. package/index.js +8 -1
  35. package/index.spec.d.ts +1 -1
  36. package/legacy/createBox.js +4 -2
  37. package/legacy/createStyled.js +6 -3
  38. package/legacy/createTheme/createBreakpoints.js +23 -4
  39. package/legacy/cssVars/createCssVarsProvider.js +4 -2
  40. package/legacy/cssVars/createGetCssVar.js +7 -1
  41. package/legacy/cssVars/cssVarsParser.js +4 -3
  42. package/legacy/getThemeValue.js +1 -1
  43. package/legacy/index.js +2 -2
  44. package/legacy/styleFunctionSx/index.js +1 -0
  45. package/legacy/styleFunctionSx/styleFunctionSx.js +76 -51
  46. package/modern/createBox.js +3 -2
  47. package/modern/createStyled.js +5 -3
  48. package/modern/createTheme/createBreakpoints.js +20 -4
  49. package/modern/cssVars/createCssVarsProvider.js +4 -2
  50. package/modern/cssVars/createGetCssVar.js +7 -1
  51. package/modern/cssVars/cssVarsParser.js +4 -3
  52. package/modern/getThemeValue.js +1 -1
  53. package/modern/index.js +2 -2
  54. package/modern/styleFunctionSx/index.js +1 -0
  55. package/modern/styleFunctionSx/styleFunctionSx.js +78 -51
  56. package/package.json +8 -8
  57. package/style.d.ts +1 -1
  58. package/styleFunctionSx/index.js +12 -2
  59. package/styleFunctionSx/styleFunctionSx.d.ts +12 -1
  60. package/styleFunctionSx/styleFunctionSx.js +79 -54
  61. package/styleFunctionSx/styleFunctionSx.spec.d.ts +1 -1
package/createStyled.js CHANGED
@@ -19,10 +19,10 @@ var _utils = require("@mui/utils");
19
19
 
20
20
  var _createTheme = _interopRequireDefault(require("./createTheme"));
21
21
 
22
- var _styleFunctionSx = _interopRequireDefault(require("./styleFunctionSx"));
23
-
24
22
  var _propsToClassKey = _interopRequireDefault(require("./propsToClassKey"));
25
23
 
24
+ var _styleFunctionSx = _interopRequireDefault(require("./styleFunctionSx"));
25
+
26
26
  const _excluded = ["name", "slot", "skipVariantsResolver", "skipSx", "overridesResolver"],
27
27
  _excluded2 = ["theme"],
28
28
  _excluded3 = ["theme"];
@@ -79,7 +79,8 @@ const variantsResolver = (props, styles, theme, name) => {
79
79
  }
80
80
 
81
81
  return variantsStyles;
82
- };
82
+ }; // Update /system/styled/#api in case if this changes
83
+
83
84
 
84
85
  function shouldForwardProp(prop) {
85
86
  return prop !== 'ownerState' && prop !== 'theme' && prop !== 'sx' && prop !== 'as';
@@ -96,7 +97,8 @@ function createStyled(input = {}) {
96
97
  const {
97
98
  defaultTheme = systemDefaultTheme,
98
99
  rootShouldForwardProp = shouldForwardProp,
99
- slotShouldForwardProp = shouldForwardProp
100
+ slotShouldForwardProp = shouldForwardProp,
101
+ styleFunctionSx = _styleFunctionSx.default
100
102
  } = input;
101
103
  return (tag, inputOptions = {}) => {
102
104
  const {
@@ -177,7 +179,7 @@ function createStyled(input = {}) {
177
179
  if (!skipSx) {
178
180
  expressionsWithDefaultTheme.push(props => {
179
181
  const theme = isEmpty(props.theme) ? defaultTheme : props.theme;
180
- return (0, _styleFunctionSx.default)((0, _extends2.default)({}, props, {
182
+ return styleFunctionSx((0, _extends2.default)({}, props, {
181
183
  theme
182
184
  }));
183
185
  });
@@ -8,17 +8,31 @@ Object.defineProperty(exports, "__esModule", {
8
8
  exports.breakpointKeys = void 0;
9
9
  exports.default = createBreakpoints;
10
10
 
11
- var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
12
-
13
11
  var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
14
12
 
13
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
14
+
15
15
  const _excluded = ["values", "unit", "step"];
16
16
  // Sorted ASC by size. That's important.
17
17
  // It can't be configured as it's used statically for propTypes.
18
- const breakpointKeys = ['xs', 'sm', 'md', 'lg', 'xl']; // Keep in mind that @media is inclusive by the CSS specification.
19
-
18
+ const breakpointKeys = ['xs', 'sm', 'md', 'lg', 'xl'];
20
19
  exports.breakpointKeys = breakpointKeys;
21
20
 
21
+ const sortBreakpointsValues = values => {
22
+ const breakpointsAsArray = Object.keys(values).map(key => ({
23
+ key,
24
+ val: values[key]
25
+ })) || []; // Sort in ascending order
26
+
27
+ breakpointsAsArray.sort((breakpoint1, breakpoint2) => breakpoint1.val - breakpoint2.val);
28
+ return breakpointsAsArray.reduce((acc, obj) => {
29
+ return (0, _extends2.default)({}, acc, {
30
+ [obj.key]: obj.val
31
+ });
32
+ }, {});
33
+ }; // Keep in mind that @media is inclusive by the CSS specification.
34
+
35
+
22
36
  function createBreakpoints(breakpoints) {
23
37
  const {
24
38
  // The breakpoint **start** at this value.
@@ -39,7 +53,8 @@ function createBreakpoints(breakpoints) {
39
53
  step = 5
40
54
  } = breakpoints,
41
55
  other = (0, _objectWithoutPropertiesLoose2.default)(breakpoints, _excluded);
42
- const keys = Object.keys(values);
56
+ const sortedValues = sortBreakpointsValues(values);
57
+ const keys = Object.keys(sortedValues);
43
58
 
44
59
  function up(key) {
45
60
  const value = typeof values[key] === 'number' ? values[key] : key;
@@ -81,7 +96,7 @@ function createBreakpoints(breakpoints) {
81
96
 
82
97
  return (0, _extends2.default)({
83
98
  keys,
84
- values,
99
+ values: sortedValues,
85
100
  up,
86
101
  down,
87
102
  between,
@@ -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;
@@ -2,73 +2,16 @@ import * as React from 'react';
2
2
  import getInitColorSchemeScript from './getInitColorSchemeScript';
3
3
  import { Mode, Result } from './useCurrentColorScheme';
4
4
 
5
- export type BuildCssVarsTheme<ThemeInput> = ThemeInput extends {
6
- colorSchemes: Record<string, infer ColorSystems>;
7
- }
8
- ? Omit<ThemeInput, 'colorSchemes'> &
9
- ColorSystems & { vars: Omit<ThemeInput, 'colorSchemes'> & ColorSystems }
10
- : never;
11
-
12
- /**
13
- * DesignSystemColorScheme: is what a design system provide by default. Mostly, `light` and `dark`
14
- * ApplicationColorScheme: is what developer can extend from a design system. Ex, `comfort` `trueDark` ...any name that they want
15
- *
16
- * This type enhance customization experience by checking if developer has extended the colorScheme or not (usually via module augmentation)
17
- * If yes, they must provide the palette of the extended colorScheme. Otherwise `theme` is optional.
18
- */
19
- type DecideTheme<
20
- DesignSystemTheme extends { colorSchemes: Record<DesignSystemColorScheme, any> },
21
- DesignSystemColorScheme extends string,
22
- ApplicationTheme extends { colorSchemes: Record<ApplicationColorScheme, any> },
23
- ApplicationColorScheme extends string | never,
24
- > = [ApplicationColorScheme] extends [never]
25
- ? {
26
- theme?: Omit<DesignSystemTheme, 'colorSchemes'> & {
27
- colorSchemes?: Partial<
28
- Record<
29
- DesignSystemColorScheme,
30
- DesignSystemTheme['colorSchemes'][DesignSystemColorScheme]
31
- >
32
- >;
33
- };
34
- }
35
- : {
36
- theme: Omit<ApplicationTheme, 'colorSchemes'> & {
37
- colorSchemes: Partial<
38
- Record<
39
- DesignSystemColorScheme,
40
- DesignSystemTheme['colorSchemes'][DesignSystemColorScheme]
41
- >
42
- > &
43
- Record<ApplicationColorScheme, ApplicationTheme['colorSchemes'][ApplicationColorScheme]>;
44
- };
45
- };
46
-
47
5
  export interface ColorSchemeContextValue<SupportedColorScheme extends string>
48
6
  extends Result<SupportedColorScheme> {
49
7
  allColorSchemes: SupportedColorScheme[];
50
8
  }
51
9
 
52
- export default function createCssVarsProvider<
53
- DesignSystemThemeInput extends {
54
- colorSchemes: Record<DesignSystemColorScheme, any>;
55
- },
56
- DesignSystemColorScheme extends string,
57
- ApplicationThemeInput extends {
58
- colorSchemes: Record<ApplicationColorScheme, any>;
59
- } = never,
60
- ApplicationColorScheme extends string = never,
61
- >(options: {
62
- /**
63
- * Design system default theme
64
- */
65
- theme: DesignSystemThemeInput;
10
+ export interface CssVarsProviderConfig<ColorScheme extends string> {
66
11
  /**
67
12
  * Design system default color scheme
68
13
  */
69
- defaultColorScheme:
70
- | DesignSystemColorScheme
71
- | { light: DesignSystemColorScheme; dark: DesignSystemColorScheme };
14
+ defaultColorScheme: ColorScheme | { light: ColorScheme; dark: ColorScheme };
72
15
  /**
73
16
  * Design system default mode
74
17
  * @default 'light'
@@ -89,32 +32,38 @@ export default function createCssVarsProvider<
89
32
  * @default ''
90
33
  */
91
34
  prefix?: string;
92
- /**
93
- * A function to determine if the key, value should be attached as CSS Variable
94
- * `keys` is an array that represents the object path keys.
95
- * Ex, if the theme is { foo: { bar: 'var(--test)' } }
96
- * then, keys = ['foo', 'bar']
97
- * value = 'var(--test)'
98
- */
99
- shouldSkipGeneratingVar?: (keys: string[], value: string | number) => boolean;
100
- }): {
35
+ }
36
+
37
+ export default function createCssVarsProvider<
38
+ ColorScheme extends string,
39
+ ThemeInput extends { colorSchemes?: Partial<Record<ColorScheme, any>> },
40
+ >(
41
+ options: CssVarsProviderConfig<ColorScheme> & {
42
+ /**
43
+ * Design system default theme
44
+ */
45
+ theme: any;
46
+ /**
47
+ * A function to determine if the key, value should be attached as CSS Variable
48
+ * `keys` is an array that represents the object path keys.
49
+ * Ex, if the theme is { foo: { bar: 'var(--test)' } }
50
+ * then, keys = ['foo', 'bar']
51
+ * value = 'var(--test)'
52
+ */
53
+ shouldSkipGeneratingVar?: (keys: string[], value: string | number) => boolean;
54
+ /**
55
+ * A function to be called after the CSS variables are attached. The result of this function will be the final theme pass to ThemeProvider.
56
+ *
57
+ * The example usage is the variant generation in Joy. We need to combine the token from user-input and the default theme first, then generate
58
+ * variants from those tokens.
59
+ */
60
+ resolveTheme?: (theme: any) => any; // the type is any because it depends on the design system.
61
+ },
62
+ ): {
101
63
  CssVarsProvider: (
102
64
  props: React.PropsWithChildren<
103
- {
104
- /**
105
- * Application default mode (overrides design system `defaultMode` if specified)
106
- */
107
- defaultMode?: Mode;
108
- /**
109
- * Application default colorScheme (overrides design system `defaultColorScheme` if specified)
110
- */
111
- defaultColorScheme?:
112
- | DesignSystemColorScheme
113
- | ApplicationColorScheme
114
- | {
115
- light: DesignSystemColorScheme | ApplicationColorScheme;
116
- dark: DesignSystemColorScheme | ApplicationColorScheme;
117
- };
65
+ Partial<CssVarsProviderConfig<ColorScheme>> & {
66
+ theme?: ThemeInput;
118
67
  /**
119
68
  * localStorage key used to store application `mode`
120
69
  * @default 'mui-mode'
@@ -125,19 +74,10 @@ export default function createCssVarsProvider<
125
74
  * @default 'data-mui-color-scheme'
126
75
  */
127
76
  attribute?: string;
128
- /**
129
- * CSS variable prefix (overrides design system `prefix` if specified)
130
- */
131
- prefix?: string;
132
- } & DecideTheme<
133
- DesignSystemThemeInput,
134
- DesignSystemColorScheme,
135
- ApplicationThemeInput,
136
- ApplicationColorScheme
137
- >
77
+ }
138
78
  >,
139
79
  ) => React.ReactElement;
140
- useColorScheme: () => ColorSchemeContextValue<DesignSystemColorScheme | ApplicationColorScheme>;
80
+ useColorScheme: () => ColorSchemeContextValue<ColorScheme>;
141
81
  getInitColorSchemeScript: typeof getInitColorSchemeScript;
142
82
  };
143
83
 
@@ -57,7 +57,8 @@ function createCssVarsProvider(options) {
57
57
  disableTransitionOnChange = false,
58
58
  enableColorScheme = true,
59
59
  prefix: designSystemPrefix = '',
60
- shouldSkipGeneratingVar
60
+ shouldSkipGeneratingVar,
61
+ resolveTheme
61
62
  } = options;
62
63
  const systemSpacing = (0, _createSpacing.default)(baseTheme.spacing);
63
64
  const systemBreakpoints = (0, _createBreakpoints.default)((_baseTheme$breakpoint = baseTheme.breakpoints) != null ? _baseTheme$breakpoint : {});
@@ -151,6 +152,7 @@ function createCssVarsProvider(options) {
151
152
  mergedTheme = (0, _extends2.default)({}, mergedTheme, colorSchemes[resolvedColorScheme], {
152
153
  components,
153
154
  colorSchemes,
155
+ prefix,
154
156
  vars: rootVars,
155
157
  spacing: themeProp.spacing ? (0, _createSpacing.default)(themeProp.spacing) : systemSpacing,
156
158
  breakpoints: themeProp.breakpoints ? (0, _createBreakpoints.default)(themeProp.breakpoints) : systemBreakpoints,
@@ -252,7 +254,7 @@ function createCssVarsProvider(options) {
252
254
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_styledEngine.GlobalStyles, {
253
255
  styles: styleSheet
254
256
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ThemeProvider.default, {
255
- theme: mergedTheme,
257
+ theme: resolveTheme ? resolveTheme(mergedTheme) : mergedTheme,
256
258
  children: children
257
259
  })]
258
260
  });
@@ -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;
@@ -15,7 +15,13 @@ function createGetCssVar(prefix = '') {
15
15
  return '';
16
16
  }
17
17
 
18
- return `, var(--${prefix ? `${prefix}-` : ''}${vars[0]}${appendVar(...vars.slice(1))})`;
18
+ const value = vars[0];
19
+
20
+ if (typeof value === 'string' && !value.match(/(#|\(|\)|(-?(\d*\.)?\d+)(px|em|%|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc))/)) {
21
+ return `, var(--${prefix ? `${prefix}-` : ''}${value}${appendVar(...vars.slice(1))})`;
22
+ }
23
+
24
+ return `, ${value}`;
19
25
  } // AdditionalVars makes `getCssVar` less strict, so it can be use like this `getCssVar('non-mui-variable')` without type error.
20
26
 
21
27
 
@@ -1,68 +1,68 @@
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
- * This function also mutate the string value of theme input by replacing `basePrefix` (if existed) with `prefix`
47
- *
48
- * @returns {{ css: Object, vars: Object }} `css` is the stylesheet, `vars` is an object to get css variable (same structure as theme)
49
- *
50
- * @example
51
- * const { css, vars } = parser({
52
- * fontSize: 12,
53
- * lineHeight: 1.2,
54
- * palette: { primary: { 500: '#000000' } }
55
- * })
56
- *
57
- * console.log(css) // { '--fontSize': '12px', '--lineHeight': 1.2, '--palette-primary-500': '#000000' }
58
- * console.log(vars) // { fontSize: '--fontSize', lineHeight: '--lineHeight', palette: { primary: { 500: 'var(--palette-primary-500)' } } }
59
- */
60
- export default function cssVarsParser(theme: Record<string, any>, options?: {
61
- prefix?: string;
62
- basePrefix?: string;
63
- shouldSkipGeneratingVar?: (objectPathKeys: Array<string>, value: string | number) => boolean;
64
- }): {
65
- css: NestedRecord<string>;
66
- vars: NestedRecord<string>;
67
- };
68
- 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) => 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
+ * This function also mutate the string value of theme input by replacing `basePrefix` (if existed) with `prefix`
47
+ *
48
+ * @returns {{ css: Object, vars: Object }} `css` is the stylesheet, `vars` is an object to get css variable (same structure as theme)
49
+ *
50
+ * @example
51
+ * const { css, vars } = parser({
52
+ * fontSize: 12,
53
+ * lineHeight: 1.2,
54
+ * palette: { primary: { 500: '#000000' } }
55
+ * })
56
+ *
57
+ * console.log(css) // { '--fontSize': '12px', '--lineHeight': 1.2, '--palette-primary-500': '#000000' }
58
+ * console.log(vars) // { fontSize: '--fontSize', lineHeight: '--lineHeight', palette: { primary: { 500: 'var(--palette-primary-500)' } } }
59
+ */
60
+ export default function cssVarsParser(theme: Record<string, any>, options?: {
61
+ prefix?: string;
62
+ basePrefix?: string;
63
+ shouldSkipGeneratingVar?: (objectPathKeys: Array<string>, value: string | number) => boolean;
64
+ }): {
65
+ css: NestedRecord<string>;
66
+ vars: NestedRecord<string>;
67
+ };
68
+ export {};
@@ -127,12 +127,13 @@ function cssVarsParser(theme, options) {
127
127
  if (typeof val === 'string' || typeof val === 'number') {
128
128
  let value = val;
129
129
 
130
- if (typeof value === 'string' && value.startsWith('var')) {
130
+ if (typeof value === 'string' && value.match(/var\(\s*--/)) {
131
131
  // replace the value of the `scope` object with the prefix or remove basePrefix from the value
132
132
  if (!basePrefix && prefix) {
133
- value = value.replace(/var\(--/g, `var(--${prefix}-`);
133
+ value = value.replace(/var\(\s*--/g, `var(--${prefix}-`);
134
134
  } else {
135
- value = prefix ? value.replace(new RegExp(basePrefix, 'g'), prefix) : value.replace(new RegExp(`${basePrefix}-`, 'g'), '');
135
+ value = prefix ? value.replace(new RegExp(`var\\(\\s*--${basePrefix}`, 'g'), `var(--${prefix}`) // removing spaces
136
+ : value.replace(new RegExp(`var\\(\\s*--${basePrefix}-`, 'g'), 'var(--');
136
137
  } // scope is the deepest object in the tree, keys is the theme path keys
137
138
 
138
139
 
@@ -1,12 +1,12 @@
1
- /// <reference types="react" />
2
- export declare const DEFAULT_MODE_STORAGE_KEY = "mui-mode";
3
- export declare const DEFAULT_COLOR_SCHEME_STORAGE_KEY = "mui-color-scheme";
4
- export declare const DEFAULT_ATTRIBUTE = "data-mui-color-scheme";
5
- export default function getInitColorSchemeScript(options?: {
6
- enableSystem?: boolean;
7
- defaultLightColorScheme?: string;
8
- defaultDarkColorScheme?: string;
9
- modeStorageKey?: string;
10
- colorSchemeStorageKey?: string;
11
- attribute?: string;
12
- }): JSX.Element;
1
+ /// <reference types="react" />
2
+ export declare const DEFAULT_MODE_STORAGE_KEY = "mui-mode";
3
+ export declare const DEFAULT_COLOR_SCHEME_STORAGE_KEY = "mui-color-scheme";
4
+ export declare const DEFAULT_ATTRIBUTE = "data-mui-color-scheme";
5
+ export default function getInitColorSchemeScript(options?: {
6
+ enableSystem?: boolean;
7
+ defaultLightColorScheme?: string;
8
+ defaultDarkColorScheme?: string;
9
+ modeStorageKey?: string;
10
+ colorSchemeStorageKey?: string;
11
+ attribute?: string;
12
+ }): JSX.Element;
@@ -1,2 +1 @@
1
- export { default } from './createCssVarsProvider';
2
- export type { BuildCssVarsTheme } from './createCssVarsProvider';
1
+ export { default } from './createCssVarsProvider';
@@ -1,50 +1,50 @@
1
- export declare type Mode = 'light' | 'dark' | 'system';
2
- export declare type SystemMode = Exclude<Mode, 'system'>;
3
- export interface State<SupportedColorScheme extends string> {
4
- /**
5
- * User selected mode.
6
- * Note: on the server, mode is always undefined
7
- */
8
- mode: Mode | undefined;
9
- /**
10
- * Only valid if `mode: 'system'`, either 'light' | 'dark'.
11
- */
12
- systemMode: SystemMode | undefined;
13
- /**
14
- * The color scheme for the light mode.
15
- */
16
- lightColorScheme: SupportedColorScheme;
17
- /**
18
- * The color scheme for the dark mode.
19
- */
20
- darkColorScheme: SupportedColorScheme;
21
- }
22
- export declare type Result<SupportedColorScheme extends string> = State<SupportedColorScheme> & {
23
- /**
24
- * The current application color scheme. It is always `undefined` on the server.
25
- */
26
- colorScheme: SupportedColorScheme | undefined;
27
- /**
28
- * `mode` is saved to internal state and localStorage
29
- * If `mode` is null, it will be reset to the defaultMode
30
- */
31
- setMode: (mode: Mode | null) => void;
32
- /**
33
- * `colorScheme` is saved to internal state and localStorage
34
- * If `colorScheme` is null, it will be reset to the defaultColorScheme (light | dark)
35
- */
36
- setColorScheme: (colorScheme: SupportedColorScheme | Partial<{
37
- light: SupportedColorScheme | null;
38
- dark: SupportedColorScheme | null;
39
- }> | null) => void;
40
- };
41
- export declare function getSystemMode(mode: undefined | string): SystemMode | undefined;
42
- export declare function getColorScheme<SupportedColorScheme extends string>(state: State<SupportedColorScheme>): SupportedColorScheme | undefined;
43
- export default function useCurrentColorScheme<SupportedColorScheme extends string>(options: {
44
- defaultLightColorScheme: SupportedColorScheme;
45
- defaultDarkColorScheme: SupportedColorScheme;
46
- supportedColorSchemes: Array<SupportedColorScheme>;
47
- defaultMode?: Mode;
48
- modeStorageKey?: string;
49
- colorSchemeStorageKey?: string;
50
- }): Result<SupportedColorScheme>;
1
+ export declare type Mode = 'light' | 'dark' | 'system';
2
+ export declare type SystemMode = Exclude<Mode, 'system'>;
3
+ export interface State<SupportedColorScheme extends string> {
4
+ /**
5
+ * User selected mode.
6
+ * Note: on the server, mode is always undefined
7
+ */
8
+ mode: Mode | undefined;
9
+ /**
10
+ * Only valid if `mode: 'system'`, either 'light' | 'dark'.
11
+ */
12
+ systemMode: SystemMode | undefined;
13
+ /**
14
+ * The color scheme for the light mode.
15
+ */
16
+ lightColorScheme: SupportedColorScheme;
17
+ /**
18
+ * The color scheme for the dark mode.
19
+ */
20
+ darkColorScheme: SupportedColorScheme;
21
+ }
22
+ export declare type Result<SupportedColorScheme extends string> = State<SupportedColorScheme> & {
23
+ /**
24
+ * The current application color scheme. It is always `undefined` on the server.
25
+ */
26
+ colorScheme: SupportedColorScheme | undefined;
27
+ /**
28
+ * `mode` is saved to internal state and localStorage
29
+ * If `mode` is null, it will be reset to the defaultMode
30
+ */
31
+ setMode: (mode: Mode | null) => void;
32
+ /**
33
+ * `colorScheme` is saved to internal state and localStorage
34
+ * If `colorScheme` is null, it will be reset to the defaultColorScheme (light | dark)
35
+ */
36
+ setColorScheme: (colorScheme: SupportedColorScheme | Partial<{
37
+ light: SupportedColorScheme | null;
38
+ dark: SupportedColorScheme | null;
39
+ }> | null) => void;
40
+ };
41
+ export declare function getSystemMode(mode: undefined | string): SystemMode | undefined;
42
+ export declare function getColorScheme<SupportedColorScheme extends string>(state: State<SupportedColorScheme>): SupportedColorScheme | undefined;
43
+ export default function useCurrentColorScheme<SupportedColorScheme extends string>(options: {
44
+ defaultLightColorScheme: SupportedColorScheme;
45
+ defaultDarkColorScheme: SupportedColorScheme;
46
+ supportedColorSchemes: Array<SupportedColorScheme>;
47
+ defaultMode?: Mode;
48
+ modeStorageKey?: string;
49
+ colorSchemeStorageKey?: string;
50
+ }): Result<SupportedColorScheme>;
package/esm/createBox.js CHANGED
@@ -5,14 +5,15 @@ import * as React from 'react';
5
5
  import PropTypes from 'prop-types';
6
6
  import clsx from 'clsx';
7
7
  import styled from '@mui/styled-engine';
8
- import styleFunctionSx, { extendSxProp } from './styleFunctionSx';
8
+ import defaultStyleFunctionSx, { extendSxProp } from './styleFunctionSx';
9
9
  import useTheme from './useTheme';
10
10
  import { jsx as _jsx } from "react/jsx-runtime";
11
11
  export default function createBox(options = {}) {
12
12
  const {
13
13
  defaultTheme,
14
14
  defaultClassName = 'MuiBox-root',
15
- generateClassName
15
+ generateClassName,
16
+ styleFunctionSx = defaultStyleFunctionSx
16
17
  } = options;
17
18
  const BoxRoot = styled('div')(styleFunctionSx);
18
19
  const Box = /*#__PURE__*/React.forwardRef(function Box(inProps, ref) {