@mui/system 5.0.1 → 5.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/Box/Box.spec.d.ts +1 -1
  2. package/CHANGELOG.md +281 -0
  3. package/LICENSE +21 -21
  4. package/borders.js +1 -1
  5. package/breakpoints.js +4 -3
  6. package/colorManipulator.js +8 -8
  7. package/createStyled.d.ts +16 -215
  8. package/createStyled.js +1 -1
  9. package/createTheme/createBreakpoints.d.ts +53 -6
  10. package/createTheme/createBreakpoints.js +1 -1
  11. package/createTheme/createSpacing.d.ts +10 -10
  12. package/cssVars/createCssVarsProvider.d.ts +81 -0
  13. package/cssVars/createCssVarsProvider.js +206 -0
  14. package/cssVars/createCssVarsProvider.spec.d.ts +1 -0
  15. package/cssVars/cssVarsParser.d.ts +57 -0
  16. package/cssVars/cssVarsParser.js +126 -0
  17. package/cssVars/getInitColorSchemeScript.d.ts +7 -0
  18. package/cssVars/getInitColorSchemeScript.js +38 -0
  19. package/cssVars/index.d.ts +2 -0
  20. package/cssVars/index.js +15 -0
  21. package/cssVars/package.json +6 -0
  22. package/display.js +1 -1
  23. package/esm/cssVars/createCssVarsProvider.js +188 -0
  24. package/esm/cssVars/cssVarsParser.js +112 -0
  25. package/esm/cssVars/getInitColorSchemeScript.js +21 -0
  26. package/esm/cssVars/index.js +1 -0
  27. package/esm/index.js +2 -1
  28. package/esm/spacing.js +2 -2
  29. package/esm/styleFunctionSx/styleFunctionSx.js +6 -6
  30. package/flexbox.js +1 -1
  31. package/getThemeValue.js +1 -1
  32. package/grid.js +1 -1
  33. package/index.d.ts +6 -0
  34. package/index.js +77 -68
  35. package/index.spec.d.ts +1 -1
  36. package/legacy/cssVars/createCssVarsProvider.js +202 -0
  37. package/legacy/cssVars/cssVarsParser.js +125 -0
  38. package/legacy/cssVars/getInitColorSchemeScript.js +18 -0
  39. package/legacy/cssVars/index.js +1 -0
  40. package/legacy/index.js +3 -2
  41. package/legacy/spacing.js +2 -2
  42. package/legacy/styleFunctionSx/styleFunctionSx.js +6 -6
  43. package/modern/cssVars/createCssVarsProvider.js +188 -0
  44. package/modern/cssVars/cssVarsParser.js +112 -0
  45. package/modern/cssVars/getInitColorSchemeScript.js +21 -0
  46. package/modern/cssVars/index.js +1 -0
  47. package/modern/index.js +3 -2
  48. package/modern/spacing.js +2 -2
  49. package/modern/styleFunctionSx/styleFunctionSx.js +6 -6
  50. package/package.json +2 -2
  51. package/palette.js +1 -1
  52. package/positions.js +1 -1
  53. package/sizing.js +1 -1
  54. package/spacing.d.ts +12 -0
  55. package/spacing.js +5 -5
  56. package/style.d.ts +2 -2
  57. package/style.js +1 -1
  58. package/styleFunctionSx/styleFunctionSx.d.ts +8 -3
  59. package/styleFunctionSx/styleFunctionSx.js +6 -6
  60. package/typography.js +1 -1
  61. package/useTheme.js +1 -1
@@ -32,11 +32,11 @@ function styleFunctionSx(props) {
32
32
  return null;
33
33
  }
34
34
 
35
- if (typeof styles === 'function') {
36
- return styles(theme);
37
- }
35
+ var stylesObject = styles;
38
36
 
39
- if (_typeof(styles) !== 'object') {
37
+ if (typeof styles === 'function') {
38
+ stylesObject = styles(theme);
39
+ } else if (_typeof(styles) !== 'object') {
40
40
  // value
41
41
  return styles;
42
42
  }
@@ -44,8 +44,8 @@ function styleFunctionSx(props) {
44
44
  var emptyBreakpoints = createEmptyBreakpointObject(theme.breakpoints);
45
45
  var breakpointsKeys = Object.keys(emptyBreakpoints);
46
46
  var css = emptyBreakpoints;
47
- Object.keys(styles).forEach(function (styleKey) {
48
- var value = callIfFn(styles[styleKey], theme);
47
+ Object.keys(stylesObject).forEach(function (styleKey) {
48
+ var value = callIfFn(stylesObject[styleKey], theme);
49
49
 
50
50
  if (_typeof(value) === 'object') {
51
51
  if (propToStyleFunction[styleKey]) {
@@ -0,0 +1,188 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
+ import { formatMuiErrorMessage as _formatMuiErrorMessage } from "@mui/utils";
4
+ const _excluded = ["colorSchemes"],
5
+ _excluded2 = ["colorSchemes"];
6
+ import * as React from 'react';
7
+ import PropTypes from 'prop-types';
8
+ import { GlobalStyles } from '@mui/styled-engine';
9
+ import { deepmerge } from '@mui/utils';
10
+ import cssVarsParser from './cssVarsParser';
11
+ import getInitColorSchemeScript, { DEFAULT_ATTRIBUTE, DEFAULT_STORAGE_KEY } from './getInitColorSchemeScript';
12
+ import { jsx as _jsx } from "react/jsx-runtime";
13
+ import { jsxs as _jsxs } from "react/jsx-runtime";
14
+
15
+ const resolveMode = (key, fallback, supportedColorSchemes) => {
16
+ if (typeof window === 'undefined') {
17
+ return undefined;
18
+ }
19
+
20
+ let value;
21
+
22
+ try {
23
+ value = localStorage.getItem(key) || undefined;
24
+
25
+ if (!supportedColorSchemes.includes(value)) {
26
+ value = undefined;
27
+ }
28
+ } catch (e) {// Unsupported
29
+ }
30
+
31
+ return value || fallback;
32
+ };
33
+
34
+ export default function createCssVarsProvider(ThemeContext, options) {
35
+ const {
36
+ theme: baseTheme = {},
37
+ defaultColorScheme: designSystemColorScheme,
38
+ prefix: designSystemPrefix = ''
39
+ } = options;
40
+
41
+ if (!baseTheme.colorSchemes || !baseTheme.colorSchemes[designSystemColorScheme]) {
42
+ console.error(`MUI: \`${designSystemColorScheme}\` does not exist in \`theme.colorSchemes\`.`);
43
+ }
44
+
45
+ const ColorSchemeContext = /*#__PURE__*/React.createContext(undefined);
46
+
47
+ const useColorScheme = () => {
48
+ const value = React.useContext(ColorSchemeContext);
49
+
50
+ if (!value) {
51
+ throw new Error(process.env.NODE_ENV !== "production" ? `MUI: \`useColorScheme\` must be called under <CssVarsProvider />` : _formatMuiErrorMessage(19));
52
+ }
53
+
54
+ return value;
55
+ };
56
+
57
+ function CssVarsProvider({
58
+ children,
59
+ theme: themeProp = {},
60
+ prefix = designSystemPrefix,
61
+ storageKey = DEFAULT_STORAGE_KEY,
62
+ attribute = DEFAULT_ATTRIBUTE,
63
+ defaultColorScheme = designSystemColorScheme
64
+ }) {
65
+ const {
66
+ colorSchemes: baseColorSchemes = {}
67
+ } = baseTheme,
68
+ restBaseTheme = _objectWithoutPropertiesLoose(baseTheme, _excluded);
69
+
70
+ const {
71
+ colorSchemes: colorSchemesProp = {}
72
+ } = themeProp,
73
+ restThemeProp = _objectWithoutPropertiesLoose(themeProp, _excluded2);
74
+
75
+ let mergedTheme = deepmerge(restBaseTheme, restThemeProp);
76
+ const colorSchemes = deepmerge(baseColorSchemes, colorSchemesProp);
77
+ const allColorSchemes = Object.keys(colorSchemes);
78
+ const joinedColorSchemes = allColorSchemes.join(',');
79
+ const [colorScheme, setColorScheme] = React.useState(() => resolveMode(storageKey, defaultColorScheme, allColorSchemes));
80
+ const resolvedColorScheme = colorScheme || defaultColorScheme;
81
+ const {
82
+ css: rootCss,
83
+ vars: rootVars
84
+ } = cssVarsParser(mergedTheme, {
85
+ prefix
86
+ });
87
+ mergedTheme = _extends({}, mergedTheme, colorSchemes[resolvedColorScheme], {
88
+ vars: rootVars
89
+ });
90
+ const styleSheet = {};
91
+ Object.entries(colorSchemes).forEach(([key, scheme]) => {
92
+ const {
93
+ css,
94
+ vars
95
+ } = cssVarsParser(scheme, {
96
+ prefix
97
+ });
98
+
99
+ if (key === resolvedColorScheme) {
100
+ mergedTheme.vars = _extends({}, mergedTheme.vars, vars);
101
+ }
102
+
103
+ if (key === defaultColorScheme) {
104
+ styleSheet[':root'] = deepmerge(rootCss, css);
105
+ } else {
106
+ styleSheet[`[${attribute}="${key}"]`] = css;
107
+ }
108
+ });
109
+ React.useEffect(() => {
110
+ if (colorScheme) {
111
+ document.body.setAttribute(attribute, colorScheme);
112
+ localStorage.setItem(storageKey, colorScheme);
113
+ }
114
+ }, [colorScheme, attribute, storageKey]); // local storage modified in the context of another document
115
+
116
+ React.useEffect(() => {
117
+ const handleStorage = event => {
118
+ const storageColorScheme = event.newValue;
119
+
120
+ if (event.key === storageKey && joinedColorSchemes.match(storageColorScheme)) {
121
+ if (storageColorScheme) {
122
+ setColorScheme(storageColorScheme);
123
+ }
124
+ }
125
+ };
126
+
127
+ window.addEventListener('storage', handleStorage);
128
+ return () => window.removeEventListener('storage', handleStorage);
129
+ }, [setColorScheme, storageKey, joinedColorSchemes]);
130
+ const wrappedSetColorScheme = React.useCallback(val => {
131
+ if (typeof val === 'string' && !allColorSchemes.includes(val)) {
132
+ console.error(`\`${val}\` does not exist in \`theme.colorSchemes\`.`);
133
+ } else {
134
+ setColorScheme(val);
135
+ }
136
+ }, [setColorScheme, allColorSchemes]);
137
+ return /*#__PURE__*/_jsxs(ColorSchemeContext.Provider, {
138
+ value: {
139
+ colorScheme,
140
+ setColorScheme: wrappedSetColorScheme,
141
+ allColorSchemes
142
+ },
143
+ children: [/*#__PURE__*/_jsx(GlobalStyles, {
144
+ styles: styleSheet
145
+ }), /*#__PURE__*/_jsx(ThemeContext.Provider, {
146
+ value: mergedTheme,
147
+ children: children
148
+ })]
149
+ });
150
+ }
151
+
152
+ process.env.NODE_ENV !== "production" ? CssVarsProvider.propTypes = {
153
+ /**
154
+ * The body attribute name to attach colorScheme.
155
+ */
156
+ attribute: PropTypes.string,
157
+
158
+ /**
159
+ * Your component tree.
160
+ */
161
+ children: PropTypes.node,
162
+
163
+ /**
164
+ * The initial color scheme used.
165
+ */
166
+ defaultColorScheme: PropTypes.string,
167
+
168
+ /**
169
+ * css variable prefix
170
+ */
171
+ prefix: PropTypes.string,
172
+
173
+ /**
174
+ * The key in the local storage used to store current color scheme.
175
+ */
176
+ storageKey: PropTypes.string,
177
+
178
+ /**
179
+ * The calculated theme object that will be passed through context.
180
+ */
181
+ theme: PropTypes.object
182
+ } : void 0;
183
+ return {
184
+ CssVarsProvider,
185
+ useColorScheme,
186
+ getInitColorSchemeScript
187
+ };
188
+ }
@@ -0,0 +1,112 @@
1
+ /**
2
+ * This function create an object from keys, value and then assign to target
3
+ *
4
+ * @param {Object} obj : the target object to be assigned
5
+ * @param {string[]} keys
6
+ * @param {string | number} value
7
+ *
8
+ * @example
9
+ * const source = {}
10
+ * assignNestedKeys(source, ['palette', 'primary'], 'var(--palette-primary)')
11
+ * console.log(source) // { palette: { primary: 'var(--palette-primary)' } }
12
+ *
13
+ * @example
14
+ * const source = { palette: { primary: 'var(--palette-primary)' } }
15
+ * assignNestedKeys(source, ['palette', 'secondary'], 'var(--palette-secondary)')
16
+ * console.log(source) // { palette: { primary: 'var(--palette-primary)', secondary: 'var(--palette-secondary)' } }
17
+ */
18
+ export const assignNestedKeys = (obj, keys, value) => {
19
+ let temp = obj;
20
+ keys.forEach((k, index) => {
21
+ if (index === keys.length - 1) {
22
+ if (temp && typeof temp === 'object') {
23
+ temp[k] = value;
24
+ }
25
+ } else if (temp && typeof temp === 'object') {
26
+ if (!temp[k]) {
27
+ temp[k] = {};
28
+ }
29
+
30
+ temp = temp[k];
31
+ }
32
+ });
33
+ };
34
+ /**
35
+ *
36
+ * @param {Object} obj : source object
37
+ * @param {Function} callback : a function that will be called when
38
+ * - the deepest key in source object is reached
39
+ * - the value of the deepest key is NOT `undefined` | `null`
40
+ *
41
+ * @example
42
+ * walkObjectDeep({ palette: { primary: { main: '#000000' } } }, console.log)
43
+ * // ['palette', 'primary', 'main'] '#000000'
44
+ */
45
+
46
+ export const walkObjectDeep = (obj, callback) => {
47
+ function recurse(object, parentKeys = []) {
48
+ Object.entries(object).forEach(([key, value]) => {
49
+ if (value !== undefined && value !== null) {
50
+ if (typeof value === 'object' && Object.keys(value).length > 0) {
51
+ recurse(value, [...parentKeys, key]);
52
+ } else {
53
+ callback([...parentKeys, key], value);
54
+ }
55
+ }
56
+ });
57
+ }
58
+
59
+ recurse(obj);
60
+ };
61
+
62
+ const getCssValue = (keys, value) => {
63
+ if (typeof value === 'number') {
64
+ if (['lineHeight', 'fontWeight', 'opacity', 'zIndex'].some(prop => keys.includes(prop))) {
65
+ // css property that are unitless
66
+ return value;
67
+ }
68
+
69
+ return `${value}px`;
70
+ }
71
+
72
+ return value;
73
+ };
74
+ /**
75
+ * a function that parse theme and return { css, vars }
76
+ *
77
+ * @param {Object} theme
78
+ * @param {{ prefix?: string }} options
79
+ * @returns {{ css: Object, vars: Object }} `css` is the stylesheet, `vars` is an object to get css variable (same structure as theme)
80
+ *
81
+ * @example
82
+ * const { css, vars } = parser({
83
+ * fontSize: 12,
84
+ * lineHeight: 1.2,
85
+ * palette: { primary: { 500: '#000000' } }
86
+ * })
87
+ *
88
+ * console.log(css) // { '--fontSize': '12px', '--lineHeight': 1.2, '--palette-primary-500': '#000000' }
89
+ * console.log(vars) // { fontSize: '--fontSize', lineHeight: '--lineHeight', palette: { primary: { 500: 'var(--palette-primary-500)' } } }
90
+ */
91
+
92
+
93
+ export default function cssVarsParser(obj, options) {
94
+ const {
95
+ prefix
96
+ } = options || {};
97
+ const css = {};
98
+ const vars = {};
99
+ walkObjectDeep(obj, (keys, value) => {
100
+ if (typeof value === 'string' || typeof value === 'number') {
101
+ const cssVar = `--${prefix ? `${prefix}-` : ''}${keys.join('-')}`;
102
+ Object.assign(css, {
103
+ [cssVar]: getCssValue(keys, value)
104
+ });
105
+ assignNestedKeys(vars, keys, `var(${cssVar})`);
106
+ }
107
+ });
108
+ return {
109
+ css,
110
+ vars
111
+ };
112
+ }
@@ -0,0 +1,21 @@
1
+ import * as React from 'react';
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ export const DEFAULT_STORAGE_KEY = 'mui-color-scheme';
4
+ export const DEFAULT_ATTRIBUTE = 'data-mui-color-scheme';
5
+ export default function getInitColorSchemeScript(options) {
6
+ const {
7
+ storageKey = DEFAULT_STORAGE_KEY,
8
+ attribute = DEFAULT_ATTRIBUTE
9
+ } = options || {};
10
+ return /*#__PURE__*/_jsx("script", {
11
+ // eslint-disable-next-line react/no-danger
12
+ dangerouslySetInnerHTML: {
13
+ __html: `(function() { try {
14
+ var colorScheme = localStorage.getItem('${storageKey}');
15
+ if (colorScheme) {
16
+ document.body.setAttribute('${attribute}', colorScheme);
17
+ }
18
+ } catch (e) {} })();`
19
+ }
20
+ });
21
+ }
@@ -0,0 +1 @@
1
+ export { default } from './createCssVarsProvider';
package/modern/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license MUI v5.0.1
1
+ /** @license MUI v5.0.5
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.
@@ -41,4 +41,5 @@ export { default as useThemeProps, getThemeProps } from './useThemeProps';
41
41
  export { default as useTheme } from './useTheme';
42
42
  export { default as useThemeWithoutDefault } from './useThemeWithoutDefault';
43
43
  export * from './colorManipulator';
44
- export { default as ThemeProvider } from './ThemeProvider';
44
+ export { default as ThemeProvider } from './ThemeProvider';
45
+ export { default as unstable_createCssVarsProvider } from './cssVars/createCssVarsProvider';
package/modern/spacing.js CHANGED
@@ -39,8 +39,8 @@ const getCssProperties = memoize(prop => {
39
39
  const direction = directions[b] || '';
40
40
  return Array.isArray(direction) ? direction.map(dir => property + dir) : [property + direction];
41
41
  });
42
- const marginKeys = ['m', 'mt', 'mr', 'mb', 'ml', 'mx', 'my', 'margin', 'marginTop', 'marginRight', 'marginBottom', 'marginLeft', 'marginX', 'marginY'];
43
- const paddingKeys = ['p', 'pt', 'pr', 'pb', 'pl', 'px', 'py', 'padding', 'paddingTop', 'paddingRight', 'paddingBottom', 'paddingLeft', 'paddingX', 'paddingY'];
42
+ const marginKeys = ['m', 'mt', 'mr', 'mb', 'ml', 'mx', 'my', 'margin', 'marginTop', 'marginRight', 'marginBottom', 'marginLeft', 'marginX', 'marginY', 'marginInline', 'marginInlineStart', 'marginInlineEnd', 'marginBlock', 'marginBlockStart', 'marginBlockEnd'];
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
  const themeSpacing = getPath(theme, themeKey) || defaultValue;
@@ -22,11 +22,11 @@ function styleFunctionSx(props) {
22
22
  return null;
23
23
  }
24
24
 
25
- if (typeof styles === 'function') {
26
- return styles(theme);
27
- }
25
+ let stylesObject = styles;
28
26
 
29
- if (typeof styles !== 'object') {
27
+ if (typeof styles === 'function') {
28
+ stylesObject = styles(theme);
29
+ } else if (typeof styles !== 'object') {
30
30
  // value
31
31
  return styles;
32
32
  }
@@ -34,8 +34,8 @@ function styleFunctionSx(props) {
34
34
  const emptyBreakpoints = createEmptyBreakpointObject(theme.breakpoints);
35
35
  const breakpointsKeys = Object.keys(emptyBreakpoints);
36
36
  let css = emptyBreakpoints;
37
- Object.keys(styles).forEach(styleKey => {
38
- const value = callIfFn(styles[styleKey], theme);
37
+ Object.keys(stylesObject).forEach(styleKey => {
38
+ const value = callIfFn(stylesObject[styleKey], theme);
39
39
 
40
40
  if (typeof value === 'object') {
41
41
  if (propToStyleFunction[styleKey]) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/system",
3
- "version": "5.0.1",
3
+ "version": "5.0.5",
4
4
  "private": false,
5
5
  "author": "MUI Team",
6
6
  "description": "CSS utilities for rapidly laying out custom designs.",
@@ -26,7 +26,7 @@
26
26
  "url": "https://opencollective.com/material-ui"
27
27
  },
28
28
  "peerDependencies": {
29
- "@emotion/react": "^11.4.1",
29
+ "@emotion/react": "^11.5.0",
30
30
  "@emotion/styled": "^11.3.0",
31
31
  "@types/react": "^16.8.6 || ^17.0.0",
32
32
  "react": "^17.0.2"
package/palette.js CHANGED
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.default = exports.backgroundColor = exports.bgcolor = exports.color = void 0;
8
+ exports.default = exports.color = exports.bgcolor = exports.backgroundColor = void 0;
9
9
 
10
10
  var _style = _interopRequireDefault(require("./style"));
11
11
 
package/positions.js CHANGED
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.default = exports.left = exports.bottom = exports.right = exports.top = exports.zIndex = exports.position = void 0;
8
+ exports.zIndex = exports.top = exports.right = exports.position = exports.left = exports.default = exports.bottom = void 0;
9
9
 
10
10
  var _style = _interopRequireDefault(require("./style"));
11
11
 
package/sizing.js CHANGED
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.default = exports.boxSizing = exports.sizeHeight = exports.sizeWidth = exports.minHeight = exports.maxHeight = exports.height = exports.minWidth = exports.maxWidth = exports.width = void 0;
8
+ exports.width = exports.sizeWidth = exports.sizeHeight = exports.minWidth = exports.minHeight = exports.maxWidth = exports.maxHeight = exports.height = exports.default = exports.boxSizing = void 0;
9
9
 
10
10
  var _style = _interopRequireDefault(require("./style"));
11
11
 
package/spacing.d.ts CHANGED
@@ -25,6 +25,12 @@ export const margin: SimpleStyleFunction<
25
25
  | 'marginLeft'
26
26
  | 'marginX'
27
27
  | 'marginY'
28
+ | 'marginInline'
29
+ | 'marginInlineStart'
30
+ | 'marginInlineEnd'
31
+ | 'marginBlock'
32
+ | 'marginBlockStart'
33
+ | 'marginBlockEnd'
28
34
  >;
29
35
 
30
36
  export type MarginProps = PropsFor<typeof margin>;
@@ -44,6 +50,12 @@ export const padding: SimpleStyleFunction<
44
50
  | 'paddingLeft'
45
51
  | 'paddingX'
46
52
  | 'paddingY'
53
+ | 'paddingInline'
54
+ | 'paddingInlineStart'
55
+ | 'paddingInlineEnd'
56
+ | 'paddingBlock'
57
+ | 'paddingBlockStart'
58
+ | 'paddingBlockEnd'
47
59
  >;
48
60
 
49
61
  export type PaddingProps = PropsFor<typeof padding>;
package/spacing.js CHANGED
@@ -5,13 +5,13 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.createUnaryUnit = createUnaryUnit;
9
8
  exports.createUnarySpacing = createUnarySpacing;
10
- exports.getValue = getValue;
9
+ exports.createUnaryUnit = createUnaryUnit;
10
+ exports.default = void 0;
11
11
  exports.getStyleFromPropValue = getStyleFromPropValue;
12
+ exports.getValue = getValue;
12
13
  exports.margin = margin;
13
14
  exports.padding = padding;
14
- exports.default = void 0;
15
15
 
16
16
  var _responsivePropType = _interopRequireDefault(require("./responsivePropType"));
17
17
 
@@ -59,8 +59,8 @@ const getCssProperties = (0, _memoize.default)(prop => {
59
59
  const direction = directions[b] || '';
60
60
  return Array.isArray(direction) ? direction.map(dir => property + dir) : [property + direction];
61
61
  });
62
- const marginKeys = ['m', 'mt', 'mr', 'mb', 'ml', 'mx', 'my', 'margin', 'marginTop', 'marginRight', 'marginBottom', 'marginLeft', 'marginX', 'marginY'];
63
- const paddingKeys = ['p', 'pt', 'pr', 'pb', 'pl', 'px', 'py', 'padding', 'paddingTop', 'paddingRight', 'paddingBottom', 'paddingLeft', 'paddingX', 'paddingY'];
62
+ const marginKeys = ['m', 'mt', 'mr', 'mb', 'ml', 'mx', 'my', 'margin', 'marginTop', 'marginRight', 'marginBottom', 'marginLeft', 'marginX', 'marginY', 'marginInline', 'marginInlineStart', 'marginInlineEnd', 'marginBlock', 'marginBlockStart', 'marginBlockEnd'];
63
+ const paddingKeys = ['p', 'pt', 'pr', 'pb', 'pl', 'px', 'py', 'padding', 'paddingTop', 'paddingRight', 'paddingBottom', 'paddingLeft', 'paddingX', 'paddingY', 'paddingInline', 'paddingInlineStart', 'paddingInlineEnd', 'paddingBlock', 'paddingBlockStart', 'paddingBlockEnd'];
64
64
  const spacingKeys = [...marginKeys, ...paddingKeys];
65
65
 
66
66
  function createUnaryUnit(theme, themeKey, defaultValue, propName) {
package/style.d.ts CHANGED
@@ -1,5 +1,5 @@
1
+ import { CSSObject } from '@mui/styled-engine';
1
2
  import { StyleFunction } from './Box';
2
- import { CSSObject } from './createStyled';
3
3
 
4
4
  export interface StyleOptions<PropKey> {
5
5
  cssProperty?: PropKey | keyof React.CSSProperties | false;
@@ -12,4 +12,4 @@ export interface StyleOptions<PropKey> {
12
12
  }
13
13
  export function style<PropKey extends string, Theme extends object>(
14
14
  options: StyleOptions<PropKey>,
15
- ): StyleFunction<{ [K in PropKey]?: unknown } & { theme: Theme }>;
15
+ ): StyleFunction<{ [K in PropKey]?: unknown } & { theme?: Theme }>;
package/style.js CHANGED
@@ -5,8 +5,8 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.getPath = getPath;
9
8
  exports.default = void 0;
9
+ exports.getPath = getPath;
10
10
 
11
11
  var _utils = require("@mui/utils");
12
12
 
@@ -14,14 +14,14 @@ export type ResponsiveStyleValue<T> = T | Array<T | null> | { [key: string]: T |
14
14
  * Map of all CSS pseudo selectors (`:hover`, `:focus`, ...).
15
15
  */
16
16
  export type CSSPseudoSelectorProps<Theme extends object = {}> = {
17
- [K in CSS.Pseudos]?: SystemStyleObject<Theme>;
17
+ [K in CSS.Pseudos]?: ((theme: Theme) => SystemStyleObject<Theme>) | SystemStyleObject<Theme>;
18
18
  };
19
19
 
20
20
  /**
21
21
  * Map all nested selectors.
22
22
  */
23
23
  export interface CSSSelectorObject<Theme extends object = {}> {
24
- [cssSelector: string]: SystemStyleObject<Theme>;
24
+ [cssSelector: string]: ((theme: Theme) => SystemStyleObject<Theme>) | SystemStyleObject<Theme>;
25
25
  }
26
26
 
27
27
  /**
@@ -51,7 +51,12 @@ export type SystemStyleObject<Theme extends object = {}> =
51
51
  | CSSSelectorObject<Theme>
52
52
  | null;
53
53
 
54
- export type SxProps<Theme extends object = {}> = SystemStyleObject<Theme>;
54
+ /**
55
+ * The `SxProps` can be either object or function
56
+ */
57
+ export type SxProps<Theme extends object = {}> =
58
+ | SystemStyleObject<Theme>
59
+ | ((theme: Theme) => SystemStyleObject<Theme>);
55
60
 
56
61
  // eslint-disable-next-line @typescript-eslint/naming-convention
57
62
  export default function unstable_styleFunctionSx(props: object): object;
@@ -37,11 +37,11 @@ function styleFunctionSx(props) {
37
37
  return null;
38
38
  }
39
39
 
40
- if (typeof styles === 'function') {
41
- return styles(theme);
42
- }
40
+ let stylesObject = styles;
43
41
 
44
- if (typeof styles !== 'object') {
42
+ if (typeof styles === 'function') {
43
+ stylesObject = styles(theme);
44
+ } else if (typeof styles !== 'object') {
45
45
  // value
46
46
  return styles;
47
47
  }
@@ -49,8 +49,8 @@ function styleFunctionSx(props) {
49
49
  const emptyBreakpoints = (0, _breakpoints.createEmptyBreakpointObject)(theme.breakpoints);
50
50
  const breakpointsKeys = Object.keys(emptyBreakpoints);
51
51
  let css = emptyBreakpoints;
52
- Object.keys(styles).forEach(styleKey => {
53
- const value = callIfFn(styles[styleKey], theme);
52
+ Object.keys(stylesObject).forEach(styleKey => {
53
+ const value = callIfFn(stylesObject[styleKey], theme);
54
54
 
55
55
  if (typeof value === 'object') {
56
56
  if (_getThemeValue.propToStyleFunction[styleKey]) {
package/typography.js CHANGED
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.default = exports.typographyVariant = exports.textAlign = exports.lineHeight = exports.letterSpacing = exports.fontWeight = exports.fontStyle = exports.fontSize = exports.fontFamily = void 0;
8
+ exports.typographyVariant = exports.textAlign = exports.lineHeight = exports.letterSpacing = exports.fontWeight = exports.fontStyle = exports.fontSize = exports.fontFamily = exports.default = void 0;
9
9
 
10
10
  var _style = _interopRequireDefault(require("./style"));
11
11
 
package/useTheme.js CHANGED
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.default = exports.systemDefaultTheme = void 0;
8
+ exports.systemDefaultTheme = exports.default = void 0;
9
9
 
10
10
  var _createTheme = _interopRequireDefault(require("./createTheme"));
11
11