@mui/system 5.10.13 → 5.10.14
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.js +1 -10
- package/Box/Box.spec.d.ts +1 -1
- package/Box/index.js +0 -2
- package/CHANGELOG.md +70 -2
- package/Container/Container.d.ts +13 -13
- package/Container/Container.js +2 -17
- package/Container/ContainerProps.d.ts +40 -40
- package/Container/containerClasses.d.ts +22 -22
- package/Container/containerClasses.js +0 -3
- package/Container/createContainer.d.ts +18 -18
- package/Container/createContainer.js +15 -37
- package/Container/index.js +0 -6
- package/Stack/Stack.d.ts +13 -13
- package/Stack/Stack.js +1 -12
- package/Stack/StackProps.d.ts +42 -42
- package/Stack/createStack.d.ts +21 -21
- package/Stack/createStack.js +10 -48
- package/Stack/index.d.ts +5 -5
- package/Stack/index.js +0 -9
- package/Stack/stackClasses.d.ts +8 -8
- package/Stack/stackClasses.js +0 -3
- package/ThemeProvider/ThemeProvider.js +2 -22
- package/ThemeProvider/index.js +0 -2
- package/Unstable_Grid/Grid.d.ts +12 -12
- package/Unstable_Grid/Grid.js +6 -42
- package/Unstable_Grid/GridProps.d.ts +162 -162
- package/Unstable_Grid/createGrid.d.ts +11 -11
- package/Unstable_Grid/createGrid.js +19 -49
- package/Unstable_Grid/gridClasses.d.ts +20 -20
- package/Unstable_Grid/gridClasses.js +8 -7
- package/Unstable_Grid/gridGenerator.d.ts +29 -28
- package/Unstable_Grid/gridGenerator.js +22 -63
- package/Unstable_Grid/index.d.ts +5 -5
- package/Unstable_Grid/index.js +0 -9
- package/borders.js +0 -14
- package/breakpoints.js +3 -32
- package/colorManipulator.js +13 -55
- package/compose.js +0 -7
- package/createBox.js +5 -20
- package/createBox.spec.d.ts +1 -1
- package/createStyled.js +27 -71
- package/createTheme/createBreakpoints.js +22 -37
- package/createTheme/createSpacing.d.ts +10 -10
- package/createTheme/createSpacing.js +4 -8
- package/createTheme/createTheme.js +6 -16
- package/createTheme/index.js +0 -2
- package/cssGrid.js +0 -21
- package/cssVars/createCssVarsProvider.js +24 -72
- package/cssVars/createCssVarsProvider.spec.d.ts +1 -1
- package/cssVars/createGetCssVar.d.ts +5 -5
- package/cssVars/createGetCssVar.js +2 -7
- package/cssVars/cssVarsParser.d.ts +65 -65
- package/cssVars/cssVarsParser.js +3 -15
- package/cssVars/getInitColorSchemeScript.d.ts +42 -42
- package/cssVars/getInitColorSchemeScript.js +0 -6
- package/cssVars/index.d.ts +3 -3
- package/cssVars/index.js +0 -3
- package/cssVars/useCurrentColorScheme.d.ts +53 -53
- package/cssVars/useCurrentColorScheme.js +20 -49
- package/display.js +0 -6
- package/esm/Box/Box.js +1 -6
- package/esm/Container/Container.js +3 -14
- package/esm/Container/createContainer.js +15 -25
- package/esm/Stack/Stack.js +1 -9
- package/esm/Stack/createStack.js +10 -29
- package/esm/ThemeProvider/ThemeProvider.js +2 -11
- package/esm/Unstable_Grid/Grid.js +6 -39
- package/esm/Unstable_Grid/createGrid.js +18 -35
- package/esm/Unstable_Grid/gridClasses.js +8 -4
- package/esm/Unstable_Grid/gridGenerator.js +20 -38
- package/esm/borders.js +0 -6
- package/esm/breakpoints.js +7 -22
- package/esm/colorManipulator.js +13 -43
- package/esm/compose.js +0 -5
- package/esm/createBox.js +5 -7
- package/esm/createStyled.js +27 -64
- package/esm/createTheme/createBreakpoints.js +22 -34
- package/esm/createTheme/createSpacing.js +4 -7
- package/esm/createTheme/createTheme.js +6 -9
- package/esm/cssGrid.js +0 -9
- package/esm/cssVars/createCssVarsProvider.js +24 -58
- package/esm/cssVars/createGetCssVar.js +2 -6
- package/esm/cssVars/cssVarsParser.js +3 -11
- package/esm/cssVars/useCurrentColorScheme.js +20 -44
- package/esm/getThemeValue.js +0 -2
- package/esm/index.js +1 -2
- package/esm/memoize.js +0 -1
- package/esm/merge.js +0 -3
- package/esm/palette.js +0 -3
- package/esm/propsToClassKey.js +4 -7
- package/esm/sizing.js +0 -5
- package/esm/spacing.js +3 -23
- package/esm/style.js +2 -19
- package/esm/styleFunctionSx/extendSxProp.js +3 -10
- package/esm/styleFunctionSx/styleFunctionSx.js +3 -16
- package/esm/sx/sx.js +0 -2
- package/esm/useTheme.js +0 -2
- package/esm/useThemeProps/getThemeProps.js +0 -2
- package/esm/useThemeWithoutDefault.js +0 -3
- package/flexbox.js +0 -4
- package/getThemeValue.js +0 -14
- package/index.js +1 -55
- package/index.spec.d.ts +1 -1
- package/legacy/Box/Box.js +1 -6
- package/legacy/Container/Container.js +3 -14
- package/legacy/Container/createContainer.js +29 -39
- package/legacy/Stack/Stack.js +1 -9
- package/legacy/Stack/createStack.js +17 -37
- package/legacy/ThemeProvider/ThemeProvider.js +3 -12
- package/legacy/Unstable_Grid/Grid.js +6 -39
- package/legacy/Unstable_Grid/createGrid.js +34 -53
- package/legacy/Unstable_Grid/gridGenerator.js +36 -58
- package/legacy/borders.js +0 -6
- package/legacy/breakpoints.js +9 -28
- package/legacy/colorManipulator.js +16 -48
- package/legacy/compose.js +0 -6
- package/legacy/createBox.js +9 -11
- package/legacy/createStyled.js +27 -68
- package/legacy/createTheme/createBreakpoints.js +20 -33
- package/legacy/createTheme/createSpacing.js +4 -9
- package/legacy/createTheme/createTheme.js +7 -13
- package/legacy/cssGrid.js +0 -9
- package/legacy/cssVars/createCssVarsProvider.js +90 -129
- package/legacy/cssVars/createGetCssVar.js +2 -10
- package/legacy/cssVars/cssVarsParser.js +7 -20
- package/legacy/cssVars/getInitColorSchemeScript.js +14 -15
- package/legacy/cssVars/useCurrentColorScheme.js +43 -69
- package/legacy/getThemeValue.js +0 -3
- package/legacy/index.js +2 -3
- package/legacy/memoize.js +0 -1
- package/legacy/merge.js +0 -3
- package/legacy/palette.js +0 -3
- package/legacy/propsToClassKey.js +2 -5
- package/legacy/sizing.js +0 -5
- package/legacy/spacing.js +6 -27
- package/legacy/style.js +6 -24
- package/legacy/styleFunctionSx/extendSxProp.js +3 -11
- package/legacy/styleFunctionSx/styleFunctionSx.js +6 -21
- package/legacy/sx/sx.js +0 -2
- package/legacy/useTheme.js +0 -2
- package/legacy/useThemeProps/getThemeProps.js +2 -4
- package/legacy/useThemeProps/useThemeProps.js +2 -2
- package/legacy/useThemeWithoutDefault.js +0 -3
- package/memoize.js +0 -2
- package/merge.js +0 -5
- package/modern/Box/Box.js +1 -6
- package/modern/Container/Container.js +3 -14
- package/modern/Container/createContainer.js +15 -25
- package/modern/Stack/Stack.js +1 -9
- package/modern/Stack/createStack.js +10 -29
- package/modern/ThemeProvider/ThemeProvider.js +2 -11
- package/modern/Unstable_Grid/Grid.js +6 -39
- package/modern/Unstable_Grid/createGrid.js +18 -34
- package/modern/Unstable_Grid/gridClasses.js +8 -4
- package/modern/Unstable_Grid/gridGenerator.js +20 -36
- package/modern/borders.js +0 -6
- package/modern/breakpoints.js +7 -21
- package/modern/colorManipulator.js +13 -43
- package/modern/compose.js +0 -5
- package/modern/createBox.js +5 -7
- package/modern/createStyled.js +27 -63
- package/modern/createTheme/createBreakpoints.js +22 -34
- package/modern/createTheme/createSpacing.js +4 -7
- package/modern/createTheme/createTheme.js +6 -9
- package/modern/cssGrid.js +0 -9
- package/modern/cssVars/createCssVarsProvider.js +24 -58
- package/modern/cssVars/createGetCssVar.js +2 -6
- package/modern/cssVars/cssVarsParser.js +3 -11
- package/modern/cssVars/useCurrentColorScheme.js +20 -44
- package/modern/getThemeValue.js +0 -2
- package/modern/index.js +2 -3
- package/modern/memoize.js +0 -1
- package/modern/merge.js +0 -3
- package/modern/palette.js +0 -3
- package/modern/propsToClassKey.js +4 -7
- package/modern/sizing.js +0 -4
- package/modern/spacing.js +3 -22
- package/modern/style.js +2 -19
- package/modern/styleFunctionSx/extendSxProp.js +3 -10
- package/modern/styleFunctionSx/styleFunctionSx.js +3 -16
- package/modern/sx/sx.js +0 -2
- package/modern/useTheme.js +0 -2
- package/modern/useThemeProps/getThemeProps.js +0 -2
- package/modern/useThemeWithoutDefault.js +0 -3
- package/package.json +6 -6
- package/palette.js +0 -6
- package/positions.js +0 -6
- package/propsToClassKey.js +4 -10
- package/responsivePropType.js +0 -3
- package/shadows.js +0 -3
- package/sizing.js +0 -11
- package/spacing.js +3 -37
- package/style.js +2 -24
- package/styleFunctionSx/extendSxProp.js +3 -15
- package/styleFunctionSx/index.js +0 -5
- package/styleFunctionSx/styleFunctionSx.js +3 -21
- package/styleFunctionSx/styleFunctionSx.spec.d.ts +1 -1
- package/styled.js +0 -3
- package/sx/index.js +0 -2
- package/sx/sx.js +0 -4
- package/typography.js +0 -4
- package/useTheme.js +0 -6
- package/useThemeProps/getThemeProps.js +0 -4
- package/useThemeProps/index.js +0 -3
- package/useThemeProps/useThemeProps.js +0 -4
- package/useThemeWithoutDefault.js +0 -4
|
@@ -4,84 +4,72 @@ const _excluded = ["values", "unit", "step"];
|
|
|
4
4
|
// Sorted ASC by size. That's important.
|
|
5
5
|
// It can't be configured as it's used statically for propTypes.
|
|
6
6
|
export const breakpointKeys = ['xs', 'sm', 'md', 'lg', 'xl'];
|
|
7
|
-
|
|
8
7
|
const sortBreakpointsValues = values => {
|
|
9
8
|
const breakpointsAsArray = Object.keys(values).map(key => ({
|
|
10
9
|
key,
|
|
11
10
|
val: values[key]
|
|
12
|
-
})) || [];
|
|
13
|
-
|
|
11
|
+
})) || [];
|
|
12
|
+
// Sort in ascending order
|
|
14
13
|
breakpointsAsArray.sort((breakpoint1, breakpoint2) => breakpoint1.val - breakpoint2.val);
|
|
15
14
|
return breakpointsAsArray.reduce((acc, obj) => {
|
|
16
15
|
return _extends({}, acc, {
|
|
17
16
|
[obj.key]: obj.val
|
|
18
17
|
});
|
|
19
18
|
}, {});
|
|
20
|
-
};
|
|
21
|
-
|
|
19
|
+
};
|
|
22
20
|
|
|
21
|
+
// Keep in mind that @media is inclusive by the CSS specification.
|
|
23
22
|
export default function createBreakpoints(breakpoints) {
|
|
24
23
|
const {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
24
|
+
// The breakpoint **start** at this value.
|
|
25
|
+
// For instance with the first breakpoint xs: [xs, sm).
|
|
26
|
+
values = {
|
|
27
|
+
xs: 0,
|
|
28
|
+
// phone
|
|
29
|
+
sm: 600,
|
|
30
|
+
// tablet
|
|
31
|
+
md: 900,
|
|
32
|
+
// small laptop
|
|
33
|
+
lg: 1200,
|
|
34
|
+
// desktop
|
|
35
|
+
xl: 1536 // large screen
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
unit = 'px',
|
|
39
|
+
step = 5
|
|
40
|
+
} = breakpoints,
|
|
41
|
+
other = _objectWithoutPropertiesLoose(breakpoints, _excluded);
|
|
44
42
|
const sortedValues = sortBreakpointsValues(values);
|
|
45
43
|
const keys = Object.keys(sortedValues);
|
|
46
|
-
|
|
47
44
|
function up(key) {
|
|
48
45
|
const value = typeof values[key] === 'number' ? values[key] : key;
|
|
49
46
|
return `@media (min-width:${value}${unit})`;
|
|
50
47
|
}
|
|
51
|
-
|
|
52
48
|
function down(key) {
|
|
53
49
|
const value = typeof values[key] === 'number' ? values[key] : key;
|
|
54
50
|
return `@media (max-width:${value - step / 100}${unit})`;
|
|
55
51
|
}
|
|
56
|
-
|
|
57
52
|
function between(start, end) {
|
|
58
53
|
const endIndex = keys.indexOf(end);
|
|
59
54
|
return `@media (min-width:${typeof values[start] === 'number' ? values[start] : start}${unit}) and ` + `(max-width:${(endIndex !== -1 && typeof values[keys[endIndex]] === 'number' ? values[keys[endIndex]] : end) - step / 100}${unit})`;
|
|
60
55
|
}
|
|
61
|
-
|
|
62
56
|
function only(key) {
|
|
63
57
|
if (keys.indexOf(key) + 1 < keys.length) {
|
|
64
58
|
return between(key, keys[keys.indexOf(key) + 1]);
|
|
65
59
|
}
|
|
66
|
-
|
|
67
60
|
return up(key);
|
|
68
61
|
}
|
|
69
|
-
|
|
70
62
|
function not(key) {
|
|
71
63
|
// handle first and last key separately, for better readability
|
|
72
64
|
const keyIndex = keys.indexOf(key);
|
|
73
|
-
|
|
74
65
|
if (keyIndex === 0) {
|
|
75
66
|
return up(keys[1]);
|
|
76
67
|
}
|
|
77
|
-
|
|
78
68
|
if (keyIndex === keys.length - 1) {
|
|
79
69
|
return down(keys[keyIndex]);
|
|
80
70
|
}
|
|
81
|
-
|
|
82
71
|
return between(key, keys[keys.indexOf(key) + 1]).replace('@media', '@media not all and');
|
|
83
72
|
}
|
|
84
|
-
|
|
85
73
|
return _extends({
|
|
86
74
|
keys,
|
|
87
75
|
values: sortedValues,
|
|
@@ -1,33 +1,30 @@
|
|
|
1
1
|
import { createUnarySpacing } from '../spacing';
|
|
2
|
-
|
|
3
2
|
/* tslint:enable:unified-signatures */
|
|
3
|
+
|
|
4
4
|
export default function createSpacing(spacingInput = 8) {
|
|
5
5
|
// Already transformed.
|
|
6
6
|
if (spacingInput.mui) {
|
|
7
7
|
return spacingInput;
|
|
8
|
-
}
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// Material Design layouts are visually balanced. Most measurements align to an 8dp grid, which aligns both spacing and the overall layout.
|
|
9
11
|
// Smaller components, such as icons, can align to a 4dp grid.
|
|
10
12
|
// https://m2.material.io/design/layout/understanding-layout.html
|
|
11
|
-
|
|
12
|
-
|
|
13
13
|
const transform = createUnarySpacing({
|
|
14
14
|
spacing: spacingInput
|
|
15
15
|
});
|
|
16
|
-
|
|
17
16
|
const spacing = (...argsInput) => {
|
|
18
17
|
if (process.env.NODE_ENV !== 'production') {
|
|
19
18
|
if (!(argsInput.length <= 4)) {
|
|
20
19
|
console.error(`MUI: Too many arguments provided, expected between 0 and 4, got ${argsInput.length}`);
|
|
21
20
|
}
|
|
22
21
|
}
|
|
23
|
-
|
|
24
22
|
const args = argsInput.length === 0 ? [1] : argsInput;
|
|
25
23
|
return args.map(argument => {
|
|
26
24
|
const output = transform(argument);
|
|
27
25
|
return typeof output === 'number' ? `${output}px` : output;
|
|
28
26
|
}).join(' ');
|
|
29
27
|
};
|
|
30
|
-
|
|
31
28
|
spacing.mui = true;
|
|
32
29
|
return spacing;
|
|
33
30
|
}
|
|
@@ -5,16 +5,14 @@ import { deepmerge } from '@mui/utils';
|
|
|
5
5
|
import createBreakpoints from './createBreakpoints';
|
|
6
6
|
import shape from './shape';
|
|
7
7
|
import createSpacing from './createSpacing';
|
|
8
|
-
|
|
9
8
|
function createTheme(options = {}, ...args) {
|
|
10
9
|
const {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
10
|
+
breakpoints: breakpointsInput = {},
|
|
11
|
+
palette: paletteInput = {},
|
|
12
|
+
spacing: spacingInput,
|
|
13
|
+
shape: shapeInput = {}
|
|
14
|
+
} = options,
|
|
15
|
+
other = _objectWithoutPropertiesLoose(options, _excluded);
|
|
18
16
|
const breakpoints = createBreakpoints(breakpointsInput);
|
|
19
17
|
const spacing = createSpacing(spacingInput);
|
|
20
18
|
let muiTheme = deepmerge({
|
|
@@ -31,5 +29,4 @@ function createTheme(options = {}, ...args) {
|
|
|
31
29
|
muiTheme = args.reduce((acc, argument) => deepmerge(acc, argument), muiTheme);
|
|
32
30
|
return muiTheme;
|
|
33
31
|
}
|
|
34
|
-
|
|
35
32
|
export default createTheme;
|
package/modern/cssGrid.js
CHANGED
|
@@ -6,14 +6,11 @@ import responsivePropType from './responsivePropType';
|
|
|
6
6
|
export const gap = props => {
|
|
7
7
|
if (props.gap !== undefined && props.gap !== null) {
|
|
8
8
|
const transformer = createUnaryUnit(props.theme, 'spacing', 8, 'gap');
|
|
9
|
-
|
|
10
9
|
const styleFromPropValue = propValue => ({
|
|
11
10
|
gap: getValue(transformer, propValue)
|
|
12
11
|
});
|
|
13
|
-
|
|
14
12
|
return handleBreakpoints(props, props.gap, styleFromPropValue);
|
|
15
13
|
}
|
|
16
|
-
|
|
17
14
|
return null;
|
|
18
15
|
};
|
|
19
16
|
gap.propTypes = process.env.NODE_ENV !== 'production' ? {
|
|
@@ -23,14 +20,11 @@ gap.filterProps = ['gap'];
|
|
|
23
20
|
export const columnGap = props => {
|
|
24
21
|
if (props.columnGap !== undefined && props.columnGap !== null) {
|
|
25
22
|
const transformer = createUnaryUnit(props.theme, 'spacing', 8, 'columnGap');
|
|
26
|
-
|
|
27
23
|
const styleFromPropValue = propValue => ({
|
|
28
24
|
columnGap: getValue(transformer, propValue)
|
|
29
25
|
});
|
|
30
|
-
|
|
31
26
|
return handleBreakpoints(props, props.columnGap, styleFromPropValue);
|
|
32
27
|
}
|
|
33
|
-
|
|
34
28
|
return null;
|
|
35
29
|
};
|
|
36
30
|
columnGap.propTypes = process.env.NODE_ENV !== 'production' ? {
|
|
@@ -40,14 +34,11 @@ columnGap.filterProps = ['columnGap'];
|
|
|
40
34
|
export const rowGap = props => {
|
|
41
35
|
if (props.rowGap !== undefined && props.rowGap !== null) {
|
|
42
36
|
const transformer = createUnaryUnit(props.theme, 'spacing', 8, 'rowGap');
|
|
43
|
-
|
|
44
37
|
const styleFromPropValue = propValue => ({
|
|
45
38
|
rowGap: getValue(transformer, propValue)
|
|
46
39
|
});
|
|
47
|
-
|
|
48
40
|
return handleBreakpoints(props, props.rowGap, styleFromPropValue);
|
|
49
41
|
}
|
|
50
|
-
|
|
51
42
|
return null;
|
|
52
43
|
};
|
|
53
44
|
rowGap.propTypes = process.env.NODE_ENV !== 'production' ? {
|
|
@@ -26,23 +26,17 @@ export default function createCssVarsProvider(options) {
|
|
|
26
26
|
resolveTheme,
|
|
27
27
|
excludeVariablesFromRoot
|
|
28
28
|
} = options;
|
|
29
|
-
|
|
30
29
|
if (!defaultTheme.colorSchemes || typeof designSystemColorScheme === 'string' && !defaultTheme.colorSchemes[designSystemColorScheme] || typeof designSystemColorScheme === 'object' && !defaultTheme.colorSchemes[designSystemColorScheme?.light] || typeof designSystemColorScheme === 'object' && !defaultTheme.colorSchemes[designSystemColorScheme?.dark]) {
|
|
31
30
|
console.error(`MUI: \`${designSystemColorScheme}\` does not exist in \`theme.colorSchemes\`.`);
|
|
32
31
|
}
|
|
33
|
-
|
|
34
32
|
const ColorSchemeContext = /*#__PURE__*/React.createContext(undefined);
|
|
35
|
-
|
|
36
33
|
const useColorScheme = () => {
|
|
37
34
|
const value = React.useContext(ColorSchemeContext);
|
|
38
|
-
|
|
39
35
|
if (!value) {
|
|
40
36
|
throw new Error(process.env.NODE_ENV !== "production" ? `MUI: \`useColorScheme\` must be called under <CssVarsProvider />` : _formatMuiErrorMessage(19));
|
|
41
37
|
}
|
|
42
|
-
|
|
43
38
|
return value;
|
|
44
39
|
};
|
|
45
|
-
|
|
46
40
|
function CssVarsProvider({
|
|
47
41
|
children,
|
|
48
42
|
theme: themeProp = defaultTheme,
|
|
@@ -59,18 +53,17 @@ export default function createCssVarsProvider(options) {
|
|
|
59
53
|
shouldSkipGeneratingVar = designSystemShouldSkipGeneratingVar
|
|
60
54
|
}) {
|
|
61
55
|
const hasMounted = React.useRef(false);
|
|
62
|
-
|
|
63
56
|
const {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
57
|
+
colorSchemes = {},
|
|
58
|
+
components = {},
|
|
59
|
+
cssVarPrefix
|
|
60
|
+
} = themeProp,
|
|
61
|
+
restThemeProp = _objectWithoutPropertiesLoose(themeProp, _excluded);
|
|
70
62
|
const allColorSchemes = Object.keys(colorSchemes);
|
|
71
63
|
const defaultLightColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.light;
|
|
72
|
-
const defaultDarkColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.dark;
|
|
64
|
+
const defaultDarkColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.dark;
|
|
73
65
|
|
|
66
|
+
// 1. Get the data about the `mode`, `colorScheme`, and setter functions.
|
|
74
67
|
const {
|
|
75
68
|
mode,
|
|
76
69
|
setMode,
|
|
@@ -88,35 +81,29 @@ export default function createCssVarsProvider(options) {
|
|
|
88
81
|
defaultMode,
|
|
89
82
|
storageWindow
|
|
90
83
|
});
|
|
91
|
-
|
|
92
84
|
const calculatedMode = (() => {
|
|
93
85
|
if (!mode) {
|
|
94
86
|
// This scope occurs on the server
|
|
95
87
|
if (defaultMode === 'system') {
|
|
96
88
|
return designSystemMode;
|
|
97
89
|
}
|
|
98
|
-
|
|
99
90
|
return defaultMode;
|
|
100
91
|
}
|
|
101
|
-
|
|
102
92
|
return mode;
|
|
103
93
|
})();
|
|
104
|
-
|
|
105
94
|
const calculatedColorScheme = (() => {
|
|
106
95
|
if (!colorScheme) {
|
|
107
96
|
// This scope occurs on the server
|
|
108
97
|
if (calculatedMode === 'dark') {
|
|
109
98
|
return defaultDarkColorScheme;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
|
|
99
|
+
}
|
|
100
|
+
// use light color scheme, if default mode is 'light' | 'system'
|
|
113
101
|
return defaultLightColorScheme;
|
|
114
102
|
}
|
|
115
|
-
|
|
116
103
|
return colorScheme;
|
|
117
|
-
})();
|
|
118
|
-
|
|
104
|
+
})();
|
|
119
105
|
|
|
106
|
+
// 2. Create CSS variables and store them in objects (to be generated in stylesheets in the final step)
|
|
120
107
|
const {
|
|
121
108
|
css: rootCss,
|
|
122
109
|
vars: rootVars,
|
|
@@ -124,19 +111,20 @@ export default function createCssVarsProvider(options) {
|
|
|
124
111
|
} = cssVarsParser(restThemeProp, {
|
|
125
112
|
prefix: cssVarPrefix,
|
|
126
113
|
shouldSkipGeneratingVar
|
|
127
|
-
});
|
|
114
|
+
});
|
|
128
115
|
|
|
116
|
+
// 3. Start composing the theme object
|
|
129
117
|
let theme = _extends({}, parsedTheme, {
|
|
130
118
|
components,
|
|
131
119
|
colorSchemes,
|
|
132
120
|
cssVarPrefix,
|
|
133
121
|
vars: rootVars,
|
|
134
122
|
getColorSchemeSelector: targetColorScheme => `[${attribute}="${targetColorScheme}"] &`
|
|
135
|
-
});
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
// 4. Create color CSS variables and store them in objects (to be generated in stylesheets in the final step)
|
|
136
126
|
// The default color scheme stylesheet is constructed to have the least CSS specificity.
|
|
137
127
|
// The other color schemes uses selector, default as data attribute, to increase the CSS specificity so that they can override the default color scheme stylesheet.
|
|
138
|
-
|
|
139
|
-
|
|
140
128
|
const defaultColorSchemeStyleSheet = {};
|
|
141
129
|
const otherColorSchemesStyleSheet = {};
|
|
142
130
|
Object.entries(colorSchemes).forEach(([key, scheme]) => {
|
|
@@ -149,28 +137,22 @@ export default function createCssVarsProvider(options) {
|
|
|
149
137
|
shouldSkipGeneratingVar
|
|
150
138
|
});
|
|
151
139
|
theme.vars = deepmerge(theme.vars, vars);
|
|
152
|
-
|
|
153
140
|
if (key === calculatedColorScheme) {
|
|
154
141
|
// 4.1 Merge the selected color scheme to the theme
|
|
155
142
|
theme = _extends({}, theme, parsedScheme);
|
|
156
|
-
|
|
157
143
|
if (theme.palette) {
|
|
158
144
|
theme.palette.colorScheme = key;
|
|
159
145
|
}
|
|
160
146
|
}
|
|
161
|
-
|
|
162
147
|
const resolvedDefaultColorScheme = (() => {
|
|
163
148
|
if (typeof defaultColorScheme === 'string') {
|
|
164
149
|
return defaultColorScheme;
|
|
165
150
|
}
|
|
166
|
-
|
|
167
151
|
if (defaultMode === 'dark') {
|
|
168
152
|
return defaultColorScheme.dark;
|
|
169
153
|
}
|
|
170
|
-
|
|
171
154
|
return defaultColorScheme.light;
|
|
172
155
|
})();
|
|
173
|
-
|
|
174
156
|
if (key === resolvedDefaultColorScheme) {
|
|
175
157
|
if (excludeVariablesFromRoot) {
|
|
176
158
|
const excludedVariables = {};
|
|
@@ -180,37 +162,36 @@ export default function createCssVarsProvider(options) {
|
|
|
180
162
|
});
|
|
181
163
|
defaultColorSchemeStyleSheet[`[${attribute}="${key}"]`] = excludedVariables;
|
|
182
164
|
}
|
|
183
|
-
|
|
184
165
|
defaultColorSchemeStyleSheet[`${colorSchemeSelector}, [${attribute}="${key}"]`] = css;
|
|
185
166
|
} else {
|
|
186
167
|
otherColorSchemesStyleSheet[`${colorSchemeSelector === ':root' ? '' : colorSchemeSelector}[${attribute}="${key}"]`] = css;
|
|
187
168
|
}
|
|
188
|
-
});
|
|
189
|
-
// 5.1 Updates the selector value to use the current color scheme which tells CSS to use the proper stylesheet.
|
|
169
|
+
});
|
|
190
170
|
|
|
171
|
+
// 5. Declaring effects
|
|
172
|
+
// 5.1 Updates the selector value to use the current color scheme which tells CSS to use the proper stylesheet.
|
|
191
173
|
React.useEffect(() => {
|
|
192
174
|
if (colorScheme && colorSchemeNode) {
|
|
193
175
|
// attaches attribute to <html> because the css variables are attached to :root (html)
|
|
194
176
|
colorSchemeNode.setAttribute(attribute, colorScheme);
|
|
195
177
|
}
|
|
196
|
-
}, [colorScheme, attribute, colorSchemeNode]);
|
|
197
|
-
// credit: https://github.com/pacocoursey/next-themes/blob/b5c2bad50de2d61ad7b52a9c5cdc801a78507d7a/index.tsx#L313
|
|
178
|
+
}, [colorScheme, attribute, colorSchemeNode]);
|
|
198
179
|
|
|
180
|
+
// 5.2 Remove the CSS transition when color scheme changes to create instant experience.
|
|
181
|
+
// credit: https://github.com/pacocoursey/next-themes/blob/b5c2bad50de2d61ad7b52a9c5cdc801a78507d7a/index.tsx#L313
|
|
199
182
|
React.useEffect(() => {
|
|
200
183
|
let timer;
|
|
201
|
-
|
|
202
184
|
if (disableTransitionOnChange && hasMounted.current && documentNode) {
|
|
203
185
|
const css = documentNode.createElement('style');
|
|
204
186
|
css.appendChild(documentNode.createTextNode(DISABLE_CSS_TRANSITION));
|
|
205
|
-
documentNode.head.appendChild(css);
|
|
187
|
+
documentNode.head.appendChild(css);
|
|
206
188
|
|
|
189
|
+
// Force browser repaint
|
|
207
190
|
(() => window.getComputedStyle(documentNode.body))();
|
|
208
|
-
|
|
209
191
|
timer = setTimeout(() => {
|
|
210
192
|
documentNode.head.removeChild(css);
|
|
211
193
|
}, 1);
|
|
212
194
|
}
|
|
213
|
-
|
|
214
195
|
return () => {
|
|
215
196
|
clearTimeout(timer);
|
|
216
197
|
};
|
|
@@ -247,69 +228,56 @@ export default function createCssVarsProvider(options) {
|
|
|
247
228
|
})]
|
|
248
229
|
});
|
|
249
230
|
}
|
|
250
|
-
|
|
251
231
|
process.env.NODE_ENV !== "production" ? CssVarsProvider.propTypes = {
|
|
252
232
|
/**
|
|
253
233
|
* The body attribute name to attach colorScheme.
|
|
254
234
|
*/
|
|
255
235
|
attribute: PropTypes.string,
|
|
256
|
-
|
|
257
236
|
/**
|
|
258
237
|
* The component tree.
|
|
259
238
|
*/
|
|
260
239
|
children: PropTypes.node,
|
|
261
|
-
|
|
262
240
|
/**
|
|
263
241
|
* The node used to attach the color-scheme attribute
|
|
264
242
|
*/
|
|
265
243
|
colorSchemeNode: PropTypes.any,
|
|
266
|
-
|
|
267
244
|
/**
|
|
268
245
|
* The CSS selector for attaching the generated custom properties
|
|
269
246
|
*/
|
|
270
247
|
colorSchemeSelector: PropTypes.string,
|
|
271
|
-
|
|
272
248
|
/**
|
|
273
249
|
* localStorage key used to store `colorScheme`
|
|
274
250
|
*/
|
|
275
251
|
colorSchemeStorageKey: PropTypes.string,
|
|
276
|
-
|
|
277
252
|
/**
|
|
278
253
|
* The initial color scheme used.
|
|
279
254
|
*/
|
|
280
255
|
defaultColorScheme: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
|
|
281
|
-
|
|
282
256
|
/**
|
|
283
257
|
* The initial mode used.
|
|
284
258
|
*/
|
|
285
259
|
defaultMode: PropTypes.string,
|
|
286
|
-
|
|
287
260
|
/**
|
|
288
261
|
* Disable CSS transitions when switching between modes or color schemes
|
|
289
262
|
*/
|
|
290
263
|
disableTransitionOnChange: PropTypes.bool,
|
|
291
|
-
|
|
292
264
|
/**
|
|
293
265
|
* The document to attach the attribute to
|
|
294
266
|
*/
|
|
295
267
|
documentNode: PropTypes.any,
|
|
296
|
-
|
|
297
268
|
/**
|
|
298
269
|
* The key in the local storage used to store current color scheme.
|
|
299
270
|
*/
|
|
300
271
|
modeStorageKey: PropTypes.string,
|
|
301
|
-
|
|
302
272
|
/**
|
|
303
273
|
* A function to determine if the key, value should be attached as CSS Variable
|
|
304
274
|
*/
|
|
305
275
|
shouldSkipGeneratingVar: PropTypes.func,
|
|
306
|
-
|
|
307
276
|
/**
|
|
308
277
|
* The window that attaches the 'storage' event listener
|
|
309
278
|
* @default window
|
|
310
279
|
*/
|
|
311
280
|
storageWindow: PropTypes.any,
|
|
312
|
-
|
|
313
281
|
/**
|
|
314
282
|
* The calculated theme object that will be passed through context.
|
|
315
283
|
*/
|
|
@@ -317,7 +285,6 @@ export default function createCssVarsProvider(options) {
|
|
|
317
285
|
} : void 0;
|
|
318
286
|
const defaultLightColorScheme = typeof designSystemColorScheme === 'string' ? designSystemColorScheme : designSystemColorScheme.light;
|
|
319
287
|
const defaultDarkColorScheme = typeof designSystemColorScheme === 'string' ? designSystemColorScheme : designSystemColorScheme.dark;
|
|
320
|
-
|
|
321
288
|
const getInitColorSchemeScript = params => systemGetInitColorSchemeScript(_extends({
|
|
322
289
|
attribute: defaultAttribute,
|
|
323
290
|
colorSchemeStorageKey: defaultColorSchemeStorageKey,
|
|
@@ -326,7 +293,6 @@ export default function createCssVarsProvider(options) {
|
|
|
326
293
|
defaultDarkColorScheme,
|
|
327
294
|
modeStorageKey: defaultModeStorageKey
|
|
328
295
|
}, params));
|
|
329
|
-
|
|
330
296
|
return {
|
|
331
297
|
CssVarsProvider,
|
|
332
298
|
useColorScheme,
|
|
@@ -7,20 +7,16 @@ export default function createGetCssVar(prefix = '') {
|
|
|
7
7
|
if (!vars.length) {
|
|
8
8
|
return '';
|
|
9
9
|
}
|
|
10
|
-
|
|
11
10
|
const value = vars[0];
|
|
12
|
-
|
|
13
11
|
if (typeof value === 'string' && !value.match(/(#|\(|\)|(-?(\d*\.)?\d+)(px|em|%|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc))/)) {
|
|
14
12
|
return `, var(--${prefix ? `${prefix}-` : ''}${value}${appendVar(...vars.slice(1))})`;
|
|
15
13
|
}
|
|
16
|
-
|
|
17
14
|
return `, ${value}`;
|
|
18
|
-
}
|
|
19
|
-
|
|
15
|
+
}
|
|
20
16
|
|
|
17
|
+
// AdditionalVars makes `getCssVar` less strict, so it can be use like this `getCssVar('non-mui-variable')` without type error.
|
|
21
18
|
const getCssVar = (field, ...fallbacks) => {
|
|
22
19
|
return `var(--${prefix ? `${prefix}-` : ''}${field}${appendVar(...fallbacks)})`;
|
|
23
20
|
};
|
|
24
|
-
|
|
25
21
|
return getCssVar;
|
|
26
22
|
}
|
|
@@ -28,11 +28,11 @@ export const assignNestedKeys = (obj, keys, value, arrayKeys = []) => {
|
|
|
28
28
|
if (!temp[k]) {
|
|
29
29
|
temp[k] = arrayKeys.includes(k) ? [] : {};
|
|
30
30
|
}
|
|
31
|
-
|
|
32
31
|
temp = temp[k];
|
|
33
32
|
}
|
|
34
33
|
});
|
|
35
34
|
};
|
|
35
|
+
|
|
36
36
|
/**
|
|
37
37
|
*
|
|
38
38
|
* @param {Object} obj : source object
|
|
@@ -44,7 +44,6 @@ export const assignNestedKeys = (obj, keys, value, arrayKeys = []) => {
|
|
|
44
44
|
* walkObjectDeep({ palette: { primary: { main: '#000000' } } }, console.log)
|
|
45
45
|
* // ['palette', 'primary', 'main'] '#000000'
|
|
46
46
|
*/
|
|
47
|
-
|
|
48
47
|
export const walkObjectDeep = (obj, callback, shouldSkipPaths) => {
|
|
49
48
|
function recurse(object, parentKeys = [], arrayKeys = []) {
|
|
50
49
|
Object.entries(object).forEach(([key, value]) => {
|
|
@@ -59,29 +58,24 @@ export const walkObjectDeep = (obj, callback, shouldSkipPaths) => {
|
|
|
59
58
|
}
|
|
60
59
|
});
|
|
61
60
|
}
|
|
62
|
-
|
|
63
61
|
recurse(obj);
|
|
64
62
|
};
|
|
65
|
-
|
|
66
63
|
const getCssValue = (keys, value) => {
|
|
67
64
|
if (typeof value === 'number') {
|
|
68
65
|
if (['lineHeight', 'fontWeight', 'opacity', 'zIndex'].some(prop => keys.includes(prop))) {
|
|
69
66
|
// CSS property that are unitless
|
|
70
67
|
return value;
|
|
71
68
|
}
|
|
72
|
-
|
|
73
69
|
const lastKey = keys[keys.length - 1];
|
|
74
|
-
|
|
75
70
|
if (lastKey.toLowerCase().indexOf('opacity') >= 0) {
|
|
76
71
|
// opacity values are unitless
|
|
77
72
|
return value;
|
|
78
73
|
}
|
|
79
|
-
|
|
80
74
|
return `${value}px`;
|
|
81
75
|
}
|
|
82
|
-
|
|
83
76
|
return value;
|
|
84
77
|
};
|
|
78
|
+
|
|
85
79
|
/**
|
|
86
80
|
* a function that parse theme and return { css, vars }
|
|
87
81
|
*
|
|
@@ -105,8 +99,6 @@ const getCssValue = (keys, value) => {
|
|
|
105
99
|
* console.log(vars) // { fontSize: 'var(--foo-fontSize)', lineHeight: 'var(--foo-lineHeight)', palette: { primary: { 500: 'var(--foo-palette-primary-500)' } } }
|
|
106
100
|
* console.log(parsedTheme) // { fontSize: 12, lineHeight: 1.2, palette: { primary: { 500: 'var(--color)' } } }
|
|
107
101
|
*/
|
|
108
|
-
|
|
109
|
-
|
|
110
102
|
export default function cssVarsParser(theme, options) {
|
|
111
103
|
const {
|
|
112
104
|
prefix,
|
|
@@ -126,10 +118,10 @@ export default function cssVarsParser(theme, options) {
|
|
|
126
118
|
assignNestedKeys(vars, keys, `var(${cssVar})`, arrayKeys);
|
|
127
119
|
}
|
|
128
120
|
}
|
|
129
|
-
|
|
130
121
|
assignNestedKeys(parsedTheme, keys, value, arrayKeys);
|
|
131
122
|
}, keys => keys[0] === 'vars' // skip 'vars/*' paths
|
|
132
123
|
);
|
|
124
|
+
|
|
133
125
|
return {
|
|
134
126
|
css,
|
|
135
127
|
vars,
|