@mui/system 5.2.3 → 5.2.8
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 +302 -32
- package/createBox.spec.d.ts +1 -1
- package/createTheme/createBreakpoints.d.ts +6 -0
- package/createTheme/createBreakpoints.js +16 -0
- package/createTheme/createSpacing.d.ts +10 -10
- package/cssVars/createCssVarsProvider.js +9 -3
- package/cssVars/createCssVarsProvider.spec.d.ts +1 -1
- package/cssVars/createGetCssVar.d.ts +5 -0
- package/cssVars/createGetCssVar.js +27 -0
- package/cssVars/cssVarsParser.d.ts +68 -68
- package/cssVars/getInitColorSchemeScript.d.ts +12 -12
- package/cssVars/index.d.ts +2 -2
- package/cssVars/useCurrentColorScheme.d.ts +50 -50
- package/esm/createTheme/createBreakpoints.js +16 -0
- package/esm/cssVars/createCssVarsProvider.js +9 -4
- package/esm/cssVars/createGetCssVar.js +20 -0
- package/esm/index.js +2 -1
- package/index.d.ts +1 -0
- package/index.js +11 -2
- package/index.spec.d.ts +1 -1
- package/legacy/createTheme/createBreakpoints.js +16 -0
- package/legacy/cssVars/createCssVarsProvider.js +9 -4
- package/legacy/cssVars/createGetCssVar.js +32 -0
- package/legacy/index.js +3 -2
- package/modern/createTheme/createBreakpoints.js +16 -0
- package/modern/cssVars/createCssVarsProvider.js +9 -4
- package/modern/cssVars/createGetCssVar.js +20 -0
- package/modern/index.js +3 -2
- package/package.json +2 -2
- package/styleFunctionSx/styleFunctionSx.d.ts +1 -0
- package/styleFunctionSx/styleFunctionSx.spec.d.ts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
|
@@ -0,0 +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;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = createGetCssVar;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The benefit of this function is to help developers get CSS var from theme without specifying the whole variable
|
|
10
|
+
* and they does not need to remember the prefix (defined once).
|
|
11
|
+
*/
|
|
12
|
+
function createGetCssVar(prefix = '') {
|
|
13
|
+
function appendVar(...vars) {
|
|
14
|
+
if (!vars.length) {
|
|
15
|
+
return '';
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return `, var(--${prefix ? `${prefix}-` : ''}${vars[0]}${appendVar(...vars.slice(1))})`;
|
|
19
|
+
} // AdditionalVars makes `getCssVar` less strict, so it can be use like this `getCssVar('non-mui-variable')` without type error.
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
const getCssVar = (field, ...vars) => {
|
|
23
|
+
return `var(--${prefix ? `${prefix}-` : ''}${field}${appendVar(...vars)})`;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
return getCssVar;
|
|
27
|
+
}
|
|
@@ -1,68 +1,68 @@
|
|
|
1
|
-
declare type NestedRecord<V = any> = {
|
|
2
|
-
[k: string | number]: NestedRecord<V> | V;
|
|
3
|
-
};
|
|
4
|
-
/**
|
|
5
|
-
* This function create an object from keys, value and then assign to target
|
|
6
|
-
*
|
|
7
|
-
* @param {Object} obj : the target object to be assigned
|
|
8
|
-
* @param {string[]} keys
|
|
9
|
-
* @param {string | number} value
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* const source = {}
|
|
13
|
-
* assignNestedKeys(source, ['palette', 'primary'], 'var(--palette-primary)')
|
|
14
|
-
* console.log(source) // { palette: { primary: 'var(--palette-primary)' } }
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* const source = { palette: { primary: 'var(--palette-primary)' } }
|
|
18
|
-
* assignNestedKeys(source, ['palette', 'secondary'], 'var(--palette-secondary)')
|
|
19
|
-
* console.log(source) // { palette: { primary: 'var(--palette-primary)', secondary: 'var(--palette-secondary)' } }
|
|
20
|
-
*/
|
|
21
|
-
export declare const assignNestedKeys: <Object_1 = NestedRecord<any>, Value = any>(obj: Object_1, keys: Array<string>, value: Value) => void;
|
|
22
|
-
/**
|
|
23
|
-
*
|
|
24
|
-
* @param {Object} obj : source object
|
|
25
|
-
* @param {Function} callback : a function that will be called when
|
|
26
|
-
* - the deepest key in source object is reached
|
|
27
|
-
* - the value of the deepest key is NOT `undefined` | `null`
|
|
28
|
-
*
|
|
29
|
-
* @example
|
|
30
|
-
* walkObjectDeep({ palette: { primary: { main: '#000000' } } }, console.log)
|
|
31
|
-
* // ['palette', 'primary', 'main'] '#000000'
|
|
32
|
-
*/
|
|
33
|
-
export declare const walkObjectDeep: <Value, T = Record<string, any>>(obj: T, callback: (keys: Array<string>, value: Value, scope: Record<string, string | number>) => void, shouldSkipPaths?: ((keys: Array<string>) => boolean) | undefined) => void;
|
|
34
|
-
/**
|
|
35
|
-
* a function that parse theme and return { css, vars }
|
|
36
|
-
*
|
|
37
|
-
* @param {Object} theme
|
|
38
|
-
* @param {{
|
|
39
|
-
* prefix?: string,
|
|
40
|
-
* basePrefix?: string,
|
|
41
|
-
* shouldSkipGeneratingVar?: (objectPathKeys: Array<string>, value: string | number) => boolean
|
|
42
|
-
* }} options.
|
|
43
|
-
* `basePrefix`: defined by design system.
|
|
44
|
-
* `prefix`: defined by application
|
|
45
|
-
*
|
|
46
|
-
* This function also mutate the string value of theme input by replacing `basePrefix` (if existed) with `prefix`
|
|
47
|
-
*
|
|
48
|
-
* @returns {{ css: Object, vars: Object }} `css` is the stylesheet, `vars` is an object to get css variable (same structure as theme)
|
|
49
|
-
*
|
|
50
|
-
* @example
|
|
51
|
-
* const { css, vars } = parser({
|
|
52
|
-
* fontSize: 12,
|
|
53
|
-
* lineHeight: 1.2,
|
|
54
|
-
* palette: { primary: { 500: '#000000' } }
|
|
55
|
-
* })
|
|
56
|
-
*
|
|
57
|
-
* console.log(css) // { '--fontSize': '12px', '--lineHeight': 1.2, '--palette-primary-500': '#000000' }
|
|
58
|
-
* console.log(vars) // { fontSize: '--fontSize', lineHeight: '--lineHeight', palette: { primary: { 500: 'var(--palette-primary-500)' } } }
|
|
59
|
-
*/
|
|
60
|
-
export default function cssVarsParser(theme: Record<string, any>, options?: {
|
|
61
|
-
prefix?: string;
|
|
62
|
-
basePrefix?: string;
|
|
63
|
-
shouldSkipGeneratingVar?: (objectPathKeys: Array<string>, value: string | number) => boolean;
|
|
64
|
-
}): {
|
|
65
|
-
css: NestedRecord<string>;
|
|
66
|
-
vars: NestedRecord<string>;
|
|
67
|
-
};
|
|
68
|
-
export {};
|
|
1
|
+
declare type NestedRecord<V = any> = {
|
|
2
|
+
[k: string | number]: NestedRecord<V> | V;
|
|
3
|
+
};
|
|
4
|
+
/**
|
|
5
|
+
* This function create an object from keys, value and then assign to target
|
|
6
|
+
*
|
|
7
|
+
* @param {Object} obj : the target object to be assigned
|
|
8
|
+
* @param {string[]} keys
|
|
9
|
+
* @param {string | number} value
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* const source = {}
|
|
13
|
+
* assignNestedKeys(source, ['palette', 'primary'], 'var(--palette-primary)')
|
|
14
|
+
* console.log(source) // { palette: { primary: 'var(--palette-primary)' } }
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* const source = { palette: { primary: 'var(--palette-primary)' } }
|
|
18
|
+
* assignNestedKeys(source, ['palette', 'secondary'], 'var(--palette-secondary)')
|
|
19
|
+
* console.log(source) // { palette: { primary: 'var(--palette-primary)', secondary: 'var(--palette-secondary)' } }
|
|
20
|
+
*/
|
|
21
|
+
export declare const assignNestedKeys: <Object_1 = NestedRecord<any>, Value = any>(obj: Object_1, keys: Array<string>, value: Value) => void;
|
|
22
|
+
/**
|
|
23
|
+
*
|
|
24
|
+
* @param {Object} obj : source object
|
|
25
|
+
* @param {Function} callback : a function that will be called when
|
|
26
|
+
* - the deepest key in source object is reached
|
|
27
|
+
* - the value of the deepest key is NOT `undefined` | `null`
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* walkObjectDeep({ palette: { primary: { main: '#000000' } } }, console.log)
|
|
31
|
+
* // ['palette', 'primary', 'main'] '#000000'
|
|
32
|
+
*/
|
|
33
|
+
export declare const walkObjectDeep: <Value, T = Record<string, any>>(obj: T, callback: (keys: Array<string>, value: Value, scope: Record<string, string | number>) => void, shouldSkipPaths?: ((keys: Array<string>) => boolean) | undefined) => void;
|
|
34
|
+
/**
|
|
35
|
+
* a function that parse theme and return { css, vars }
|
|
36
|
+
*
|
|
37
|
+
* @param {Object} theme
|
|
38
|
+
* @param {{
|
|
39
|
+
* prefix?: string,
|
|
40
|
+
* basePrefix?: string,
|
|
41
|
+
* shouldSkipGeneratingVar?: (objectPathKeys: Array<string>, value: string | number) => boolean
|
|
42
|
+
* }} options.
|
|
43
|
+
* `basePrefix`: defined by design system.
|
|
44
|
+
* `prefix`: defined by application
|
|
45
|
+
*
|
|
46
|
+
* This function also mutate the string value of theme input by replacing `basePrefix` (if existed) with `prefix`
|
|
47
|
+
*
|
|
48
|
+
* @returns {{ css: Object, vars: Object }} `css` is the stylesheet, `vars` is an object to get css variable (same structure as theme)
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* const { css, vars } = parser({
|
|
52
|
+
* fontSize: 12,
|
|
53
|
+
* lineHeight: 1.2,
|
|
54
|
+
* palette: { primary: { 500: '#000000' } }
|
|
55
|
+
* })
|
|
56
|
+
*
|
|
57
|
+
* console.log(css) // { '--fontSize': '12px', '--lineHeight': 1.2, '--palette-primary-500': '#000000' }
|
|
58
|
+
* console.log(vars) // { fontSize: '--fontSize', lineHeight: '--lineHeight', palette: { primary: { 500: 'var(--palette-primary-500)' } } }
|
|
59
|
+
*/
|
|
60
|
+
export default function cssVarsParser(theme: Record<string, any>, options?: {
|
|
61
|
+
prefix?: string;
|
|
62
|
+
basePrefix?: string;
|
|
63
|
+
shouldSkipGeneratingVar?: (objectPathKeys: Array<string>, value: string | number) => boolean;
|
|
64
|
+
}): {
|
|
65
|
+
css: NestedRecord<string>;
|
|
66
|
+
vars: NestedRecord<string>;
|
|
67
|
+
};
|
|
68
|
+
export {};
|
|
@@ -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 { BuildCssVarsTheme } from './createCssVarsProvider';
|
|
1
|
+
export { default } from './createCssVarsProvider';
|
|
2
|
+
export type { BuildCssVarsTheme } 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>;
|
|
@@ -51,6 +51,21 @@ export default function createBreakpoints(breakpoints) {
|
|
|
51
51
|
return up(key);
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
+
function not(key) {
|
|
55
|
+
// handle first and last key separately, for better readability
|
|
56
|
+
const keyIndex = keys.indexOf(key);
|
|
57
|
+
|
|
58
|
+
if (keyIndex === 0) {
|
|
59
|
+
return up(keys[1]);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (keyIndex === keys.length - 1) {
|
|
63
|
+
return down(keys[keyIndex]);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return between(key, keys[keys.indexOf(key) + 1]).replace('@media', '@media not all and');
|
|
67
|
+
}
|
|
68
|
+
|
|
54
69
|
return _extends({
|
|
55
70
|
keys,
|
|
56
71
|
values,
|
|
@@ -58,6 +73,7 @@ export default function createBreakpoints(breakpoints) {
|
|
|
58
73
|
down,
|
|
59
74
|
between,
|
|
60
75
|
only,
|
|
76
|
+
not,
|
|
61
77
|
unit
|
|
62
78
|
}, other);
|
|
63
79
|
}
|
|
@@ -7,13 +7,14 @@ const _excluded = ["colorSchemes"],
|
|
|
7
7
|
import * as React from 'react';
|
|
8
8
|
import PropTypes from 'prop-types';
|
|
9
9
|
import { GlobalStyles } from '@mui/styled-engine';
|
|
10
|
-
import { deepmerge } from '@mui/utils';
|
|
10
|
+
import { deepmerge, unstable_useEnhancedEffect as useEnhancedEffect } from '@mui/utils';
|
|
11
11
|
import createSpacing from '../createTheme/createSpacing';
|
|
12
12
|
import createBreakpoints from '../createTheme/createBreakpoints';
|
|
13
13
|
import cssVarsParser from './cssVarsParser';
|
|
14
14
|
import ThemeProvider from '../ThemeProvider';
|
|
15
15
|
import getInitColorSchemeScript, { DEFAULT_ATTRIBUTE, DEFAULT_MODE_STORAGE_KEY } from './getInitColorSchemeScript';
|
|
16
16
|
import useCurrentColorScheme from './useCurrentColorScheme';
|
|
17
|
+
import createGetCssVar from './createGetCssVar';
|
|
17
18
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
18
19
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
19
20
|
export const DISABLE_CSS_TRANSITION = '*{-webkit-transition:none!important;-moz-transition:none!important;-o-transition:none!important;-ms-transition:none!important;transition:none!important}';
|
|
@@ -71,7 +72,7 @@ export default function createCssVarsProvider(options) {
|
|
|
71
72
|
} = themeProp,
|
|
72
73
|
restThemeProp = _objectWithoutPropertiesLoose(themeProp, _excluded2);
|
|
73
74
|
|
|
74
|
-
const hasMounted = React.useRef(
|
|
75
|
+
const hasMounted = React.useRef(false); // eslint-disable-next-line prefer-const
|
|
75
76
|
|
|
76
77
|
let _deepmerge = deepmerge(restBaseTheme, restThemeProp),
|
|
77
78
|
{
|
|
@@ -126,7 +127,8 @@ export default function createCssVarsProvider(options) {
|
|
|
126
127
|
colorSchemes,
|
|
127
128
|
vars: rootVars,
|
|
128
129
|
spacing: themeProp.spacing ? createSpacing(themeProp.spacing) : systemSpacing,
|
|
129
|
-
breakpoints: themeProp.breakpoints ? createBreakpoints(themeProp.breakpoints) : systemBreakpoints
|
|
130
|
+
breakpoints: themeProp.breakpoints ? createBreakpoints(themeProp.breakpoints) : systemBreakpoints,
|
|
131
|
+
getCssVar: createGetCssVar(prefix)
|
|
130
132
|
});
|
|
131
133
|
const styleSheet = {};
|
|
132
134
|
Object.entries(colorSchemes).forEach(([key, scheme]) => {
|
|
@@ -164,7 +166,7 @@ export default function createCssVarsProvider(options) {
|
|
|
164
166
|
document.documentElement.setAttribute(attribute, colorScheme);
|
|
165
167
|
}
|
|
166
168
|
}, [colorScheme, attribute]);
|
|
167
|
-
|
|
169
|
+
useEnhancedEffect(() => {
|
|
168
170
|
if (!mode || !enableColorScheme) {
|
|
169
171
|
return undefined;
|
|
170
172
|
}
|
|
@@ -203,6 +205,9 @@ export default function createCssVarsProvider(options) {
|
|
|
203
205
|
}, [colorScheme]);
|
|
204
206
|
React.useEffect(() => {
|
|
205
207
|
hasMounted.current = true;
|
|
208
|
+
return () => {
|
|
209
|
+
hasMounted.current = false;
|
|
210
|
+
};
|
|
206
211
|
}, []);
|
|
207
212
|
return /*#__PURE__*/_jsxs(ColorSchemeContext.Provider, {
|
|
208
213
|
value: {
|
|
@@ -0,0 +1,20 @@
|
|
|
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(prefix = '') {
|
|
6
|
+
function appendVar(...vars) {
|
|
7
|
+
if (!vars.length) {
|
|
8
|
+
return '';
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return `, var(--${prefix ? `${prefix}-` : ''}${vars[0]}${appendVar(...vars.slice(1))})`;
|
|
12
|
+
} // AdditionalVars makes `getCssVar` less strict, so it can be use like this `getCssVar('non-mui-variable')` without type error.
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
const getCssVar = (field, ...vars) => {
|
|
16
|
+
return `var(--${prefix ? `${prefix}-` : ''}${field}${appendVar(...vars)})`;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
return getCssVar;
|
|
20
|
+
}
|
package/esm/index.js
CHANGED
|
@@ -38,4 +38,5 @@ export { default as useTheme } from './useTheme';
|
|
|
38
38
|
export { default as useThemeWithoutDefault } from './useThemeWithoutDefault';
|
|
39
39
|
export * from './colorManipulator';
|
|
40
40
|
export { default as ThemeProvider } from './ThemeProvider';
|
|
41
|
-
export { default as unstable_createCssVarsProvider } from './cssVars/createCssVarsProvider';
|
|
41
|
+
export { default as unstable_createCssVarsProvider } from './cssVars/createCssVarsProvider';
|
|
42
|
+
export { default as unstable_createGetCssVar } from './cssVars/createGetCssVar';
|
package/index.d.ts
CHANGED
|
@@ -161,4 +161,5 @@ export { default as ThemeProvider } from './ThemeProvider';
|
|
|
161
161
|
export * from './ThemeProvider';
|
|
162
162
|
|
|
163
163
|
export { default as unstable_createCssVarsProvider } from './cssVars';
|
|
164
|
+
export { default as unstable_createGetCssVar } from './cssVars/createGetCssVar';
|
|
164
165
|
export * from './cssVars';
|
package/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** @license MUI v5.2.
|
|
1
|
+
/** @license MUI v5.2.8
|
|
2
2
|
*
|
|
3
3
|
* This source code is licensed under the MIT license found in the
|
|
4
4
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -49,7 +49,8 @@ var _exportNames = {
|
|
|
49
49
|
useTheme: true,
|
|
50
50
|
useThemeWithoutDefault: true,
|
|
51
51
|
ThemeProvider: true,
|
|
52
|
-
unstable_createCssVarsProvider: true
|
|
52
|
+
unstable_createCssVarsProvider: true,
|
|
53
|
+
unstable_createGetCssVar: true
|
|
53
54
|
};
|
|
54
55
|
Object.defineProperty(exports, "Box", {
|
|
55
56
|
enumerable: true,
|
|
@@ -243,6 +244,12 @@ Object.defineProperty(exports, "unstable_createCssVarsProvider", {
|
|
|
243
244
|
return _createCssVarsProvider.default;
|
|
244
245
|
}
|
|
245
246
|
});
|
|
247
|
+
Object.defineProperty(exports, "unstable_createGetCssVar", {
|
|
248
|
+
enumerable: true,
|
|
249
|
+
get: function () {
|
|
250
|
+
return _createGetCssVar.default;
|
|
251
|
+
}
|
|
252
|
+
});
|
|
246
253
|
Object.defineProperty(exports, "unstable_extendSxProp", {
|
|
247
254
|
enumerable: true,
|
|
248
255
|
get: function () {
|
|
@@ -468,6 +475,8 @@ var _ThemeProvider = _interopRequireDefault(require("./ThemeProvider"));
|
|
|
468
475
|
|
|
469
476
|
var _createCssVarsProvider = _interopRequireDefault(require("./cssVars/createCssVarsProvider"));
|
|
470
477
|
|
|
478
|
+
var _createGetCssVar = _interopRequireDefault(require("./cssVars/createGetCssVar"));
|
|
479
|
+
|
|
471
480
|
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); }
|
|
472
481
|
|
|
473
482
|
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; }
|
package/index.spec.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
|
@@ -49,6 +49,21 @@ export default function createBreakpoints(breakpoints) {
|
|
|
49
49
|
return up(key);
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
+
function not(key) {
|
|
53
|
+
// handle first and last key separately, for better readability
|
|
54
|
+
var keyIndex = keys.indexOf(key);
|
|
55
|
+
|
|
56
|
+
if (keyIndex === 0) {
|
|
57
|
+
return up(keys[1]);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (keyIndex === keys.length - 1) {
|
|
61
|
+
return down(keys[keyIndex]);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return between(key, keys[keys.indexOf(key) + 1]).replace('@media', '@media not all and');
|
|
65
|
+
}
|
|
66
|
+
|
|
52
67
|
return _extends({
|
|
53
68
|
keys: keys,
|
|
54
69
|
values: values,
|
|
@@ -56,6 +71,7 @@ export default function createBreakpoints(breakpoints) {
|
|
|
56
71
|
down: down,
|
|
57
72
|
between: between,
|
|
58
73
|
only: only,
|
|
74
|
+
not: not,
|
|
59
75
|
unit: unit
|
|
60
76
|
}, other);
|
|
61
77
|
}
|
|
@@ -6,13 +6,14 @@ import { formatMuiErrorMessage as _formatMuiErrorMessage } from "@mui/utils";
|
|
|
6
6
|
import * as React from 'react';
|
|
7
7
|
import PropTypes from 'prop-types';
|
|
8
8
|
import { GlobalStyles } from '@mui/styled-engine';
|
|
9
|
-
import { deepmerge } from '@mui/utils';
|
|
9
|
+
import { deepmerge, unstable_useEnhancedEffect as useEnhancedEffect } from '@mui/utils';
|
|
10
10
|
import createSpacing from '../createTheme/createSpacing';
|
|
11
11
|
import createBreakpoints from '../createTheme/createBreakpoints';
|
|
12
12
|
import cssVarsParser from './cssVarsParser';
|
|
13
13
|
import ThemeProvider from '../ThemeProvider';
|
|
14
14
|
import getInitColorSchemeScript, { DEFAULT_ATTRIBUTE, DEFAULT_MODE_STORAGE_KEY } from './getInitColorSchemeScript';
|
|
15
15
|
import useCurrentColorScheme from './useCurrentColorScheme';
|
|
16
|
+
import createGetCssVar from './createGetCssVar';
|
|
16
17
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
17
18
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
18
19
|
export var DISABLE_CSS_TRANSITION = '*{-webkit-transition:none!important;-moz-transition:none!important;-o-transition:none!important;-ms-transition:none!important;transition:none!important}';
|
|
@@ -78,7 +79,7 @@ export default function createCssVarsProvider(options) {
|
|
|
78
79
|
colorSchemesProp = _themeProp$colorSchem === void 0 ? {} : _themeProp$colorSchem,
|
|
79
80
|
restThemeProp = _objectWithoutProperties(themeProp, ["colorSchemes"]);
|
|
80
81
|
|
|
81
|
-
var hasMounted = React.useRef(
|
|
82
|
+
var hasMounted = React.useRef(false); // eslint-disable-next-line prefer-const
|
|
82
83
|
|
|
83
84
|
var _deepmerge = deepmerge(restBaseTheme, restThemeProp),
|
|
84
85
|
_deepmerge$components = _deepmerge.components,
|
|
@@ -132,7 +133,8 @@ export default function createCssVarsProvider(options) {
|
|
|
132
133
|
colorSchemes: colorSchemes,
|
|
133
134
|
vars: rootVars,
|
|
134
135
|
spacing: themeProp.spacing ? createSpacing(themeProp.spacing) : systemSpacing,
|
|
135
|
-
breakpoints: themeProp.breakpoints ? createBreakpoints(themeProp.breakpoints) : systemBreakpoints
|
|
136
|
+
breakpoints: themeProp.breakpoints ? createBreakpoints(themeProp.breakpoints) : systemBreakpoints,
|
|
137
|
+
getCssVar: createGetCssVar(prefix)
|
|
136
138
|
});
|
|
137
139
|
var styleSheet = {};
|
|
138
140
|
Object.entries(colorSchemes).forEach(function (_ref2) {
|
|
@@ -174,7 +176,7 @@ export default function createCssVarsProvider(options) {
|
|
|
174
176
|
document.documentElement.setAttribute(attribute, colorScheme);
|
|
175
177
|
}
|
|
176
178
|
}, [colorScheme, attribute]);
|
|
177
|
-
|
|
179
|
+
useEnhancedEffect(function () {
|
|
178
180
|
if (!mode || !enableColorScheme) {
|
|
179
181
|
return undefined;
|
|
180
182
|
}
|
|
@@ -215,6 +217,9 @@ export default function createCssVarsProvider(options) {
|
|
|
215
217
|
}, [colorScheme]);
|
|
216
218
|
React.useEffect(function () {
|
|
217
219
|
hasMounted.current = true;
|
|
220
|
+
return function () {
|
|
221
|
+
hasMounted.current = false;
|
|
222
|
+
};
|
|
218
223
|
}, []);
|
|
219
224
|
return /*#__PURE__*/_jsxs(ColorSchemeContext.Provider, {
|
|
220
225
|
value: {
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The benefit of this function is to help developers get CSS var from theme without specifying the whole variable
|
|
5
|
+
* and they does not need to remember the prefix (defined once).
|
|
6
|
+
*/
|
|
7
|
+
export default function createGetCssVar() {
|
|
8
|
+
var prefix = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
9
|
+
|
|
10
|
+
function appendVar() {
|
|
11
|
+
for (var _len = arguments.length, vars = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
12
|
+
vars[_key] = arguments[_key];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (!vars.length) {
|
|
16
|
+
return '';
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return ", var(--".concat(prefix ? "".concat(prefix, "-") : '').concat(vars[0]).concat(appendVar.apply(void 0, _toConsumableArray(vars.slice(1))), ")");
|
|
20
|
+
} // AdditionalVars makes `getCssVar` less strict, so it can be use like this `getCssVar('non-mui-variable')` without type error.
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
var getCssVar = function getCssVar(field) {
|
|
24
|
+
for (var _len2 = arguments.length, vars = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
25
|
+
vars[_key2 - 1] = arguments[_key2];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return "var(--".concat(prefix ? "".concat(prefix, "-") : '').concat(field).concat(appendVar.apply(void 0, vars), ")");
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
return getCssVar;
|
|
32
|
+
}
|
package/legacy/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** @license MUI v5.2.
|
|
1
|
+
/** @license MUI v5.2.8
|
|
2
2
|
*
|
|
3
3
|
* This source code is licensed under the MIT license found in the
|
|
4
4
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -43,4 +43,5 @@ export { default as useTheme } from './useTheme';
|
|
|
43
43
|
export { default as useThemeWithoutDefault } from './useThemeWithoutDefault';
|
|
44
44
|
export * from './colorManipulator';
|
|
45
45
|
export { default as ThemeProvider } from './ThemeProvider';
|
|
46
|
-
export { default as unstable_createCssVarsProvider } from './cssVars/createCssVarsProvider';
|
|
46
|
+
export { default as unstable_createCssVarsProvider } from './cssVars/createCssVarsProvider';
|
|
47
|
+
export { default as unstable_createGetCssVar } from './cssVars/createGetCssVar';
|
|
@@ -51,6 +51,21 @@ export default function createBreakpoints(breakpoints) {
|
|
|
51
51
|
return up(key);
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
+
function not(key) {
|
|
55
|
+
// handle first and last key separately, for better readability
|
|
56
|
+
const keyIndex = keys.indexOf(key);
|
|
57
|
+
|
|
58
|
+
if (keyIndex === 0) {
|
|
59
|
+
return up(keys[1]);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (keyIndex === keys.length - 1) {
|
|
63
|
+
return down(keys[keyIndex]);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return between(key, keys[keys.indexOf(key) + 1]).replace('@media', '@media not all and');
|
|
67
|
+
}
|
|
68
|
+
|
|
54
69
|
return _extends({
|
|
55
70
|
keys,
|
|
56
71
|
values,
|
|
@@ -58,6 +73,7 @@ export default function createBreakpoints(breakpoints) {
|
|
|
58
73
|
down,
|
|
59
74
|
between,
|
|
60
75
|
only,
|
|
76
|
+
not,
|
|
61
77
|
unit
|
|
62
78
|
}, other);
|
|
63
79
|
}
|