@mui/system 5.6.4 → 5.8.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.
- package/Box/Box.spec.d.ts +1 -1
- package/CHANGELOG.md +241 -0
- package/Container/Container.d.ts +13 -0
- package/Container/Container.js +81 -0
- package/Container/ContainerProps.d.ts +40 -0
- package/Container/ContainerProps.js +5 -0
- package/Container/containerClasses.d.ts +22 -0
- package/Container/containerClasses.js +17 -0
- package/Container/createContainer.d.ts +18 -0
- package/Container/createContainer.js +172 -0
- package/Container/index.d.ts +5 -0
- package/Container/index.js +42 -0
- package/Container/package.json +6 -0
- package/ThemeProvider/ThemeProvider.d.ts +1 -1
- package/createBox.spec.d.ts +1 -1
- package/createTheme/createBreakpoints.d.ts +5 -0
- package/createTheme/createSpacing.d.ts +10 -10
- package/cssVars/createCssVarsProvider.d.ts +25 -0
- package/cssVars/createCssVarsProvider.js +59 -23
- package/cssVars/createCssVarsProvider.spec.d.ts +1 -1
- package/cssVars/createGetCssVar.d.ts +5 -5
- package/cssVars/cssVarsParser.d.ts +70 -70
- package/cssVars/getInitColorSchemeScript.d.ts +40 -12
- package/cssVars/getInitColorSchemeScript.js +4 -3
- package/cssVars/index.d.ts +2 -2
- package/cssVars/useCurrentColorScheme.d.ts +53 -50
- package/cssVars/useCurrentColorScheme.js +17 -7
- package/esm/Container/Container.js +70 -0
- package/esm/Container/ContainerProps.js +1 -0
- package/esm/Container/containerClasses.js +6 -0
- package/esm/Container/createContainer.js +151 -0
- package/esm/Container/index.js +3 -0
- package/esm/cssVars/createCssVarsProvider.js +60 -24
- package/esm/cssVars/getInitColorSchemeScript.js +4 -3
- package/esm/cssVars/useCurrentColorScheme.js +17 -7
- package/esm/index.js +4 -1
- package/esm/spacing.js +1 -1
- package/esm/style.js +2 -2
- package/index.d.ts +6 -0
- package/index.js +32 -2
- package/index.spec.d.ts +1 -1
- package/legacy/Container/Container.js +70 -0
- package/legacy/Container/ContainerProps.js +1 -0
- package/legacy/Container/containerClasses.js +6 -0
- package/legacy/Container/createContainer.js +148 -0
- package/legacy/Container/index.js +3 -0
- package/legacy/cssVars/createCssVarsProvider.js +66 -26
- package/legacy/cssVars/getInitColorSchemeScript.js +6 -3
- package/legacy/cssVars/useCurrentColorScheme.js +20 -9
- package/legacy/index.js +5 -2
- package/legacy/spacing.js +1 -1
- package/legacy/style.js +3 -1
- package/modern/Container/Container.js +70 -0
- package/modern/Container/ContainerProps.js +1 -0
- package/modern/Container/containerClasses.js +6 -0
- package/modern/Container/createContainer.js +151 -0
- package/modern/Container/index.js +3 -0
- package/modern/cssVars/createCssVarsProvider.js +60 -24
- package/modern/cssVars/getInitColorSchemeScript.js +4 -3
- package/modern/cssVars/useCurrentColorScheme.js +17 -7
- package/modern/index.js +5 -2
- package/modern/spacing.js +1 -1
- package/modern/style.js +2 -2
- package/package.json +5 -5
- package/spacing.js +1 -1
- package/style.js +2 -2
- 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; }
|
|
@@ -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>,
|
package/createBox.spec.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
|
@@ -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;
|
|
@@ -74,11 +74,16 @@ function createCssVarsProvider(options) {
|
|
|
74
74
|
theme: themeProp = defaultTheme,
|
|
75
75
|
prefix = designSystemPrefix,
|
|
76
76
|
modeStorageKey = _getInitColorSchemeScript.DEFAULT_MODE_STORAGE_KEY,
|
|
77
|
+
colorSchemeStorageKey = _getInitColorSchemeScript.DEFAULT_COLOR_SCHEME_STORAGE_KEY,
|
|
77
78
|
attribute = _getInitColorSchemeScript.DEFAULT_ATTRIBUTE,
|
|
78
79
|
defaultMode = desisgnSystemMode,
|
|
79
80
|
defaultColorScheme = designSystemColorScheme,
|
|
80
81
|
disableTransitionOnChange = designSystemTransitionOnChange,
|
|
81
|
-
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'
|
|
82
87
|
}) {
|
|
83
88
|
const hasMounted = React.useRef(false);
|
|
84
89
|
const {
|
|
@@ -102,7 +107,9 @@ function createCssVarsProvider(options) {
|
|
|
102
107
|
defaultLightColorScheme,
|
|
103
108
|
defaultDarkColorScheme,
|
|
104
109
|
modeStorageKey,
|
|
105
|
-
|
|
110
|
+
colorSchemeStorageKey,
|
|
111
|
+
defaultMode,
|
|
112
|
+
storageWindow
|
|
106
113
|
});
|
|
107
114
|
|
|
108
115
|
const resolvedColorScheme = (() => {
|
|
@@ -136,7 +143,8 @@ function createCssVarsProvider(options) {
|
|
|
136
143
|
vars: rootVars,
|
|
137
144
|
getCssVar: (0, _createGetCssVar.default)(prefix)
|
|
138
145
|
});
|
|
139
|
-
const
|
|
146
|
+
const defaultColorSchemeStyleSheet = {};
|
|
147
|
+
const otherColorSchemesStyleSheet = {};
|
|
140
148
|
Object.entries(colorSchemes).forEach(([key, scheme]) => {
|
|
141
149
|
const {
|
|
142
150
|
css,
|
|
@@ -172,54 +180,54 @@ function createCssVarsProvider(options) {
|
|
|
172
180
|
})();
|
|
173
181
|
|
|
174
182
|
if (key === resolvedDefaultColorScheme) {
|
|
175
|
-
|
|
183
|
+
defaultColorSchemeStyleSheet[colorSchemeSelector] = css;
|
|
176
184
|
} else {
|
|
177
|
-
|
|
185
|
+
otherColorSchemesStyleSheet[`${colorSchemeSelector === ':root' ? '' : colorSchemeSelector}[${attribute}="${key}"]`] = css;
|
|
178
186
|
}
|
|
179
187
|
});
|
|
180
188
|
React.useEffect(() => {
|
|
181
|
-
if (colorScheme) {
|
|
189
|
+
if (colorScheme && colorSchemeNode) {
|
|
182
190
|
// attaches attribute to <html> because the css variables are attached to :root (html)
|
|
183
|
-
|
|
191
|
+
colorSchemeNode.setAttribute(attribute, colorScheme);
|
|
184
192
|
}
|
|
185
|
-
}, [colorScheme, attribute]);
|
|
193
|
+
}, [colorScheme, attribute, colorSchemeNode]);
|
|
186
194
|
(0, _utils.unstable_useEnhancedEffect)(() => {
|
|
187
|
-
if (!mode || !enableColorScheme) {
|
|
195
|
+
if (!mode || !enableColorScheme || !colorSchemeNode) {
|
|
188
196
|
return undefined;
|
|
189
197
|
}
|
|
190
198
|
|
|
191
|
-
const priorColorScheme =
|
|
199
|
+
const priorColorScheme = colorSchemeNode.style.getPropertyValue('color-scheme'); // `color-scheme` tells browser to render built-in elements according to its value: `light` or `dark`
|
|
192
200
|
|
|
193
201
|
if (mode === 'system') {
|
|
194
|
-
|
|
202
|
+
colorSchemeNode.style.setProperty('color-scheme', systemMode);
|
|
195
203
|
} else {
|
|
196
|
-
|
|
204
|
+
colorSchemeNode.style.setProperty('color-scheme', mode);
|
|
197
205
|
}
|
|
198
206
|
|
|
199
207
|
return () => {
|
|
200
|
-
|
|
208
|
+
colorSchemeNode.style.setProperty('color-scheme', priorColorScheme);
|
|
201
209
|
};
|
|
202
|
-
}, [mode, systemMode, enableColorScheme]);
|
|
210
|
+
}, [mode, systemMode, enableColorScheme, colorSchemeNode]);
|
|
203
211
|
React.useEffect(() => {
|
|
204
212
|
let timer;
|
|
205
213
|
|
|
206
|
-
if (disableTransitionOnChange && hasMounted.current) {
|
|
214
|
+
if (disableTransitionOnChange && hasMounted.current && documentNode) {
|
|
207
215
|
// credit: https://github.com/pacocoursey/next-themes/blob/b5c2bad50de2d61ad7b52a9c5cdc801a78507d7a/index.tsx#L313
|
|
208
|
-
const css =
|
|
209
|
-
css.appendChild(
|
|
210
|
-
|
|
216
|
+
const css = documentNode.createElement('style');
|
|
217
|
+
css.appendChild(documentNode.createTextNode(DISABLE_CSS_TRANSITION));
|
|
218
|
+
documentNode.head.appendChild(css); // Force browser repaint
|
|
211
219
|
|
|
212
|
-
(() => window.getComputedStyle(
|
|
220
|
+
(() => window.getComputedStyle(documentNode.body))();
|
|
213
221
|
|
|
214
222
|
timer = setTimeout(() => {
|
|
215
|
-
|
|
223
|
+
documentNode.head.removeChild(css);
|
|
216
224
|
}, 1);
|
|
217
225
|
}
|
|
218
226
|
|
|
219
227
|
return () => {
|
|
220
228
|
clearTimeout(timer);
|
|
221
229
|
};
|
|
222
|
-
}, [colorScheme, disableTransitionOnChange]);
|
|
230
|
+
}, [colorScheme, disableTransitionOnChange, documentNode]);
|
|
223
231
|
React.useEffect(() => {
|
|
224
232
|
hasMounted.current = true;
|
|
225
233
|
return () => {
|
|
@@ -238,10 +246,12 @@ function createCssVarsProvider(options) {
|
|
|
238
246
|
},
|
|
239
247
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_styledEngine.GlobalStyles, {
|
|
240
248
|
styles: {
|
|
241
|
-
|
|
249
|
+
[colorSchemeSelector]: rootCss
|
|
242
250
|
}
|
|
243
251
|
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_styledEngine.GlobalStyles, {
|
|
244
|
-
styles:
|
|
252
|
+
styles: defaultColorSchemeStyleSheet
|
|
253
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_styledEngine.GlobalStyles, {
|
|
254
|
+
styles: otherColorSchemesStyleSheet
|
|
245
255
|
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ThemeProvider.default, {
|
|
246
256
|
theme: resolveTheme ? resolveTheme(theme) : theme,
|
|
247
257
|
children: children
|
|
@@ -260,6 +270,21 @@ function createCssVarsProvider(options) {
|
|
|
260
270
|
*/
|
|
261
271
|
children: _propTypes.default.node,
|
|
262
272
|
|
|
273
|
+
/**
|
|
274
|
+
* The node used to attach the color-scheme attribute
|
|
275
|
+
*/
|
|
276
|
+
colorSchemeNode: _propTypes.default.any,
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* The CSS selector for attaching the generated custom properties
|
|
280
|
+
*/
|
|
281
|
+
colorSchemeSelector: _propTypes.default.string,
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* localStorage key used to store `colorScheme`
|
|
285
|
+
*/
|
|
286
|
+
colorSchemeStorageKey: _propTypes.default.string,
|
|
287
|
+
|
|
263
288
|
/**
|
|
264
289
|
* The initial color scheme used.
|
|
265
290
|
*/
|
|
@@ -275,6 +300,11 @@ function createCssVarsProvider(options) {
|
|
|
275
300
|
*/
|
|
276
301
|
disableTransitionOnChange: _propTypes.default.bool,
|
|
277
302
|
|
|
303
|
+
/**
|
|
304
|
+
* The document to attach the attribute to
|
|
305
|
+
*/
|
|
306
|
+
documentNode: _propTypes.default.any,
|
|
307
|
+
|
|
278
308
|
/**
|
|
279
309
|
* Indicate to the browser which color scheme is used (light or dark) for rendering built-in UI
|
|
280
310
|
*/
|
|
@@ -290,6 +320,12 @@ function createCssVarsProvider(options) {
|
|
|
290
320
|
*/
|
|
291
321
|
prefix: _propTypes.default.string,
|
|
292
322
|
|
|
323
|
+
/**
|
|
324
|
+
* The window that attaches the 'storage' event listener
|
|
325
|
+
* @default window
|
|
326
|
+
*/
|
|
327
|
+
storageWindow: _propTypes.default.any,
|
|
328
|
+
|
|
293
329
|
/**
|
|
294
330
|
* The calculated theme object that will be passed through context.
|
|
295
331
|
*/
|
|
@@ -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, 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 {};
|
|
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 {};
|
|
@@ -1,12 +1,40 @@
|
|
|
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
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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 interface GetInitColorSchemeScriptOptions {
|
|
6
|
+
/**
|
|
7
|
+
* If `true`, the initial color scheme is set to the user's prefers-color-scheme mode
|
|
8
|
+
* @default false
|
|
9
|
+
*/
|
|
10
|
+
enableSystem?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* The default color scheme to be used on the light mode
|
|
13
|
+
*/
|
|
14
|
+
defaultLightColorScheme?: string;
|
|
15
|
+
/**
|
|
16
|
+
* The default color scheme to be used on the dark mode
|
|
17
|
+
*/
|
|
18
|
+
defaultDarkColorScheme?: string;
|
|
19
|
+
/**
|
|
20
|
+
* The node (provided as string) used to attach the color-scheme attribute
|
|
21
|
+
* @default 'document.documentElement'
|
|
22
|
+
*/
|
|
23
|
+
colorSchemeNode?: string;
|
|
24
|
+
/**
|
|
25
|
+
* localStorage key used to store `mode`
|
|
26
|
+
* @default 'mui-mode'
|
|
27
|
+
*/
|
|
28
|
+
modeStorageKey?: string;
|
|
29
|
+
/**
|
|
30
|
+
* localStorage key used to store `colorScheme`
|
|
31
|
+
* @default 'mui-color-scheme'
|
|
32
|
+
*/
|
|
33
|
+
colorSchemeStorageKey?: string;
|
|
34
|
+
/**
|
|
35
|
+
* DOM attribute for applying color scheme
|
|
36
|
+
* @default 'data-mui-color-scheme'
|
|
37
|
+
*/
|
|
38
|
+
attribute?: string;
|
|
39
|
+
}
|
|
40
|
+
export default function getInitColorSchemeScript(options?: GetInitColorSchemeScriptOptions): JSX.Element;
|
|
@@ -23,12 +23,13 @@ exports.DEFAULT_ATTRIBUTE = DEFAULT_ATTRIBUTE;
|
|
|
23
23
|
|
|
24
24
|
function getInitColorSchemeScript(options) {
|
|
25
25
|
const {
|
|
26
|
-
enableSystem,
|
|
26
|
+
enableSystem = false,
|
|
27
27
|
defaultLightColorScheme = 'light',
|
|
28
28
|
defaultDarkColorScheme = 'dark',
|
|
29
29
|
modeStorageKey = DEFAULT_MODE_STORAGE_KEY,
|
|
30
30
|
colorSchemeStorageKey = DEFAULT_COLOR_SCHEME_STORAGE_KEY,
|
|
31
|
-
attribute = DEFAULT_ATTRIBUTE
|
|
31
|
+
attribute = DEFAULT_ATTRIBUTE,
|
|
32
|
+
colorSchemeNode = 'document.documentElement'
|
|
32
33
|
} = options || {};
|
|
33
34
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("script", {
|
|
34
35
|
// eslint-disable-next-line react/no-danger
|
|
@@ -52,7 +53,7 @@ function getInitColorSchemeScript(options) {
|
|
|
52
53
|
colorScheme = localStorage.getItem('${colorSchemeStorageKey}-dark') || '${defaultDarkColorScheme}';
|
|
53
54
|
}
|
|
54
55
|
if (colorScheme) {
|
|
55
|
-
|
|
56
|
+
${colorSchemeNode}.setAttribute('${attribute}', colorScheme);
|
|
56
57
|
}
|
|
57
58
|
} catch (e) {} })();`
|
|
58
59
|
}
|
package/cssVars/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { default } from './createCssVarsProvider';
|
|
2
|
-
export type { CreateCssVarsProviderResult } from './createCssVarsProvider';
|
|
1
|
+
export { default } from './createCssVarsProvider';
|
|
2
|
+
export type { CreateCssVarsProviderResult } from './createCssVarsProvider';
|
|
@@ -1,50 +1,53 @@
|
|
|
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
|
-
|
|
44
|
-
defaultLightColorScheme: SupportedColorScheme;
|
|
45
|
-
defaultDarkColorScheme: SupportedColorScheme;
|
|
46
|
-
supportedColorSchemes: Array<SupportedColorScheme>;
|
|
47
|
-
defaultMode?: Mode;
|
|
48
|
-
modeStorageKey?: string;
|
|
49
|
-
colorSchemeStorageKey?: string;
|
|
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
|
+
interface UseCurrentColoSchemeOptions<SupportedColorScheme extends string> {
|
|
44
|
+
defaultLightColorScheme: SupportedColorScheme;
|
|
45
|
+
defaultDarkColorScheme: SupportedColorScheme;
|
|
46
|
+
supportedColorSchemes: Array<SupportedColorScheme>;
|
|
47
|
+
defaultMode?: Mode;
|
|
48
|
+
modeStorageKey?: string;
|
|
49
|
+
colorSchemeStorageKey?: string;
|
|
50
|
+
storageWindow?: Window | null;
|
|
51
|
+
}
|
|
52
|
+
export default function useCurrentColorScheme<SupportedColorScheme extends string>(options: UseCurrentColoSchemeOptions<SupportedColorScheme>): Result<SupportedColorScheme>;
|
|
53
|
+
export {};
|