@mui/system 5.6.1 → 5.6.4
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.d.ts +18 -1
- package/Box/Box.js +26 -0
- package/Box/Box.spec.d.ts +1 -1
- package/CHANGELOG.md +185 -2
- package/ThemeProvider/ThemeProvider.d.ts +6 -0
- package/ThemeProvider/ThemeProvider.js +9 -2
- package/createBox.js +0 -26
- package/createBox.spec.d.ts +1 -1
- package/createStyled.js +3 -1
- package/createTheme/createSpacing.d.ts +10 -10
- package/cssVars/createCssVarsProvider.js +20 -36
- package/cssVars/createCssVarsProvider.spec.d.ts +1 -1
- package/cssVars/createGetCssVar.d.ts +5 -5
- package/cssVars/cssVarsParser.d.ts +70 -70
- package/cssVars/cssVarsParser.js +11 -9
- package/cssVars/getInitColorSchemeScript.d.ts +12 -12
- package/cssVars/index.d.ts +2 -2
- package/cssVars/useCurrentColorScheme.d.ts +50 -50
- package/esm/Box/Box.js +25 -0
- package/esm/ThemeProvider/ThemeProvider.js +9 -2
- package/esm/createBox.js +0 -25
- package/esm/createStyled.js +3 -1
- package/esm/cssVars/createCssVarsProvider.js +21 -35
- package/esm/cssVars/cssVarsParser.js +11 -9
- package/esm/spacing.js +3 -1
- package/esm/style.js +16 -1
- package/index.d.ts +4 -0
- package/index.js +1 -1
- package/index.spec.d.ts +1 -1
- package/legacy/Box/Box.js +25 -0
- package/legacy/ThemeProvider/ThemeProvider.js +9 -2
- package/legacy/createBox.js +0 -25
- package/legacy/createStyled.js +3 -1
- package/legacy/cssVars/createCssVarsProvider.js +22 -31
- package/legacy/cssVars/cssVarsParser.js +11 -7
- package/legacy/index.js +1 -1
- package/legacy/spacing.js +3 -1
- package/legacy/style.js +16 -1
- package/modern/Box/Box.js +25 -0
- package/modern/ThemeProvider/ThemeProvider.js +9 -2
- package/modern/createBox.js +0 -25
- package/modern/createStyled.js +3 -1
- package/modern/cssVars/createCssVarsProvider.js +21 -33
- package/modern/cssVars/cssVarsParser.js +11 -9
- package/modern/index.js +1 -1
- package/modern/spacing.js +1 -1
- package/modern/style.js +16 -1
- package/package.json +2 -2
- package/spacing.js +3 -1
- package/style.js +16 -1
- package/styleFunctionSx/styleFunctionSx.d.ts +3 -1
- package/styleFunctionSx/styleFunctionSx.spec.d.ts +1 -1
|
@@ -1,70 +1,70 @@
|
|
|
1
|
-
declare type NestedRecord<V = any> = {
|
|
2
|
-
[k: string | number]: NestedRecord<V> | V;
|
|
3
|
-
};
|
|
4
|
-
/**
|
|
5
|
-
* This function create an object from keys, value and then assign to target
|
|
6
|
-
*
|
|
7
|
-
* @param {Object} obj : the target object to be assigned
|
|
8
|
-
* @param {string[]} keys
|
|
9
|
-
* @param {string | number} value
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* const source = {}
|
|
13
|
-
* assignNestedKeys(source, ['palette', 'primary'], 'var(--palette-primary)')
|
|
14
|
-
* console.log(source) // { palette: { primary: 'var(--palette-primary)' } }
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* const source = { palette: { primary: 'var(--palette-primary)' } }
|
|
18
|
-
* assignNestedKeys(source, ['palette', 'secondary'], 'var(--palette-secondary)')
|
|
19
|
-
* console.log(source) // { palette: { primary: 'var(--palette-primary)', secondary: 'var(--palette-secondary)' } }
|
|
20
|
-
*/
|
|
21
|
-
export declare const assignNestedKeys: <Object_1 = NestedRecord<any>, Value = any>(obj: Object_1, keys: Array<string>, value: Value) => void;
|
|
22
|
-
/**
|
|
23
|
-
*
|
|
24
|
-
* @param {Object} obj : source object
|
|
25
|
-
* @param {Function} callback : a function that will be called when
|
|
26
|
-
* - the deepest key in source object is reached
|
|
27
|
-
* - the value of the deepest key is NOT `undefined` | `null`
|
|
28
|
-
*
|
|
29
|
-
* @example
|
|
30
|
-
* walkObjectDeep({ palette: { primary: { main: '#000000' } } }, console.log)
|
|
31
|
-
* // ['palette', 'primary', 'main'] '#000000'
|
|
32
|
-
*/
|
|
33
|
-
export declare const walkObjectDeep: <Value, T = Record<string, any>>(obj: T, callback: (keys: Array<string>, value: Value,
|
|
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 {};
|
package/cssVars/cssVarsParser.js
CHANGED
|
@@ -24,16 +24,18 @@ exports.walkObjectDeep = void 0;
|
|
|
24
24
|
* assignNestedKeys(source, ['palette', 'secondary'], 'var(--palette-secondary)')
|
|
25
25
|
* console.log(source) // { palette: { primary: 'var(--palette-primary)', secondary: 'var(--palette-secondary)' } }
|
|
26
26
|
*/
|
|
27
|
-
const assignNestedKeys = (obj, keys, value) => {
|
|
27
|
+
const assignNestedKeys = (obj, keys, value, arrayKeys = []) => {
|
|
28
28
|
let temp = obj;
|
|
29
29
|
keys.forEach((k, index) => {
|
|
30
30
|
if (index === keys.length - 1) {
|
|
31
|
-
if (temp
|
|
31
|
+
if (Array.isArray(temp)) {
|
|
32
|
+
temp[Number(k)] = value;
|
|
33
|
+
} else if (temp && typeof temp === 'object') {
|
|
32
34
|
temp[k] = value;
|
|
33
35
|
}
|
|
34
36
|
} else if (temp && typeof temp === 'object') {
|
|
35
37
|
if (!temp[k]) {
|
|
36
|
-
temp[k] = {};
|
|
38
|
+
temp[k] = arrayKeys.includes(k) ? [] : {};
|
|
37
39
|
}
|
|
38
40
|
|
|
39
41
|
temp = temp[k];
|
|
@@ -56,14 +58,14 @@ const assignNestedKeys = (obj, keys, value) => {
|
|
|
56
58
|
exports.assignNestedKeys = assignNestedKeys;
|
|
57
59
|
|
|
58
60
|
const walkObjectDeep = (obj, callback, shouldSkipPaths) => {
|
|
59
|
-
function recurse(object, parentKeys = []) {
|
|
61
|
+
function recurse(object, parentKeys = [], arrayKeys = []) {
|
|
60
62
|
Object.entries(object).forEach(([key, value]) => {
|
|
61
63
|
if (!shouldSkipPaths || shouldSkipPaths && !shouldSkipPaths([...parentKeys, key])) {
|
|
62
64
|
if (value !== undefined && value !== null) {
|
|
63
65
|
if (typeof value === 'object' && Object.keys(value).length > 0) {
|
|
64
|
-
recurse(value, [...parentKeys, key]);
|
|
66
|
+
recurse(value, [...parentKeys, key], Array.isArray(value) ? [...arrayKeys, key] : arrayKeys);
|
|
65
67
|
} else {
|
|
66
|
-
callback([...parentKeys, key], value,
|
|
68
|
+
callback([...parentKeys, key], value, arrayKeys);
|
|
67
69
|
}
|
|
68
70
|
}
|
|
69
71
|
}
|
|
@@ -132,7 +134,7 @@ function cssVarsParser(theme, options) {
|
|
|
132
134
|
const css = {};
|
|
133
135
|
const vars = {};
|
|
134
136
|
const parsedTheme = {};
|
|
135
|
-
walkObjectDeep(theme, (keys, value) => {
|
|
137
|
+
walkObjectDeep(theme, (keys, value, arrayKeys) => {
|
|
136
138
|
if (typeof value === 'string' || typeof value === 'number') {
|
|
137
139
|
if (typeof value === 'string' && value.match(/var\(\s*--/)) {
|
|
138
140
|
// for CSS variable, apply prefix or remove basePrefix from the variable
|
|
@@ -150,11 +152,11 @@ function cssVarsParser(theme, options) {
|
|
|
150
152
|
Object.assign(css, {
|
|
151
153
|
[cssVar]: getCssValue(keys, value)
|
|
152
154
|
});
|
|
153
|
-
assignNestedKeys(vars, keys, `var(${cssVar})
|
|
155
|
+
assignNestedKeys(vars, keys, `var(${cssVar})`, arrayKeys);
|
|
154
156
|
}
|
|
155
157
|
}
|
|
156
158
|
|
|
157
|
-
assignNestedKeys(parsedTheme, keys, value);
|
|
159
|
+
assignNestedKeys(parsedTheme, keys, value, arrayKeys);
|
|
158
160
|
}, keys => keys[0] === 'vars' // skip 'vars/*' paths
|
|
159
161
|
);
|
|
160
162
|
return {
|
|
@@ -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;
|
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,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/Box/Box.js
CHANGED
|
@@ -1,3 +1,28 @@
|
|
|
1
|
+
import PropTypes from 'prop-types';
|
|
1
2
|
import createBox from '../createBox';
|
|
2
3
|
const Box = createBox();
|
|
4
|
+
process.env.NODE_ENV !== "production" ? Box.propTypes
|
|
5
|
+
/* remove-proptypes */
|
|
6
|
+
= {
|
|
7
|
+
// ----------------------------- Warning --------------------------------
|
|
8
|
+
// | These PropTypes are generated from the TypeScript type definitions |
|
|
9
|
+
// | To update them edit the d.ts file and run "yarn proptypes" |
|
|
10
|
+
// ----------------------------------------------------------------------
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @ignore
|
|
14
|
+
*/
|
|
15
|
+
children: PropTypes.node,
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The component used for the root node.
|
|
19
|
+
* Either a string to use a HTML element or a component.
|
|
20
|
+
*/
|
|
21
|
+
component: PropTypes.elementType,
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The system prop that allows defining system overrides as well as additional CSS styles.
|
|
25
|
+
*/
|
|
26
|
+
sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
|
|
27
|
+
} : void 0;
|
|
3
28
|
export default Box;
|
|
@@ -38,7 +38,14 @@ function ThemeProvider(props) {
|
|
|
38
38
|
});
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
process.env.NODE_ENV !== "production" ? ThemeProvider.propTypes
|
|
41
|
+
process.env.NODE_ENV !== "production" ? ThemeProvider.propTypes
|
|
42
|
+
/* remove-proptypes */
|
|
43
|
+
= {
|
|
44
|
+
// ----------------------------- Warning --------------------------------
|
|
45
|
+
// | These PropTypes are generated from the TypeScript type definitions |
|
|
46
|
+
// | To update them edit the d.ts file and run "yarn proptypes" |
|
|
47
|
+
// ----------------------------------------------------------------------
|
|
48
|
+
|
|
42
49
|
/**
|
|
43
50
|
* Your component tree.
|
|
44
51
|
*/
|
|
@@ -47,7 +54,7 @@ process.env.NODE_ENV !== "production" ? ThemeProvider.propTypes = {
|
|
|
47
54
|
/**
|
|
48
55
|
* A theme object. You can provide a function to extend the outer theme.
|
|
49
56
|
*/
|
|
50
|
-
theme: PropTypes.oneOfType([PropTypes.
|
|
57
|
+
theme: PropTypes.oneOfType([PropTypes.func, PropTypes.object]).isRequired
|
|
51
58
|
} : void 0;
|
|
52
59
|
|
|
53
60
|
if (process.env.NODE_ENV !== 'production') {
|
package/esm/createBox.js
CHANGED
|
@@ -2,7 +2,6 @@ import _extends from "@babel/runtime/helpers/esm/extends";
|
|
|
2
2
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
3
|
const _excluded = ["className", "component"];
|
|
4
4
|
import * as React from 'react';
|
|
5
|
-
import PropTypes from 'prop-types';
|
|
6
5
|
import clsx from 'clsx';
|
|
7
6
|
import styled from '@mui/styled-engine';
|
|
8
7
|
import defaultStyleFunctionSx, { extendSxProp } from './styleFunctionSx';
|
|
@@ -33,29 +32,5 @@ export default function createBox(options = {}) {
|
|
|
33
32
|
theme: theme
|
|
34
33
|
}, other));
|
|
35
34
|
});
|
|
36
|
-
process.env.NODE_ENV !== "production" ? Box.propTypes
|
|
37
|
-
/* remove-proptypes */
|
|
38
|
-
= {
|
|
39
|
-
// ----------------------------- Warning --------------------------------
|
|
40
|
-
// | These PropTypes are generated from the TypeScript type definitions |
|
|
41
|
-
// | To update them edit the d.ts file and run "yarn proptypes" |
|
|
42
|
-
// ----------------------------------------------------------------------
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* @ignore
|
|
46
|
-
*/
|
|
47
|
-
children: PropTypes.node,
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* The component used for the root node.
|
|
51
|
-
* Either a string to use a HTML element or a component.
|
|
52
|
-
*/
|
|
53
|
-
component: PropTypes.elementType,
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* @ignore
|
|
57
|
-
*/
|
|
58
|
-
sx: PropTypes.oneOfType([PropTypes.object, PropTypes.array, PropTypes.func])
|
|
59
|
-
} : void 0;
|
|
60
35
|
return Box;
|
|
61
36
|
}
|
package/esm/createStyled.js
CHANGED
|
@@ -142,7 +142,9 @@ export default function createStyled(input = {}) {
|
|
|
142
142
|
if (styleOverrides) {
|
|
143
143
|
const resolvedStyleOverrides = {};
|
|
144
144
|
Object.entries(styleOverrides).forEach(([slotKey, slotStyle]) => {
|
|
145
|
-
resolvedStyleOverrides[slotKey] = typeof slotStyle === 'function' ? slotStyle(props
|
|
145
|
+
resolvedStyleOverrides[slotKey] = typeof slotStyle === 'function' ? slotStyle(_extends({}, props, {
|
|
146
|
+
theme
|
|
147
|
+
})) : slotStyle;
|
|
146
148
|
});
|
|
147
149
|
return overridesResolver(props, resolvedStyleOverrides);
|
|
148
150
|
}
|
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
3
|
import { formatMuiErrorMessage as _formatMuiErrorMessage } from "@mui/utils";
|
|
4
|
-
const _excluded = ["colorSchemes"]
|
|
5
|
-
_excluded2 = ["colorSchemes"],
|
|
6
|
-
_excluded3 = ["components"];
|
|
4
|
+
const _excluded = ["colorSchemes", "components"];
|
|
7
5
|
import * as React from 'react';
|
|
8
6
|
import PropTypes from 'prop-types';
|
|
9
|
-
import { GlobalStyles } from '@mui/styled-engine';
|
|
10
7
|
import { deepmerge, unstable_useEnhancedEffect as useEnhancedEffect } from '@mui/utils';
|
|
11
|
-
import
|
|
12
|
-
import createBreakpoints from '../createTheme/createBreakpoints';
|
|
8
|
+
import { GlobalStyles } from '@mui/styled-engine';
|
|
13
9
|
import cssVarsParser from './cssVarsParser';
|
|
14
10
|
import ThemeProvider from '../ThemeProvider';
|
|
15
11
|
import getInitColorSchemeScript, { DEFAULT_ATTRIBUTE, DEFAULT_MODE_STORAGE_KEY } from './getInitColorSchemeScript';
|
|
@@ -19,10 +15,8 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
19
15
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
20
16
|
export const DISABLE_CSS_TRANSITION = '*{-webkit-transition:none!important;-moz-transition:none!important;-o-transition:none!important;-ms-transition:none!important;transition:none!important}';
|
|
21
17
|
export default function createCssVarsProvider(options) {
|
|
22
|
-
var _baseTheme$breakpoint;
|
|
23
|
-
|
|
24
18
|
const {
|
|
25
|
-
theme:
|
|
19
|
+
theme: defaultTheme = {},
|
|
26
20
|
defaultMode: desisgnSystemMode = 'light',
|
|
27
21
|
defaultColorScheme: designSystemColorScheme,
|
|
28
22
|
disableTransitionOnChange: designSystemTransitionOnChange = false,
|
|
@@ -31,10 +25,8 @@ export default function createCssVarsProvider(options) {
|
|
|
31
25
|
shouldSkipGeneratingVar,
|
|
32
26
|
resolveTheme
|
|
33
27
|
} = options;
|
|
34
|
-
const systemSpacing = createSpacing(baseTheme.spacing);
|
|
35
|
-
const systemBreakpoints = createBreakpoints((_baseTheme$breakpoint = baseTheme.breakpoints) != null ? _baseTheme$breakpoint : {});
|
|
36
28
|
|
|
37
|
-
if (!
|
|
29
|
+
if (!defaultTheme.colorSchemes || typeof designSystemColorScheme === 'string' && !defaultTheme.colorSchemes[designSystemColorScheme] || typeof designSystemColorScheme === 'object' && !defaultTheme.colorSchemes[designSystemColorScheme == null ? void 0 : designSystemColorScheme.light] || typeof designSystemColorScheme === 'object' && !defaultTheme.colorSchemes[designSystemColorScheme == null ? void 0 : designSystemColorScheme.dark]) {
|
|
38
30
|
console.error(`MUI: \`${designSystemColorScheme}\` does not exist in \`theme.colorSchemes\`.`);
|
|
39
31
|
}
|
|
40
32
|
|
|
@@ -52,7 +44,7 @@ export default function createCssVarsProvider(options) {
|
|
|
52
44
|
|
|
53
45
|
function CssVarsProvider({
|
|
54
46
|
children,
|
|
55
|
-
theme: themeProp =
|
|
47
|
+
theme: themeProp = defaultTheme,
|
|
56
48
|
prefix = designSystemPrefix,
|
|
57
49
|
modeStorageKey = DEFAULT_MODE_STORAGE_KEY,
|
|
58
50
|
attribute = DEFAULT_ATTRIBUTE,
|
|
@@ -61,25 +53,14 @@ export default function createCssVarsProvider(options) {
|
|
|
61
53
|
disableTransitionOnChange = designSystemTransitionOnChange,
|
|
62
54
|
enableColorScheme = designSystemEnableColorScheme
|
|
63
55
|
}) {
|
|
64
|
-
const
|
|
65
|
-
colorSchemes: baseColorSchemes = {}
|
|
66
|
-
} = baseTheme,
|
|
67
|
-
restBaseTheme = _objectWithoutPropertiesLoose(baseTheme, _excluded);
|
|
56
|
+
const hasMounted = React.useRef(false);
|
|
68
57
|
|
|
69
58
|
const {
|
|
70
|
-
colorSchemes
|
|
71
|
-
} = themeProp,
|
|
72
|
-
restThemeProp = _objectWithoutPropertiesLoose(themeProp, _excluded2);
|
|
73
|
-
|
|
74
|
-
const hasMounted = React.useRef(false); // eslint-disable-next-line prefer-const
|
|
75
|
-
|
|
76
|
-
let _deepmerge = deepmerge(restBaseTheme, restThemeProp),
|
|
77
|
-
{
|
|
59
|
+
colorSchemes = {},
|
|
78
60
|
components = {}
|
|
79
|
-
} =
|
|
80
|
-
|
|
61
|
+
} = themeProp,
|
|
62
|
+
restThemeProp = _objectWithoutPropertiesLoose(themeProp, _excluded);
|
|
81
63
|
|
|
82
|
-
const colorSchemes = deepmerge(baseColorSchemes, colorSchemesProp);
|
|
83
64
|
const allColorSchemes = Object.keys(colorSchemes);
|
|
84
65
|
const defaultLightColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.light;
|
|
85
66
|
const defaultDarkColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.dark;
|
|
@@ -113,22 +94,21 @@ export default function createCssVarsProvider(options) {
|
|
|
113
94
|
return colorScheme;
|
|
114
95
|
})();
|
|
115
96
|
|
|
97
|
+
let theme = restThemeProp;
|
|
116
98
|
const {
|
|
117
99
|
css: rootCss,
|
|
118
100
|
vars: rootVars,
|
|
119
101
|
parsedTheme
|
|
120
|
-
} = cssVarsParser(
|
|
102
|
+
} = cssVarsParser(theme, {
|
|
121
103
|
prefix,
|
|
122
104
|
basePrefix: designSystemPrefix,
|
|
123
105
|
shouldSkipGeneratingVar
|
|
124
106
|
});
|
|
125
|
-
|
|
107
|
+
theme = _extends({}, parsedTheme, {
|
|
126
108
|
components,
|
|
127
109
|
colorSchemes,
|
|
128
110
|
prefix,
|
|
129
111
|
vars: rootVars,
|
|
130
|
-
spacing: themeProp.spacing ? createSpacing(themeProp.spacing) : systemSpacing,
|
|
131
|
-
breakpoints: themeProp.breakpoints ? createBreakpoints(themeProp.breakpoints) : systemBreakpoints,
|
|
132
112
|
getCssVar: createGetCssVar(prefix)
|
|
133
113
|
});
|
|
134
114
|
const styleSheet = {};
|
|
@@ -142,10 +122,16 @@ export default function createCssVarsProvider(options) {
|
|
|
142
122
|
basePrefix: designSystemPrefix,
|
|
143
123
|
shouldSkipGeneratingVar
|
|
144
124
|
});
|
|
145
|
-
|
|
125
|
+
theme.vars = deepmerge(theme.vars, vars);
|
|
146
126
|
|
|
147
127
|
if (key === resolvedColorScheme) {
|
|
148
|
-
|
|
128
|
+
theme = _extends({}, theme, parsedScheme);
|
|
129
|
+
|
|
130
|
+
if (theme.palette) {
|
|
131
|
+
// assign runtime mode & colorScheme
|
|
132
|
+
theme.palette.mode = mode;
|
|
133
|
+
theme.palette.colorScheme = resolvedColorScheme;
|
|
134
|
+
}
|
|
149
135
|
}
|
|
150
136
|
|
|
151
137
|
const resolvedDefaultColorScheme = (() => {
|
|
@@ -232,7 +218,7 @@ export default function createCssVarsProvider(options) {
|
|
|
232
218
|
}), /*#__PURE__*/_jsx(GlobalStyles, {
|
|
233
219
|
styles: styleSheet
|
|
234
220
|
}), /*#__PURE__*/_jsx(ThemeProvider, {
|
|
235
|
-
theme: resolveTheme ? resolveTheme(
|
|
221
|
+
theme: resolveTheme ? resolveTheme(theme) : theme,
|
|
236
222
|
children: children
|
|
237
223
|
})]
|
|
238
224
|
});
|
|
@@ -15,16 +15,18 @@
|
|
|
15
15
|
* assignNestedKeys(source, ['palette', 'secondary'], 'var(--palette-secondary)')
|
|
16
16
|
* console.log(source) // { palette: { primary: 'var(--palette-primary)', secondary: 'var(--palette-secondary)' } }
|
|
17
17
|
*/
|
|
18
|
-
export const assignNestedKeys = (obj, keys, value) => {
|
|
18
|
+
export const assignNestedKeys = (obj, keys, value, arrayKeys = []) => {
|
|
19
19
|
let temp = obj;
|
|
20
20
|
keys.forEach((k, index) => {
|
|
21
21
|
if (index === keys.length - 1) {
|
|
22
|
-
if (temp
|
|
22
|
+
if (Array.isArray(temp)) {
|
|
23
|
+
temp[Number(k)] = value;
|
|
24
|
+
} else if (temp && typeof temp === 'object') {
|
|
23
25
|
temp[k] = value;
|
|
24
26
|
}
|
|
25
27
|
} else if (temp && typeof temp === 'object') {
|
|
26
28
|
if (!temp[k]) {
|
|
27
|
-
temp[k] = {};
|
|
29
|
+
temp[k] = arrayKeys.includes(k) ? [] : {};
|
|
28
30
|
}
|
|
29
31
|
|
|
30
32
|
temp = temp[k];
|
|
@@ -44,14 +46,14 @@ export const assignNestedKeys = (obj, keys, value) => {
|
|
|
44
46
|
*/
|
|
45
47
|
|
|
46
48
|
export const walkObjectDeep = (obj, callback, shouldSkipPaths) => {
|
|
47
|
-
function recurse(object, parentKeys = []) {
|
|
49
|
+
function recurse(object, parentKeys = [], arrayKeys = []) {
|
|
48
50
|
Object.entries(object).forEach(([key, value]) => {
|
|
49
51
|
if (!shouldSkipPaths || shouldSkipPaths && !shouldSkipPaths([...parentKeys, key])) {
|
|
50
52
|
if (value !== undefined && value !== null) {
|
|
51
53
|
if (typeof value === 'object' && Object.keys(value).length > 0) {
|
|
52
|
-
recurse(value, [...parentKeys, key]);
|
|
54
|
+
recurse(value, [...parentKeys, key], Array.isArray(value) ? [...arrayKeys, key] : arrayKeys);
|
|
53
55
|
} else {
|
|
54
|
-
callback([...parentKeys, key], value,
|
|
56
|
+
callback([...parentKeys, key], value, arrayKeys);
|
|
55
57
|
}
|
|
56
58
|
}
|
|
57
59
|
}
|
|
@@ -118,7 +120,7 @@ export default function cssVarsParser(theme, options) {
|
|
|
118
120
|
const css = {};
|
|
119
121
|
const vars = {};
|
|
120
122
|
const parsedTheme = {};
|
|
121
|
-
walkObjectDeep(theme, (keys, value) => {
|
|
123
|
+
walkObjectDeep(theme, (keys, value, arrayKeys) => {
|
|
122
124
|
if (typeof value === 'string' || typeof value === 'number') {
|
|
123
125
|
if (typeof value === 'string' && value.match(/var\(\s*--/)) {
|
|
124
126
|
// for CSS variable, apply prefix or remove basePrefix from the variable
|
|
@@ -136,11 +138,11 @@ export default function cssVarsParser(theme, options) {
|
|
|
136
138
|
Object.assign(css, {
|
|
137
139
|
[cssVar]: getCssValue(keys, value)
|
|
138
140
|
});
|
|
139
|
-
assignNestedKeys(vars, keys, `var(${cssVar})
|
|
141
|
+
assignNestedKeys(vars, keys, `var(${cssVar})`, arrayKeys);
|
|
140
142
|
}
|
|
141
143
|
}
|
|
142
144
|
|
|
143
|
-
assignNestedKeys(parsedTheme, keys, value);
|
|
145
|
+
assignNestedKeys(parsedTheme, keys, value, arrayKeys);
|
|
144
146
|
}, keys => keys[0] === 'vars' // skip 'vars/*' paths
|
|
145
147
|
);
|
|
146
148
|
return {
|
package/esm/spacing.js
CHANGED
|
@@ -43,7 +43,9 @@ const marginKeys = ['m', 'mt', 'mr', 'mb', 'ml', 'mx', 'my', 'margin', 'marginTo
|
|
|
43
43
|
const paddingKeys = ['p', 'pt', 'pr', 'pb', 'pl', 'px', 'py', 'padding', 'paddingTop', 'paddingRight', 'paddingBottom', 'paddingLeft', 'paddingX', 'paddingY', 'paddingInline', 'paddingInlineStart', 'paddingInlineEnd', 'paddingBlock', 'paddingBlockStart', 'paddingBlockEnd'];
|
|
44
44
|
const spacingKeys = [...marginKeys, ...paddingKeys];
|
|
45
45
|
export function createUnaryUnit(theme, themeKey, defaultValue, propName) {
|
|
46
|
-
|
|
46
|
+
var _getPath;
|
|
47
|
+
|
|
48
|
+
const themeSpacing = (_getPath = getPath(theme, themeKey)) != null ? _getPath : defaultValue;
|
|
47
49
|
|
|
48
50
|
if (typeof themeSpacing === 'number') {
|
|
49
51
|
return abs => {
|