@mui/system 5.4.1 → 5.4.2
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 +1 -1
- package/Box/Box.spec.d.ts +1 -1
- package/CHANGELOG.md +65 -0
- package/createBox.d.ts +2 -0
- package/createBox.js +3 -2
- package/createBox.spec.d.ts +1 -1
- package/createStyled.d.ts +2 -1
- package/createStyled.js +7 -5
- package/createTheme/createBreakpoints.js +21 -6
- package/createTheme/createSpacing.d.ts +10 -10
- package/cssVars/createCssVarsProvider.d.ts +7 -0
- package/cssVars/createCssVarsProvider.js +4 -2
- package/cssVars/createCssVarsProvider.spec.d.ts +1 -1
- package/cssVars/createGetCssVar.d.ts +5 -5
- package/cssVars/createGetCssVar.js +7 -1
- package/cssVars/cssVarsParser.d.ts +68 -68
- package/cssVars/cssVarsParser.js +4 -3
- package/cssVars/getInitColorSchemeScript.d.ts +12 -12
- package/cssVars/index.d.ts +2 -2
- package/cssVars/useCurrentColorScheme.d.ts +50 -50
- package/esm/createBox.js +3 -2
- package/esm/createStyled.js +5 -3
- package/esm/createTheme/createBreakpoints.js +20 -4
- package/esm/cssVars/createCssVarsProvider.js +4 -2
- package/esm/cssVars/createGetCssVar.js +7 -1
- package/esm/cssVars/cssVarsParser.js +4 -3
- package/esm/getThemeValue.js +1 -1
- package/esm/index.js +1 -1
- package/esm/styleFunctionSx/index.js +1 -0
- package/esm/styleFunctionSx/styleFunctionSx.js +78 -51
- package/getThemeValue.js +2 -1
- package/index.d.ts +1 -0
- package/index.js +8 -1
- package/index.spec.d.ts +1 -1
- package/legacy/createBox.js +4 -2
- package/legacy/createStyled.js +6 -3
- package/legacy/createTheme/createBreakpoints.js +23 -4
- package/legacy/cssVars/createCssVarsProvider.js +4 -2
- package/legacy/cssVars/createGetCssVar.js +7 -1
- package/legacy/cssVars/cssVarsParser.js +4 -3
- package/legacy/getThemeValue.js +1 -1
- package/legacy/index.js +2 -2
- package/legacy/styleFunctionSx/index.js +1 -0
- package/legacy/styleFunctionSx/styleFunctionSx.js +76 -51
- package/modern/createBox.js +3 -2
- package/modern/createStyled.js +5 -3
- package/modern/createTheme/createBreakpoints.js +20 -4
- package/modern/cssVars/createCssVarsProvider.js +4 -2
- package/modern/cssVars/createGetCssVar.js +7 -1
- package/modern/cssVars/cssVarsParser.js +4 -3
- package/modern/getThemeValue.js +1 -1
- package/modern/index.js +2 -2
- package/modern/styleFunctionSx/index.js +1 -0
- package/modern/styleFunctionSx/styleFunctionSx.js +78 -51
- package/package.json +5 -5
- package/style.d.ts +1 -1
- package/styleFunctionSx/index.js +12 -2
- package/styleFunctionSx/styleFunctionSx.d.ts +12 -1
- package/styleFunctionSx/styleFunctionSx.js +79 -54
- package/styleFunctionSx/styleFunctionSx.spec.d.ts +1 -1
package/Box/Box.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export type PropsFor<SomeStyleFunction> = SomeStyleFunction extends StyleFunctio
|
|
|
15
15
|
export type StyleFunction<Props> = (props: Props) => any;
|
|
16
16
|
export type SimpleStyleFunction<PropKey extends keyof any> = StyleFunction<
|
|
17
17
|
Partial<Record<PropKey, any>>
|
|
18
|
-
|
|
18
|
+
> & { filterProps: string[] };
|
|
19
19
|
|
|
20
20
|
// borders.js
|
|
21
21
|
export const borders: SimpleStyleFunction<
|
package/Box/Box.spec.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,70 @@
|
|
|
1
1
|
# [Versions](https://mui.com/versions/)
|
|
2
2
|
|
|
3
|
+
## 5.4.2
|
|
4
|
+
|
|
5
|
+
_Feb 15, 2022_
|
|
6
|
+
|
|
7
|
+
A big thanks to the 16 contributors who made this release possible. Here are some highlights ✨:
|
|
8
|
+
|
|
9
|
+
- 🛠 @sydneyjodon-wk improved propTypes of the ToggleButton components (#30883)
|
|
10
|
+
- Several 🐛 bug fixes and 📚 documentation improvements
|
|
11
|
+
|
|
12
|
+
### `@mui/material@5.4.2`
|
|
13
|
+
|
|
14
|
+
- [Select] Allow customizing Select based on its variant (#30788) @michaldudak
|
|
15
|
+
- [Portal] Re-export 'Portal' in material (#31003) @liradb2000
|
|
16
|
+
- [ToggleButton] Add prop types for `onClick` and `onChange` (#30883) @sydneyjodon-wk
|
|
17
|
+
- [Typescript] Added TypeText declaration to the exports file (#30890) @agauravdev
|
|
18
|
+
|
|
19
|
+
### `@mui/system@5.4.2`
|
|
20
|
+
|
|
21
|
+
- [system] Fix broken behavior when breakpoints input are not ordered (#30996) @mnajdova
|
|
22
|
+
|
|
23
|
+
### `@mui/lab@5.0.0-alpha.69`
|
|
24
|
+
|
|
25
|
+
- [DatePicker] Fix passing clearable prop (#30786) @alisasanib
|
|
26
|
+
|
|
27
|
+
### `@mui/joy@5.0.0-alpha.15`
|
|
28
|
+
|
|
29
|
+
- [Joy] Improve variant customization experience (#30878) @siriwatknp
|
|
30
|
+
- [Joy] Make `sx` prop work in Joy (#30955) @siriwatknp
|
|
31
|
+
|
|
32
|
+
### Framer
|
|
33
|
+
|
|
34
|
+
- [design] Remove framer components (#30983) @mbrookes
|
|
35
|
+
- [design] Remove framer leftovers (#31070) @michaldudak
|
|
36
|
+
|
|
37
|
+
### Docs
|
|
38
|
+
|
|
39
|
+
- [docs] Update installation guide of the icons package (#31026) @huyenltnguyen
|
|
40
|
+
- [docs] Improve the indication for the legacy APIs (#30995) @mnajdova
|
|
41
|
+
- [docs] Specify which props are added in the default `shouldForwardProp` option (#30978) @mnajdova
|
|
42
|
+
- [docs] Fix layout shift on loading (#31017) @oliviertassinari
|
|
43
|
+
- [docs] Increase scroll affordance in wide tables (#30713) @danilo-leal
|
|
44
|
+
- [docs] Fix look & feel of the Masonry demos (#30971) @oliviertassinari
|
|
45
|
+
- [docs] Improve Base component demos (#30884) @danilo-leal
|
|
46
|
+
- [docs] Use full product names (Material UI, MUI System) (#30960) @oliviertassinari
|
|
47
|
+
- [docs] Prefer useEnhancedEffect to avoid server side warnings (#30977) @mnajdova
|
|
48
|
+
- [docs] Fix force redirection to a different locale (#30967) @oliviertassinari
|
|
49
|
+
- [docs] Add live Tailwind CSS demo (#30966) @oliviertassinari
|
|
50
|
+
- [website] Add banner for promoting priority open roles (#31076) @danilo-leal
|
|
51
|
+
- [website] Open Full-stack Engineer role for studio (#31038) @newguy-123
|
|
52
|
+
- [website] Minor security improvements (#31062) @oliviertassinari
|
|
53
|
+
- [website] Improve title of open roles (#30963) @DanailH
|
|
54
|
+
- [website] Add BIMI avatar (#30444) @oliviertassinari
|
|
55
|
+
- [website] Add Sycamore to About page (#31000) @samuelsycamore
|
|
56
|
+
|
|
57
|
+
### Core
|
|
58
|
+
|
|
59
|
+
- [benchmark] Add missing dependency (#30994) @michaldudak
|
|
60
|
+
- [core] Bump date-io version (#31016) @michaldudak
|
|
61
|
+
- [core] Fix typo in useSlider (#31061) @ryohey
|
|
62
|
+
- [core] Remove unused draft-js types package (#30993) @michaldudak
|
|
63
|
+
- [test] Test if certain Base members are exported from Material UI (#31067) @michaldudak
|
|
64
|
+
- [core] Remove dead code (#31064) @oliviertassinari
|
|
65
|
+
|
|
66
|
+
All contributors of this release in alphabetical order: @agauravdev, @alisasanib, @DanailH, @danilo-leal, @huyenltnguyen, @l10nbot, @liradb2000, @mbrookes, @michaldudak, @mnajdova, @newguy-123, @oliviertassinari, @ryohey, @samuelsycamore, @siriwatknp, @sydneyjodon-wk
|
|
67
|
+
|
|
3
68
|
## 5.4.1
|
|
4
69
|
|
|
5
70
|
<!-- generated comparing v5.4.0..master -->
|
package/createBox.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import Box from './Box';
|
|
2
|
+
import styleFunctionSx from './styleFunctionSx';
|
|
2
3
|
|
|
3
4
|
export default function createBox(options?: {
|
|
4
5
|
defaultTheme: object;
|
|
5
6
|
defaultClassName?: string;
|
|
6
7
|
generateClassName?: (componentName: string) => string;
|
|
8
|
+
styleFunctionSx?: typeof styleFunctionSx;
|
|
7
9
|
}): typeof Box;
|
package/createBox.js
CHANGED
|
@@ -35,9 +35,10 @@ function createBox(options = {}) {
|
|
|
35
35
|
const {
|
|
36
36
|
defaultTheme,
|
|
37
37
|
defaultClassName = 'MuiBox-root',
|
|
38
|
-
generateClassName
|
|
38
|
+
generateClassName,
|
|
39
|
+
styleFunctionSx = _styleFunctionSx.default
|
|
39
40
|
} = options;
|
|
40
|
-
const BoxRoot = (0, _styledEngine.default)('div')(
|
|
41
|
+
const BoxRoot = (0, _styledEngine.default)('div')(styleFunctionSx);
|
|
41
42
|
const Box = /*#__PURE__*/React.forwardRef(function Box(inProps, ref) {
|
|
42
43
|
const theme = (0, _useTheme.default)(defaultTheme);
|
|
43
44
|
|
package/createBox.spec.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
package/createStyled.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
CreateMUIStyled as CreateMUIStyledStyledEngine,
|
|
4
4
|
CSSInterpolation,
|
|
5
5
|
} from '@mui/styled-engine';
|
|
6
|
-
import { SxProps } from './styleFunctionSx';
|
|
6
|
+
import styleFunctionSx, { SxProps } from './styleFunctionSx';
|
|
7
7
|
import { Theme as DefaultTheme } from './createTheme';
|
|
8
8
|
|
|
9
9
|
export function shouldForwardProp(propName: PropertyKey): boolean;
|
|
@@ -34,4 +34,5 @@ export default function createStyled<T extends object = DefaultTheme>(options?:
|
|
|
34
34
|
defaultTheme?: T;
|
|
35
35
|
rootShouldForwardProp?: (prop: PropertyKey) => boolean;
|
|
36
36
|
slotShouldForwardProp?: (prop: PropertyKey) => boolean;
|
|
37
|
+
styleFunctionSx?: typeof styleFunctionSx;
|
|
37
38
|
}): CreateMUIStyled<T>;
|
package/createStyled.js
CHANGED
|
@@ -19,10 +19,10 @@ var _utils = require("@mui/utils");
|
|
|
19
19
|
|
|
20
20
|
var _createTheme = _interopRequireDefault(require("./createTheme"));
|
|
21
21
|
|
|
22
|
-
var _styleFunctionSx = _interopRequireDefault(require("./styleFunctionSx"));
|
|
23
|
-
|
|
24
22
|
var _propsToClassKey = _interopRequireDefault(require("./propsToClassKey"));
|
|
25
23
|
|
|
24
|
+
var _styleFunctionSx = _interopRequireDefault(require("./styleFunctionSx"));
|
|
25
|
+
|
|
26
26
|
const _excluded = ["name", "slot", "skipVariantsResolver", "skipSx", "overridesResolver"],
|
|
27
27
|
_excluded2 = ["theme"],
|
|
28
28
|
_excluded3 = ["theme"];
|
|
@@ -79,7 +79,8 @@ const variantsResolver = (props, styles, theme, name) => {
|
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
return variantsStyles;
|
|
82
|
-
};
|
|
82
|
+
}; // Update /system/styled/#api in case if this changes
|
|
83
|
+
|
|
83
84
|
|
|
84
85
|
function shouldForwardProp(prop) {
|
|
85
86
|
return prop !== 'ownerState' && prop !== 'theme' && prop !== 'sx' && prop !== 'as';
|
|
@@ -96,7 +97,8 @@ function createStyled(input = {}) {
|
|
|
96
97
|
const {
|
|
97
98
|
defaultTheme = systemDefaultTheme,
|
|
98
99
|
rootShouldForwardProp = shouldForwardProp,
|
|
99
|
-
slotShouldForwardProp = shouldForwardProp
|
|
100
|
+
slotShouldForwardProp = shouldForwardProp,
|
|
101
|
+
styleFunctionSx = _styleFunctionSx.default
|
|
100
102
|
} = input;
|
|
101
103
|
return (tag, inputOptions = {}) => {
|
|
102
104
|
const {
|
|
@@ -177,7 +179,7 @@ function createStyled(input = {}) {
|
|
|
177
179
|
if (!skipSx) {
|
|
178
180
|
expressionsWithDefaultTheme.push(props => {
|
|
179
181
|
const theme = isEmpty(props.theme) ? defaultTheme : props.theme;
|
|
180
|
-
return (
|
|
182
|
+
return styleFunctionSx((0, _extends2.default)({}, props, {
|
|
181
183
|
theme
|
|
182
184
|
}));
|
|
183
185
|
});
|
|
@@ -8,17 +8,31 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
8
8
|
exports.breakpointKeys = void 0;
|
|
9
9
|
exports.default = createBreakpoints;
|
|
10
10
|
|
|
11
|
-
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
12
|
-
|
|
13
11
|
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
|
|
14
12
|
|
|
13
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
14
|
+
|
|
15
15
|
const _excluded = ["values", "unit", "step"];
|
|
16
16
|
// Sorted ASC by size. That's important.
|
|
17
17
|
// It can't be configured as it's used statically for propTypes.
|
|
18
|
-
const breakpointKeys = ['xs', 'sm', 'md', 'lg', 'xl'];
|
|
19
|
-
|
|
18
|
+
const breakpointKeys = ['xs', 'sm', 'md', 'lg', 'xl'];
|
|
20
19
|
exports.breakpointKeys = breakpointKeys;
|
|
21
20
|
|
|
21
|
+
const sortBreakpointsValues = values => {
|
|
22
|
+
const breakpointsAsArray = Object.keys(values).map(key => ({
|
|
23
|
+
key,
|
|
24
|
+
val: values[key]
|
|
25
|
+
})) || []; // Sort in ascending order
|
|
26
|
+
|
|
27
|
+
breakpointsAsArray.sort((breakpoint1, breakpoint2) => breakpoint1.val - breakpoint2.val);
|
|
28
|
+
return breakpointsAsArray.reduce((acc, obj) => {
|
|
29
|
+
return (0, _extends2.default)({}, acc, {
|
|
30
|
+
[obj.key]: obj.val
|
|
31
|
+
});
|
|
32
|
+
}, {});
|
|
33
|
+
}; // Keep in mind that @media is inclusive by the CSS specification.
|
|
34
|
+
|
|
35
|
+
|
|
22
36
|
function createBreakpoints(breakpoints) {
|
|
23
37
|
const {
|
|
24
38
|
// The breakpoint **start** at this value.
|
|
@@ -39,7 +53,8 @@ function createBreakpoints(breakpoints) {
|
|
|
39
53
|
step = 5
|
|
40
54
|
} = breakpoints,
|
|
41
55
|
other = (0, _objectWithoutPropertiesLoose2.default)(breakpoints, _excluded);
|
|
42
|
-
const
|
|
56
|
+
const sortedValues = sortBreakpointsValues(values);
|
|
57
|
+
const keys = Object.keys(sortedValues);
|
|
43
58
|
|
|
44
59
|
function up(key) {
|
|
45
60
|
const value = typeof values[key] === 'number' ? values[key] : key;
|
|
@@ -81,7 +96,7 @@ function createBreakpoints(breakpoints) {
|
|
|
81
96
|
|
|
82
97
|
return (0, _extends2.default)({
|
|
83
98
|
keys,
|
|
84
|
-
values,
|
|
99
|
+
values: sortedValues,
|
|
85
100
|
up,
|
|
86
101
|
down,
|
|
87
102
|
between,
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export declare type SpacingOptions = number | Spacing | ((abs: number) => number | string) | ((abs: number | string) => number | string) | ReadonlyArray<string | number>;
|
|
2
|
-
export declare type SpacingArgument = number | string;
|
|
3
|
-
export interface Spacing {
|
|
4
|
-
(): string;
|
|
5
|
-
(value: number): string;
|
|
6
|
-
(topBottom: SpacingArgument, rightLeft: SpacingArgument): string;
|
|
7
|
-
(top: SpacingArgument, rightLeft: SpacingArgument, bottom: SpacingArgument): string;
|
|
8
|
-
(top: SpacingArgument, right: SpacingArgument, bottom: SpacingArgument, left: SpacingArgument): string;
|
|
9
|
-
}
|
|
10
|
-
export default function createSpacing(spacingInput?: SpacingOptions): Spacing;
|
|
1
|
+
export declare type SpacingOptions = number | Spacing | ((abs: number) => number | string) | ((abs: number | string) => number | string) | ReadonlyArray<string | number>;
|
|
2
|
+
export declare type SpacingArgument = number | string;
|
|
3
|
+
export interface Spacing {
|
|
4
|
+
(): string;
|
|
5
|
+
(value: number): string;
|
|
6
|
+
(topBottom: SpacingArgument, rightLeft: SpacingArgument): string;
|
|
7
|
+
(top: SpacingArgument, rightLeft: SpacingArgument, bottom: SpacingArgument): string;
|
|
8
|
+
(top: SpacingArgument, right: SpacingArgument, bottom: SpacingArgument, left: SpacingArgument): string;
|
|
9
|
+
}
|
|
10
|
+
export default function createSpacing(spacingInput?: SpacingOptions): Spacing;
|
|
@@ -97,6 +97,13 @@ export default function createCssVarsProvider<
|
|
|
97
97
|
* value = 'var(--test)'
|
|
98
98
|
*/
|
|
99
99
|
shouldSkipGeneratingVar?: (keys: string[], value: string | number) => boolean;
|
|
100
|
+
/**
|
|
101
|
+
* A function to be called after the CSS variables are attached. The result of this function will be the final theme pass to ThemeProvider.
|
|
102
|
+
*
|
|
103
|
+
* The example usage is the variant generation in Joy. We need to combine the token from user-input and the default theme first, then generate
|
|
104
|
+
* variants from those tokens.
|
|
105
|
+
*/
|
|
106
|
+
resolveTheme?: (theme: any) => any; // the type is any because it depends on the design system.
|
|
100
107
|
}): {
|
|
101
108
|
CssVarsProvider: (
|
|
102
109
|
props: React.PropsWithChildren<
|
|
@@ -57,7 +57,8 @@ function createCssVarsProvider(options) {
|
|
|
57
57
|
disableTransitionOnChange = false,
|
|
58
58
|
enableColorScheme = true,
|
|
59
59
|
prefix: designSystemPrefix = '',
|
|
60
|
-
shouldSkipGeneratingVar
|
|
60
|
+
shouldSkipGeneratingVar,
|
|
61
|
+
resolveTheme
|
|
61
62
|
} = options;
|
|
62
63
|
const systemSpacing = (0, _createSpacing.default)(baseTheme.spacing);
|
|
63
64
|
const systemBreakpoints = (0, _createBreakpoints.default)((_baseTheme$breakpoint = baseTheme.breakpoints) != null ? _baseTheme$breakpoint : {});
|
|
@@ -151,6 +152,7 @@ function createCssVarsProvider(options) {
|
|
|
151
152
|
mergedTheme = (0, _extends2.default)({}, mergedTheme, colorSchemes[resolvedColorScheme], {
|
|
152
153
|
components,
|
|
153
154
|
colorSchemes,
|
|
155
|
+
prefix,
|
|
154
156
|
vars: rootVars,
|
|
155
157
|
spacing: themeProp.spacing ? (0, _createSpacing.default)(themeProp.spacing) : systemSpacing,
|
|
156
158
|
breakpoints: themeProp.breakpoints ? (0, _createBreakpoints.default)(themeProp.breakpoints) : systemBreakpoints,
|
|
@@ -252,7 +254,7 @@ function createCssVarsProvider(options) {
|
|
|
252
254
|
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_styledEngine.GlobalStyles, {
|
|
253
255
|
styles: styleSheet
|
|
254
256
|
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ThemeProvider.default, {
|
|
255
|
-
theme: mergedTheme,
|
|
257
|
+
theme: resolveTheme ? resolveTheme(mergedTheme) : mergedTheme,
|
|
256
258
|
children: children
|
|
257
259
|
})]
|
|
258
260
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The benefit of this function is to help developers get CSS var from theme without specifying the whole variable
|
|
3
|
-
* and they does not need to remember the prefix (defined once).
|
|
4
|
-
*/
|
|
5
|
-
export default function createGetCssVar<T extends string = string>(prefix?: string): <AdditionalVars extends string = never>(field: T | AdditionalVars, ...vars: (T | AdditionalVars)[]) => string;
|
|
1
|
+
/**
|
|
2
|
+
* The benefit of this function is to help developers get CSS var from theme without specifying the whole variable
|
|
3
|
+
* and they does not need to remember the prefix (defined once).
|
|
4
|
+
*/
|
|
5
|
+
export default function createGetCssVar<T extends string = string>(prefix?: string): <AdditionalVars extends string = never>(field: T | AdditionalVars, ...vars: (T | AdditionalVars)[]) => string;
|
|
@@ -15,7 +15,13 @@ function createGetCssVar(prefix = '') {
|
|
|
15
15
|
return '';
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
const value = vars[0];
|
|
19
|
+
|
|
20
|
+
if (typeof value === 'string' && !value.match(/(#|\(|\)|(-?(\d*\.)?\d+)(px|em|%|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc))/)) {
|
|
21
|
+
return `, var(--${prefix ? `${prefix}-` : ''}${value}${appendVar(...vars.slice(1))})`;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return `, ${value}`;
|
|
19
25
|
} // AdditionalVars makes `getCssVar` less strict, so it can be use like this `getCssVar('non-mui-variable')` without type error.
|
|
20
26
|
|
|
21
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 {};
|
package/cssVars/cssVarsParser.js
CHANGED
|
@@ -127,12 +127,13 @@ function cssVarsParser(theme, options) {
|
|
|
127
127
|
if (typeof val === 'string' || typeof val === 'number') {
|
|
128
128
|
let value = val;
|
|
129
129
|
|
|
130
|
-
if (typeof value === 'string' && value.
|
|
130
|
+
if (typeof value === 'string' && value.match(/var\(\s*--/)) {
|
|
131
131
|
// replace the value of the `scope` object with the prefix or remove basePrefix from the value
|
|
132
132
|
if (!basePrefix && prefix) {
|
|
133
|
-
value = value.replace(/var\(
|
|
133
|
+
value = value.replace(/var\(\s*--/g, `var(--${prefix}-`);
|
|
134
134
|
} else {
|
|
135
|
-
value = prefix ? value.replace(new RegExp(basePrefix
|
|
135
|
+
value = prefix ? value.replace(new RegExp(`var\\(\\s*--${basePrefix}`, 'g'), `var(--${prefix}`) // removing spaces
|
|
136
|
+
: value.replace(new RegExp(`var\\(\\s*--${basePrefix}-`, 'g'), 'var(--');
|
|
136
137
|
} // scope is the deepest object in the tree, keys is the theme path keys
|
|
137
138
|
|
|
138
139
|
|
|
@@ -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>;
|
package/esm/createBox.js
CHANGED
|
@@ -5,14 +5,15 @@ import * as React from 'react';
|
|
|
5
5
|
import PropTypes from 'prop-types';
|
|
6
6
|
import clsx from 'clsx';
|
|
7
7
|
import styled from '@mui/styled-engine';
|
|
8
|
-
import
|
|
8
|
+
import defaultStyleFunctionSx, { extendSxProp } from './styleFunctionSx';
|
|
9
9
|
import useTheme from './useTheme';
|
|
10
10
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
11
|
export default function createBox(options = {}) {
|
|
12
12
|
const {
|
|
13
13
|
defaultTheme,
|
|
14
14
|
defaultClassName = 'MuiBox-root',
|
|
15
|
-
generateClassName
|
|
15
|
+
generateClassName,
|
|
16
|
+
styleFunctionSx = defaultStyleFunctionSx
|
|
16
17
|
} = options;
|
|
17
18
|
const BoxRoot = styled('div')(styleFunctionSx);
|
|
18
19
|
const Box = /*#__PURE__*/React.forwardRef(function Box(inProps, ref) {
|