@mui/system 5.11.16 → 5.12.1

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 (91) hide show
  1. package/CHANGELOG.md +147 -22
  2. package/Container/Container.d.ts +13 -13
  3. package/Container/ContainerProps.d.ts +40 -40
  4. package/Container/containerClasses.d.ts +22 -22
  5. package/Container/createContainer.d.ts +18 -18
  6. package/GlobalStyles/GlobalStyles.d.ts +13 -0
  7. package/GlobalStyles/GlobalStyles.js +45 -0
  8. package/GlobalStyles/index.d.ts +2 -0
  9. package/GlobalStyles/index.js +26 -0
  10. package/GlobalStyles/package.json +6 -0
  11. package/Stack/Stack.d.ts +14 -13
  12. package/Stack/Stack.js +2 -1
  13. package/Stack/StackProps.d.ts +53 -53
  14. package/Stack/createStack.d.ts +21 -21
  15. package/Stack/index.d.ts +5 -5
  16. package/Stack/stackClasses.d.ts +8 -8
  17. package/ThemeProvider/ThemeProvider.d.ts +4 -0
  18. package/ThemeProvider/ThemeProvider.js +43 -17
  19. package/Unstable_Grid/Grid.d.ts +12 -12
  20. package/Unstable_Grid/GridProps.d.ts +185 -173
  21. package/Unstable_Grid/createGrid.d.ts +11 -11
  22. package/Unstable_Grid/createGrid.js +18 -11
  23. package/Unstable_Grid/gridClasses.d.ts +20 -20
  24. package/Unstable_Grid/gridGenerator.d.ts +38 -38
  25. package/Unstable_Grid/gridGenerator.js +12 -12
  26. package/Unstable_Grid/index.d.ts +5 -5
  27. package/createBox.d.ts +1 -0
  28. package/createBox.js +2 -1
  29. package/createStyled.d.ts +1 -0
  30. package/createStyled.js +37 -24
  31. package/createTheme/createSpacing.d.ts +10 -10
  32. package/cssVars/createCssVarsProvider.d.ts +22 -7
  33. package/cssVars/createCssVarsProvider.js +7 -3
  34. package/cssVars/createCssVarsTheme.d.ts +15 -13
  35. package/cssVars/createGetCssVar.d.ts +5 -5
  36. package/cssVars/cssVarsParser.d.ts +64 -64
  37. package/cssVars/getInitColorSchemeScript.d.ts +42 -42
  38. package/cssVars/index.d.ts +5 -5
  39. package/cssVars/prepareCssVars.d.ts +16 -14
  40. package/cssVars/prepareCssVars.js +6 -2
  41. package/cssVars/useCurrentColorScheme.d.ts +53 -53
  42. package/esm/GlobalStyles/GlobalStyles.js +35 -0
  43. package/esm/GlobalStyles/index.js +2 -0
  44. package/esm/Stack/Stack.js +2 -1
  45. package/esm/ThemeProvider/ThemeProvider.js +44 -18
  46. package/esm/Unstable_Grid/createGrid.js +19 -12
  47. package/esm/Unstable_Grid/gridGenerator.js +12 -12
  48. package/esm/createBox.js +2 -1
  49. package/esm/createStyled.js +37 -24
  50. package/esm/cssVars/createCssVarsProvider.js +7 -3
  51. package/esm/cssVars/prepareCssVars.js +6 -2
  52. package/esm/index.js +2 -1
  53. package/esm/useThemeProps/useThemeProps.js +6 -2
  54. package/esm/useThemeWithoutDefault.js +3 -2
  55. package/index.d.ts +2 -2
  56. package/index.js +4 -3
  57. package/legacy/GlobalStyles/GlobalStyles.js +35 -0
  58. package/legacy/GlobalStyles/index.js +2 -0
  59. package/legacy/Stack/Stack.js +2 -1
  60. package/legacy/ThemeProvider/ThemeProvider.js +44 -19
  61. package/legacy/Unstable_Grid/createGrid.js +19 -11
  62. package/legacy/Unstable_Grid/gridGenerator.js +12 -12
  63. package/legacy/createBox.js +3 -2
  64. package/legacy/createStyled.js +37 -17
  65. package/legacy/cssVars/createCssVarsProvider.js +18 -14
  66. package/legacy/cssVars/prepareCssVars.js +6 -2
  67. package/legacy/index.js +3 -2
  68. package/legacy/useThemeProps/useThemeProps.js +5 -1
  69. package/legacy/useThemeWithoutDefault.js +3 -2
  70. package/modern/GlobalStyles/GlobalStyles.js +35 -0
  71. package/modern/GlobalStyles/index.js +2 -0
  72. package/modern/Stack/Stack.js +2 -1
  73. package/modern/ThemeProvider/ThemeProvider.js +44 -18
  74. package/modern/Unstable_Grid/createGrid.js +18 -12
  75. package/modern/Unstable_Grid/gridGenerator.js +12 -12
  76. package/modern/createBox.js +2 -1
  77. package/modern/createStyled.js +37 -24
  78. package/modern/cssVars/createCssVarsProvider.js +7 -3
  79. package/modern/cssVars/prepareCssVars.js +6 -2
  80. package/modern/index.js +3 -2
  81. package/modern/useThemeProps/useThemeProps.js +6 -2
  82. package/modern/useThemeWithoutDefault.js +3 -2
  83. package/package.json +5 -5
  84. package/useThemeProps/useThemeProps.d.ts +6 -1
  85. package/useThemeProps/useThemeProps.js +6 -2
  86. package/useThemeWithoutDefault.js +5 -2
  87. package/Box/Box.spec.d.ts +0 -1
  88. package/createBox.spec.d.ts +0 -1
  89. package/cssVars/createCssVarsProvider.spec.d.ts +0 -1
  90. package/index.spec.d.ts +0 -1
  91. package/styleFunctionSx/styleFunctionSx.spec.d.ts +0 -1
@@ -13,26 +13,26 @@ function appendLevel(level) {
13
13
  return `Level${level}`;
14
14
  }
15
15
  function isNestedContainer(ownerState) {
16
- return ownerState.level > 0 && ownerState.container;
16
+ return ownerState.unstable_level > 0 && ownerState.container;
17
17
  }
18
18
  function createGetSelfSpacing(ownerState) {
19
19
  return function getSelfSpacing(axis) {
20
- return `var(--Grid-${axis}Spacing${appendLevel(ownerState.level)})`;
20
+ return `var(--Grid-${axis}Spacing${appendLevel(ownerState.unstable_level)})`;
21
21
  };
22
22
  }
23
23
  function createGetParentSpacing(ownerState) {
24
24
  return function getParentSpacing(axis) {
25
- if (ownerState.level === 0) {
25
+ if (ownerState.unstable_level === 0) {
26
26
  return `var(--Grid-${axis}Spacing)`;
27
27
  }
28
- return `var(--Grid-${axis}Spacing${appendLevel(ownerState.level - 1)})`;
28
+ return `var(--Grid-${axis}Spacing${appendLevel(ownerState.unstable_level - 1)})`;
29
29
  };
30
30
  }
31
31
  function getParentColumns(ownerState) {
32
- if (ownerState.level === 0) {
32
+ if (ownerState.unstable_level === 0) {
33
33
  return `var(--Grid-columns)`;
34
34
  }
35
- return `var(--Grid-columns${appendLevel(ownerState.level - 1)})`;
35
+ return `var(--Grid-columns${appendLevel(ownerState.unstable_level - 1)})`;
36
36
  }
37
37
  const filterBreakpointKeys = (breakpointsKeys, responsiveKeys) => breakpointsKeys.filter(key => responsiveKeys.includes(key));
38
38
  exports.filterBreakpointKeys = filterBreakpointKeys;
@@ -144,13 +144,13 @@ const generateGridColumnsStyles = ({
144
144
  return {};
145
145
  }
146
146
  const styles = isNestedContainer(ownerState) ? {
147
- [`--Grid-columns${appendLevel(ownerState.level)}`]: getParentColumns(ownerState)
147
+ [`--Grid-columns${appendLevel(ownerState.unstable_level)}`]: getParentColumns(ownerState)
148
148
  } : {
149
149
  '--Grid-columns': 12
150
150
  };
151
151
  traverseBreakpoints(theme.breakpoints, ownerState.columns, (appendStyle, value) => {
152
152
  appendStyle(styles, {
153
- [`--Grid-columns${appendLevel(ownerState.level)}`]: value
153
+ [`--Grid-columns${appendLevel(ownerState.unstable_level)}`]: value
154
154
  });
155
155
  });
156
156
  return styles;
@@ -167,12 +167,12 @@ const generateGridRowSpacingStyles = ({
167
167
  const styles = isNestedContainer(ownerState) ? {
168
168
  // Set the default spacing as its parent spacing.
169
169
  // It will be overridden if spacing props are provided
170
- [`--Grid-rowSpacing${appendLevel(ownerState.level)}`]: getParentSpacing('row')
170
+ [`--Grid-rowSpacing${appendLevel(ownerState.unstable_level)}`]: getParentSpacing('row')
171
171
  } : {};
172
172
  traverseBreakpoints(theme.breakpoints, ownerState.rowSpacing, (appendStyle, value) => {
173
173
  var _theme$spacing;
174
174
  appendStyle(styles, {
175
- [`--Grid-rowSpacing${appendLevel(ownerState.level)}`]: typeof value === 'string' ? value : (_theme$spacing = theme.spacing) == null ? void 0 : _theme$spacing.call(theme, value)
175
+ [`--Grid-rowSpacing${appendLevel(ownerState.unstable_level)}`]: typeof value === 'string' ? value : (_theme$spacing = theme.spacing) == null ? void 0 : _theme$spacing.call(theme, value)
176
176
  });
177
177
  });
178
178
  return styles;
@@ -189,12 +189,12 @@ const generateGridColumnSpacingStyles = ({
189
189
  const styles = isNestedContainer(ownerState) ? {
190
190
  // Set the default spacing as its parent spacing.
191
191
  // It will be overridden if spacing props are provided
192
- [`--Grid-columnSpacing${appendLevel(ownerState.level)}`]: getParentSpacing('column')
192
+ [`--Grid-columnSpacing${appendLevel(ownerState.unstable_level)}`]: getParentSpacing('column')
193
193
  } : {};
194
194
  traverseBreakpoints(theme.breakpoints, ownerState.columnSpacing, (appendStyle, value) => {
195
195
  var _theme$spacing2;
196
196
  appendStyle(styles, {
197
- [`--Grid-columnSpacing${appendLevel(ownerState.level)}`]: typeof value === 'string' ? value : (_theme$spacing2 = theme.spacing) == null ? void 0 : _theme$spacing2.call(theme, value)
197
+ [`--Grid-columnSpacing${appendLevel(ownerState.unstable_level)}`]: typeof value === 'string' ? value : (_theme$spacing2 = theme.spacing) == null ? void 0 : _theme$spacing2.call(theme, value)
198
198
  });
199
199
  });
200
200
  return styles;
@@ -1,5 +1,5 @@
1
- export { default } from './Grid';
2
- export { default as createGrid } from './createGrid';
3
- export * from './GridProps';
4
- export { default as gridClasses } from './gridClasses';
5
- export * from './gridClasses';
1
+ export { default } from './Grid';
2
+ export { default as createGrid } from './createGrid';
3
+ export * from './GridProps';
4
+ export { default as gridClasses } from './gridClasses';
5
+ export * from './gridClasses';
package/createBox.d.ts CHANGED
@@ -6,6 +6,7 @@ export default function createBox<
6
6
  T extends object = SystemTheme,
7
7
  AdditionalProps extends Record<string, unknown> = {},
8
8
  >(options?: {
9
+ themeId?: string;
9
10
  defaultTheme: T;
10
11
  defaultClassName?: string;
11
12
  generateClassName?: (componentName: string) => string;
package/createBox.js CHANGED
@@ -18,6 +18,7 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
18
18
  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; }
19
19
  function createBox(options = {}) {
20
20
  const {
21
+ themeId,
21
22
  defaultTheme,
22
23
  defaultClassName = 'MuiBox-root',
23
24
  generateClassName
@@ -37,7 +38,7 @@ function createBox(options = {}) {
37
38
  as: component,
38
39
  ref: ref,
39
40
  className: (0, _clsx.default)(className, generateClassName ? generateClassName(defaultClassName) : defaultClassName),
40
- theme: theme
41
+ theme: themeId ? theme[themeId] || theme : theme
41
42
  }, other));
42
43
  });
43
44
  return Box;
package/createStyled.d.ts CHANGED
@@ -31,6 +31,7 @@ export type CreateMUIStyled<T extends object = DefaultTheme> = CreateMUIStyledSt
31
31
  >;
32
32
 
33
33
  export default function createStyled<T extends object = DefaultTheme>(options?: {
34
+ themeId?: string;
34
35
  defaultTheme?: T;
35
36
  rootShouldForwardProp?: (prop: PropertyKey) => boolean;
36
37
  slotShouldForwardProp?: (prop: PropertyKey) => boolean;
package/createStyled.js CHANGED
@@ -14,9 +14,7 @@ var _utils = require("@mui/utils");
14
14
  var _createTheme = _interopRequireDefault(require("./createTheme"));
15
15
  var _propsToClassKey = _interopRequireDefault(require("./propsToClassKey"));
16
16
  var _styleFunctionSx = _interopRequireDefault(require("./styleFunctionSx"));
17
- const _excluded = ["name", "slot", "skipVariantsResolver", "skipSx", "overridesResolver"],
18
- _excluded2 = ["theme"],
19
- _excluded3 = ["theme"];
17
+ const _excluded = ["name", "slot", "skipVariantsResolver", "skipSx", "overridesResolver"];
20
18
  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); }
21
19
  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; }
22
20
  function isEmpty(obj) {
@@ -81,16 +79,26 @@ exports.systemDefaultTheme = systemDefaultTheme;
81
79
  const lowercaseFirstLetter = string => {
82
80
  return string.charAt(0).toLowerCase() + string.slice(1);
83
81
  };
82
+ function resolveTheme({
83
+ defaultTheme,
84
+ theme,
85
+ themeId
86
+ }) {
87
+ return isEmpty(theme) ? defaultTheme : theme[themeId] || theme;
88
+ }
84
89
  function createStyled(input = {}) {
85
90
  const {
91
+ themeId,
86
92
  defaultTheme = systemDefaultTheme,
87
93
  rootShouldForwardProp = shouldForwardProp,
88
94
  slotShouldForwardProp = shouldForwardProp
89
95
  } = input;
90
96
  const systemSx = props => {
91
- const theme = isEmpty(props.theme) ? defaultTheme : props.theme;
92
97
  return (0, _styleFunctionSx.default)((0, _extends2.default)({}, props, {
93
- theme
98
+ theme: resolveTheme((0, _extends2.default)({}, props, {
99
+ defaultTheme,
100
+ themeId
101
+ }))
94
102
  }));
95
103
  };
96
104
  systemSx.__mui_systemSx = true;
@@ -134,20 +142,22 @@ function createStyled(input = {}) {
134
142
  // On the server Emotion doesn't use React.forwardRef for creating components, so the created
135
143
  // component stays as a function. This condition makes sure that we do not interpolate functions
136
144
  // which are basically components used as a selectors.
137
- return typeof stylesArg === 'function' && stylesArg.__emotion_real !== stylesArg ? _ref => {
138
- let {
139
- theme: themeInput
140
- } = _ref,
141
- other = (0, _objectWithoutPropertiesLoose2.default)(_ref, _excluded2);
142
- return stylesArg((0, _extends2.default)({
143
- theme: isEmpty(themeInput) ? defaultTheme : themeInput
144
- }, other));
145
+ return typeof stylesArg === 'function' && stylesArg.__emotion_real !== stylesArg ? props => {
146
+ return stylesArg((0, _extends2.default)({}, props, {
147
+ theme: resolveTheme((0, _extends2.default)({}, props, {
148
+ defaultTheme,
149
+ themeId
150
+ }))
151
+ }));
145
152
  } : stylesArg;
146
153
  }) : [];
147
154
  let transformedStyleArg = styleArg;
148
155
  if (componentName && overridesResolver) {
149
156
  expressionsWithDefaultTheme.push(props => {
150
- const theme = isEmpty(props.theme) ? defaultTheme : props.theme;
157
+ const theme = resolveTheme((0, _extends2.default)({}, props, {
158
+ defaultTheme,
159
+ themeId
160
+ }));
151
161
  const styleOverrides = getStyleOverrides(componentName, theme);
152
162
  if (styleOverrides) {
153
163
  const resolvedStyleOverrides = {};
@@ -163,7 +173,10 @@ function createStyled(input = {}) {
163
173
  }
164
174
  if (componentName && !skipVariantsResolver) {
165
175
  expressionsWithDefaultTheme.push(props => {
166
- const theme = isEmpty(props.theme) ? defaultTheme : props.theme;
176
+ const theme = resolveTheme((0, _extends2.default)({}, props, {
177
+ defaultTheme,
178
+ themeId
179
+ }));
167
180
  return variantsResolver(props, getVariantStyles(componentName, theme), theme, componentName);
168
181
  });
169
182
  }
@@ -182,15 +195,12 @@ function createStyled(input = {}) {
182
195
  // which are basically components used as a selectors.
183
196
  styleArg.__emotion_real !== styleArg) {
184
197
  // If the type is function, we need to define the default theme.
185
- transformedStyleArg = _ref2 => {
186
- let {
187
- theme: themeInput
188
- } = _ref2,
189
- other = (0, _objectWithoutPropertiesLoose2.default)(_ref2, _excluded3);
190
- return styleArg((0, _extends2.default)({
191
- theme: isEmpty(themeInput) ? defaultTheme : themeInput
192
- }, other));
193
- };
198
+ transformedStyleArg = props => styleArg((0, _extends2.default)({}, props, {
199
+ theme: resolveTheme((0, _extends2.default)({}, props, {
200
+ defaultTheme,
201
+ themeId
202
+ }))
203
+ }));
194
204
  }
195
205
  const Component = defaultStyledResolver(transformedStyleArg, ...expressionsWithDefaultTheme);
196
206
  if (process.env.NODE_ENV !== 'production') {
@@ -203,6 +213,9 @@ function createStyled(input = {}) {
203
213
  }
204
214
  Component.displayName = displayName;
205
215
  }
216
+ if (tag.muiName) {
217
+ Component.muiName = tag.muiName;
218
+ }
206
219
  return Component;
207
220
  };
208
221
  if (defaultStyledResolver.withConfig) {
@@ -1,10 +1,10 @@
1
- export type SpacingOptions = number | Spacing | ((abs: number) => number | string) | ((abs: number | string) => number | string) | ReadonlyArray<string | number>;
2
- export 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 type SpacingOptions = number | Spacing | ((abs: number) => number | string) | ((abs: number | string) => number | string) | ReadonlyArray<string | number>;
2
+ export 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;
@@ -41,14 +41,22 @@ export interface CssVarsProviderConfig<ColorScheme extends string> {
41
41
  disableTransitionOnChange?: boolean;
42
42
  }
43
43
 
44
- export interface CreateCssVarsProviderResult<ColorScheme extends string> {
44
+ type Identify<I extends string | undefined, T> = I extends string ? T | { [k in I]: T } : T;
45
+
46
+ export interface CreateCssVarsProviderResult<
47
+ ColorScheme extends string,
48
+ Identifier extends string | undefined = undefined,
49
+ > {
45
50
  CssVarsProvider: (
46
51
  props: React.PropsWithChildren<
47
52
  Partial<CssVarsProviderConfig<ColorScheme>> & {
48
- theme?: {
49
- cssVarPrefix?: string;
50
- colorSchemes: Record<ColorScheme, Record<string, any>>;
51
- };
53
+ theme?: Identify<
54
+ Identifier,
55
+ {
56
+ cssVarPrefix?: string;
57
+ colorSchemes: Record<ColorScheme, Record<string, any>>;
58
+ }
59
+ >;
52
60
  /**
53
61
  * The document used to perform `disableTransitionOnChange` feature
54
62
  * @default document
@@ -87,8 +95,15 @@ export interface CreateCssVarsProviderResult<ColorScheme extends string> {
87
95
  getInitColorSchemeScript: typeof getInitColorSchemeScript;
88
96
  }
89
97
 
90
- export default function createCssVarsProvider<ColorScheme extends string>(
98
+ export default function createCssVarsProvider<
99
+ ColorScheme extends string,
100
+ Identifier extends string | undefined = undefined,
101
+ >(
91
102
  options: CssVarsProviderConfig<ColorScheme> & {
103
+ /**
104
+ * The design system's unique id for getting the corresponded theme when there are multiple design systems.
105
+ */
106
+ themeId?: Identifier;
92
107
  /**
93
108
  * Design system default theme
94
109
  *
@@ -136,7 +151,7 @@ export default function createCssVarsProvider<ColorScheme extends string>(
136
151
  */
137
152
  excludeVariablesFromRoot?: (cssVarPrefix: string) => string[];
138
153
  },
139
- ): CreateCssVarsProviderResult<ColorScheme>;
154
+ ): CreateCssVarsProviderResult<ColorScheme, Identifier>;
140
155
 
141
156
  // disable automatic export
142
157
  export {};
@@ -24,6 +24,7 @@ const DISABLE_CSS_TRANSITION = '*{-webkit-transition:none!important;-moz-transit
24
24
  exports.DISABLE_CSS_TRANSITION = DISABLE_CSS_TRANSITION;
25
25
  function createCssVarsProvider(options) {
26
26
  const {
27
+ themeId,
27
28
  theme: defaultTheme = {},
28
29
  attribute: defaultAttribute = _getInitColorSchemeScript.DEFAULT_ATTRIBUTE,
29
30
  modeStorageKey: defaultModeStorageKey = _getInitColorSchemeScript.DEFAULT_MODE_STORAGE_KEY,
@@ -65,7 +66,9 @@ function createCssVarsProvider(options) {
65
66
  const upperTheme = (0, _privateTheming.useTheme)();
66
67
  const ctx = React.useContext(ColorSchemeContext);
67
68
  const nested = !!ctx && !disableNestedContext;
68
- const {
69
+ const scopedTheme = themeProp[themeId];
70
+ const _ref = scopedTheme || themeProp,
71
+ {
69
72
  colorSchemes = {},
70
73
  components = {},
71
74
  generateCssVars = () => ({
@@ -73,8 +76,8 @@ function createCssVarsProvider(options) {
73
76
  css: {}
74
77
  }),
75
78
  cssVarPrefix
76
- } = themeProp,
77
- restThemeProp = (0, _objectWithoutPropertiesLoose2.default)(themeProp, _excluded);
79
+ } = _ref,
80
+ restThemeProp = (0, _objectWithoutPropertiesLoose2.default)(_ref, _excluded);
78
81
  const allColorSchemes = Object.keys(colorSchemes);
79
82
  const defaultLightColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.light;
80
83
  const defaultDarkColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.dark;
@@ -250,6 +253,7 @@ function createCssVarsProvider(options) {
250
253
  styles: otherColorSchemesStyleSheet
251
254
  })]
252
255
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ThemeProvider.default, {
256
+ themeId: scopedTheme ? themeId : undefined,
253
257
  theme: resolveTheme ? resolveTheme(theme) : theme,
254
258
  children: children
255
259
  })]
@@ -1,13 +1,15 @@
1
- import { DefaultCssVarsTheme } from './prepareCssVars';
2
- interface Theme extends DefaultCssVarsTheme {
3
- cssVarPrefix?: string;
4
- shouldSkipGeneratingVar?: (objectPathKeys: Array<string>, value: string | number) => boolean;
5
- }
6
- declare function createCssVarsTheme<T extends Theme, ThemeVars extends Record<string, any>>(theme: T): T & {
7
- vars: ThemeVars;
8
- generateCssVars: (colorScheme?: string | undefined) => {
9
- css: Record<string, string | number>;
10
- vars: ThemeVars;
11
- };
12
- };
13
- export default createCssVarsTheme;
1
+ import { DefaultCssVarsTheme } from './prepareCssVars';
2
+ interface Theme extends DefaultCssVarsTheme {
3
+ cssVarPrefix?: string;
4
+ shouldSkipGeneratingVar?: (objectPathKeys: Array<string>, value: string | number) => boolean;
5
+ }
6
+ declare function createCssVarsTheme<T extends Theme, ThemeVars extends Record<string, any>>(theme: T): T & {
7
+ vars: ThemeVars;
8
+ generateCssVars: (colorScheme?: string | undefined) => {
9
+ css: {
10
+ [x: string]: string | number;
11
+ };
12
+ vars: ThemeVars;
13
+ };
14
+ };
15
+ export default createCssVarsTheme;
@@ -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, ...fallbacks: (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, ...fallbacks: (T | AdditionalVars)[]) => string;
@@ -1,64 +1,64 @@
1
- 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: <T extends string | Record<string, any> | null | undefined = NestedRecord<any>, Value = any>(obj: T, 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
- * shouldSkipGeneratingVar?: (objectPathKeys: Array<string>, value: string | number) => boolean
41
- * }} options.
42
- * `prefix`: The prefix of the generated CSS variables. This function does not change the value.
43
- *
44
- * @returns {{ css: Object, vars: Object }} `css` is the stylesheet, `vars` is an object to get css variable (same structure as theme).
45
- *
46
- * @example
47
- * const { css, vars } = parser({
48
- * fontSize: 12,
49
- * lineHeight: 1.2,
50
- * palette: { primary: { 500: 'var(--color)' } }
51
- * }, { prefix: 'foo' })
52
- *
53
- * console.log(css) // { '--foo-fontSize': '12px', '--foo-lineHeight': 1.2, '--foo-palette-primary-500': 'var(--color)' }
54
- * console.log(vars) // { fontSize: 'var(--foo-fontSize)', lineHeight: 'var(--foo-lineHeight)', palette: { primary: { 500: 'var(--foo-palette-primary-500)' } } }
55
- */
56
- export default function cssVarsParser<T extends Record<string, any>>(theme: Record<string, any>, options?: {
57
- prefix?: string;
58
- shouldSkipGeneratingVar?: (objectPathKeys: Array<string>, value: string | number) => boolean;
59
- }): {
60
- css: Record<string, string | number>;
61
- vars: T;
62
- varsWithDefaults: {};
63
- };
64
- export {};
1
+ 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: <T extends string | Record<string, any> | null | undefined = NestedRecord<any>, Value = any>(obj: T, 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
+ * shouldSkipGeneratingVar?: (objectPathKeys: Array<string>, value: string | number) => boolean
41
+ * }} options.
42
+ * `prefix`: The prefix of the generated CSS variables. This function does not change the value.
43
+ *
44
+ * @returns {{ css: Object, vars: Object }} `css` is the stylesheet, `vars` is an object to get css variable (same structure as theme).
45
+ *
46
+ * @example
47
+ * const { css, vars } = parser({
48
+ * fontSize: 12,
49
+ * lineHeight: 1.2,
50
+ * palette: { primary: { 500: 'var(--color)' } }
51
+ * }, { prefix: 'foo' })
52
+ *
53
+ * console.log(css) // { '--foo-fontSize': '12px', '--foo-lineHeight': 1.2, '--foo-palette-primary-500': 'var(--color)' }
54
+ * console.log(vars) // { fontSize: 'var(--foo-fontSize)', lineHeight: 'var(--foo-lineHeight)', palette: { primary: { 500: 'var(--foo-palette-primary-500)' } } }
55
+ */
56
+ export default function cssVarsParser<T extends Record<string, any>>(theme: Record<string, any>, options?: {
57
+ prefix?: string;
58
+ shouldSkipGeneratingVar?: (objectPathKeys: Array<string>, value: string | number) => boolean;
59
+ }): {
60
+ css: Record<string, string | number>;
61
+ vars: T;
62
+ varsWithDefaults: {};
63
+ };
64
+ export {};
@@ -1,42 +1,42 @@
1
- /// <reference types="react" />
2
- export declare const DEFAULT_MODE_STORAGE_KEY = "mode";
3
- export declare const DEFAULT_COLOR_SCHEME_STORAGE_KEY = "color-scheme";
4
- export declare const DEFAULT_ATTRIBUTE = "data-color-scheme";
5
- export interface GetInitColorSchemeScriptOptions {
6
- /**
7
- * The mode to be used for the first visit
8
- * @default 'light'
9
- */
10
- defaultMode?: 'light' | 'dark' | 'system';
11
- /**
12
- * The default color scheme to be used on the light mode
13
- * @default 'light'
14
- */
15
- defaultLightColorScheme?: string;
16
- /**
17
- * The default color scheme to be used on the dark mode
18
- * * @default 'dark'
19
- */
20
- defaultDarkColorScheme?: string;
21
- /**
22
- * The node (provided as string) used to attach the color-scheme attribute
23
- * @default 'document.documentElement'
24
- */
25
- colorSchemeNode?: string;
26
- /**
27
- * localStorage key used to store `mode`
28
- * @default 'mode'
29
- */
30
- modeStorageKey?: string;
31
- /**
32
- * localStorage key used to store `colorScheme`
33
- * @default 'color-scheme'
34
- */
35
- colorSchemeStorageKey?: string;
36
- /**
37
- * DOM attribute for applying color scheme
38
- * @default 'data-color-scheme'
39
- */
40
- attribute?: string;
41
- }
42
- export default function getInitColorSchemeScript(options?: GetInitColorSchemeScriptOptions): JSX.Element;
1
+ /// <reference types="react" />
2
+ export declare const DEFAULT_MODE_STORAGE_KEY = "mode";
3
+ export declare const DEFAULT_COLOR_SCHEME_STORAGE_KEY = "color-scheme";
4
+ export declare const DEFAULT_ATTRIBUTE = "data-color-scheme";
5
+ export interface GetInitColorSchemeScriptOptions {
6
+ /**
7
+ * The mode to be used for the first visit
8
+ * @default 'light'
9
+ */
10
+ defaultMode?: 'light' | 'dark' | 'system';
11
+ /**
12
+ * The default color scheme to be used on the light mode
13
+ * @default 'light'
14
+ */
15
+ defaultLightColorScheme?: string;
16
+ /**
17
+ * The default color scheme to be used on the dark mode
18
+ * * @default 'dark'
19
+ */
20
+ defaultDarkColorScheme?: string;
21
+ /**
22
+ * The node (provided as string) used to attach the color-scheme attribute
23
+ * @default 'document.documentElement'
24
+ */
25
+ colorSchemeNode?: string;
26
+ /**
27
+ * localStorage key used to store `mode`
28
+ * @default 'mode'
29
+ */
30
+ modeStorageKey?: string;
31
+ /**
32
+ * localStorage key used to store `colorScheme`
33
+ * @default 'color-scheme'
34
+ */
35
+ colorSchemeStorageKey?: string;
36
+ /**
37
+ * DOM attribute for applying color scheme
38
+ * @default 'data-color-scheme'
39
+ */
40
+ attribute?: string;
41
+ }
42
+ export default function getInitColorSchemeScript(options?: GetInitColorSchemeScriptOptions): JSX.Element;
@@ -1,5 +1,5 @@
1
- export { default } from './createCssVarsProvider';
2
- export type { CreateCssVarsProviderResult, CssVarsProviderConfig, ColorSchemeContextValue, } from './createCssVarsProvider';
3
- export { default as getInitColorSchemeScript } from './getInitColorSchemeScript';
4
- export { default as prepareCssVars } from './prepareCssVars';
5
- export { default as createCssVarsTheme } from './createCssVarsTheme';
1
+ export { default } from './createCssVarsProvider';
2
+ export type { CreateCssVarsProviderResult, CssVarsProviderConfig, ColorSchemeContextValue, } from './createCssVarsProvider';
3
+ export { default as getInitColorSchemeScript } from './getInitColorSchemeScript';
4
+ export { default as prepareCssVars } from './prepareCssVars';
5
+ export { default as createCssVarsTheme } from './createCssVarsTheme';