@mui/system 5.6.4 → 5.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Box/Box.spec.d.ts +1 -1
- package/CHANGELOG.md +101 -0
- package/ThemeProvider/ThemeProvider.d.ts +1 -1
- package/createBox.spec.d.ts +1 -1
- package/createTheme/createSpacing.d.ts +10 -10
- package/cssVars/createCssVarsProvider.d.ts +25 -0
- package/cssVars/createCssVarsProvider.js +54 -21
- package/cssVars/createCssVarsProvider.spec.d.ts +1 -1
- package/cssVars/createGetCssVar.d.ts +5 -5
- package/cssVars/cssVarsParser.d.ts +70 -70
- package/cssVars/getInitColorSchemeScript.d.ts +40 -12
- package/cssVars/getInitColorSchemeScript.js +4 -3
- package/cssVars/index.d.ts +2 -2
- package/cssVars/useCurrentColorScheme.d.ts +53 -50
- package/cssVars/useCurrentColorScheme.js +17 -7
- package/esm/cssVars/createCssVarsProvider.js +55 -22
- package/esm/cssVars/getInitColorSchemeScript.js +4 -3
- package/esm/cssVars/useCurrentColorScheme.js +17 -7
- package/index.js +1 -1
- package/index.spec.d.ts +1 -1
- package/legacy/cssVars/createCssVarsProvider.js +61 -24
- package/legacy/cssVars/getInitColorSchemeScript.js +6 -3
- package/legacy/cssVars/useCurrentColorScheme.js +20 -9
- package/legacy/index.js +1 -1
- package/modern/cssVars/createCssVarsProvider.js +55 -22
- package/modern/cssVars/getInitColorSchemeScript.js +4 -3
- package/modern/cssVars/useCurrentColorScheme.js +17 -7
- package/modern/index.js +1 -1
- package/package.json +5 -5
- package/styleFunctionSx/styleFunctionSx.spec.d.ts +1 -1
package/Box/Box.spec.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,106 @@
|
|
|
1
1
|
# [Versions](https://mui.com/versions/)
|
|
2
2
|
|
|
3
|
+
## 5.7.0
|
|
4
|
+
|
|
5
|
+
<!-- generated comparing v5.6.4..master -->
|
|
6
|
+
|
|
7
|
+
_May 10, 2022_
|
|
8
|
+
|
|
9
|
+
A big thanks to the 27 contributors who made this release possible. Here are some highlights ✨:
|
|
10
|
+
|
|
11
|
+
🛠 This release is all about supporting CSS variables in many Material UI components.
|
|
12
|
+
Kudos to all contributors!
|
|
13
|
+
|
|
14
|
+
### `@mui/material@5.7.0`
|
|
15
|
+
|
|
16
|
+
- [StepLabel, StepIcon] Add support for CSS variables (#32609) @vicasas
|
|
17
|
+
- [Table, TableRow] Add support for CSS variables (#32614) @vicasas
|
|
18
|
+
- [AppBar] Add a logo component for the responsive app bar demo (#32374) @ameetmadan
|
|
19
|
+
- [Autocomplete] Fix clearing single array values (#32626) @mikepricedev
|
|
20
|
+
- [Autocomplete] Fix keep listbox open on left/right keys when inputValue is not empty (#31407) @alisasanib
|
|
21
|
+
- [Autocomplete] Add support for CSS variables (#32598) @ZeeshanTamboli
|
|
22
|
+
- [Autocomplete] Render `endAdornment` only when necessary (#32386) @g1eny0ung
|
|
23
|
+
- [ButtonGroup] Add support for CSS variables (#32498) @vicasas
|
|
24
|
+
- [CardActionArea] Add support for CSS variables (#32554) @vicasas
|
|
25
|
+
- [ClickAwayListener] Allow pointer up/down events to event handler (#32264) @vladjerca
|
|
26
|
+
- [CssBaseline] Add support for CSS vars (#32618) @haneenmahd
|
|
27
|
+
- [Dialog] Add support for CSS variables (#32555) @vicasas
|
|
28
|
+
- [Divider] Add support for CSS variables (#32519) @vicasas
|
|
29
|
+
- [Drawer] Add support for CSS variables (#32565) @nghiamvt
|
|
30
|
+
- [Fab] Add support for CSS variables (#32564) @alisasanib
|
|
31
|
+
- [FormControlLabel] Add support for CSS variables (#32588) @elliefoote
|
|
32
|
+
- [FormHelperText] Add support for CSS variables (#32596) @ZeeshanTamboli
|
|
33
|
+
- [FormLabel] Add support for CSS variables (#32602) @ZeeshanTamboli
|
|
34
|
+
- [Icon] Add support for CSS variables (#32595) @Jamaalwbrown
|
|
35
|
+
- [IconButton] Add support for CSS variables (#32590) @Ariyapong
|
|
36
|
+
- [ImageListItemBar] Add support for CSS variables (#32578) @vicasas
|
|
37
|
+
- [Input] Support CSS variables (#32128) @ivan-ngchakming
|
|
38
|
+
- [InputAdornment] Add support CSS variables (#32607) @vicasas
|
|
39
|
+
- [Link] Fix style overrides color prop (#32653) @siriwatknp
|
|
40
|
+
- [ListItem] Add support for CSS variables (#32580) @dan-mba
|
|
41
|
+
- [ListItemButton] Add support for CSS variables (#32582) @dan-mba
|
|
42
|
+
- [ListItemIcon] Add support for CSS variables (#32583) @dan-mba
|
|
43
|
+
- [ListSubheader] Add support for CSS variables (#32584) @dan-mba
|
|
44
|
+
- [MenuItem] Add support for CSS variables (#32561) @nghiamvt
|
|
45
|
+
- [MobileStepper] Add support for CSS vars (#32606) @haneenmahd
|
|
46
|
+
- [Modal] Add support for CSS variables (#32605) @haneenmahd
|
|
47
|
+
- [PaginationItem] Add support for CSS vars (#32612) @haneenmahd
|
|
48
|
+
- [Rating] Add support for CSS variables (#32556) @vicasas
|
|
49
|
+
- [Snackbar] Add support for CSS variables (#32603) @gin1314
|
|
50
|
+
- [SpeedDial] Add support for CSS variables (#32613) @alisasanib
|
|
51
|
+
- [Stepper] Export useStepperContext (#31398) @pzi
|
|
52
|
+
- [SvgIcon] Add support for CSS variables (#32610) @vicasas
|
|
53
|
+
- [TablePagination] Add support for CSS variables (#32615) @haneenmahd
|
|
54
|
+
- [TableSortLabel]: Add support for CSS vars (#32616) @haneenmahd
|
|
55
|
+
- [Tabs] Add support for CSS variables (#32547) @ZeeshanTamboli
|
|
56
|
+
- [ToggleButton] Add support for CSS variables (#32600) @Ariyapong
|
|
57
|
+
- [ToggleButtonGroup] Add support for CSS variables (#32617) @haneenmahd
|
|
58
|
+
- [Tooltip] Add support for CSS variables (#32594) @gin1314
|
|
59
|
+
|
|
60
|
+
### `@mui/system@5.7.0`
|
|
61
|
+
|
|
62
|
+
- [System] Support CSS variables for iframes & custom nodes (#32496) @siriwatknp
|
|
63
|
+
|
|
64
|
+
### `@mui/base@5.0.0-alpha.80`
|
|
65
|
+
|
|
66
|
+
- [ButtonUnstyled] Fix keyboard navigation on customized elements (#32204) @michaldudak
|
|
67
|
+
|
|
68
|
+
### `@mui/private-classnames@5.7.0`
|
|
69
|
+
|
|
70
|
+
- [classnames] Add new package for classnames utils (#32502) @mnajdova
|
|
71
|
+
|
|
72
|
+
### Docs
|
|
73
|
+
|
|
74
|
+
- [docs] Correct links to prevent 301 redirects (#32692) @michaldudak
|
|
75
|
+
- [docs] Move, split, and revise "Unstyled components" page (#32562) @samuelsycamore
|
|
76
|
+
- [docs] Nest `ListItemButton` in `ListItem` in the Drawer examples (#31987) @stefanprobst
|
|
77
|
+
- [docs] Apply callouts in the Material UI docs (#32567) @danilo-leal
|
|
78
|
+
- [docs] Show product identifier on new X pages (#32657) @cherniavskii
|
|
79
|
+
- [docs] Fix copy button childNode not found (#32652) @siriwatknp
|
|
80
|
+
- [docs] Split install commands in isolated code blocks (#32566) @danilo-leal
|
|
81
|
+
- [docs] Base Switch style revisions and final review (#32376) @samuelsycamore
|
|
82
|
+
- [docs] Adds Badge link to Base doc nav (#32619) @samuelsycamore
|
|
83
|
+
- [docs] Base Installation style revisions and final review (#32483) @samuelsycamore
|
|
84
|
+
- [docs] Fix broken redirection (#32581) @oliviertassinari
|
|
85
|
+
- [docs] Allows to use `import '<library name>'` in demonstrations (#32492) @alexfauquette
|
|
86
|
+
- [docs] Hide copy button on search icon dialog (#32577) @siriwatknp
|
|
87
|
+
- [docs] Use full API link for ThemeProvider (#32549) @jcvidiri
|
|
88
|
+
- [Joy] Add principles page (#32648) @siriwatknp
|
|
89
|
+
- [Joy] Add Button page (#32576) @siriwatknp
|
|
90
|
+
- [Joy] Add "Quick start" and "Tutorial" pages (#32383) @siriwatknp
|
|
91
|
+
- [website] Add store to the footer and "hiring" chip adjustment (#32650) @danilo-leal
|
|
92
|
+
- [website] Optimize conversion to store (#32646) @oliviertassinari
|
|
93
|
+
- [website] Remove copy button on marketing pages (#32649) @siriwatknp
|
|
94
|
+
- [website] Add missing space in copy label (#32638) @flaviendelangle
|
|
95
|
+
|
|
96
|
+
### Core
|
|
97
|
+
|
|
98
|
+
- [core] Security updates (#32636) @michaldudak
|
|
99
|
+
- [core] Fix `docs:dev` not working after upgrading `next` to 12.1.0 (#32552) @cherniavskii
|
|
100
|
+
- [core] Update minimist to fix security vulnerability (#32575) @michaldudak
|
|
101
|
+
|
|
102
|
+
All contributors of this release in alphabetical order: @alexfauquette, @alisasanib, @ameetmadan, @Ariyapong, @cherniavskii, @dan-mba, @danilo-leal, @elliefoote, @flaviendelangle, @g1eny0ung, @gin1314, @haneenmahd, @ivan-ngchakming, @Jamaalwbrown, @jcvidiri, @michaldudak, @mikepricedev, @mnajdova, @nghiamvt, @oliviertassinari, @pzi, @samuelsycamore, @siriwatknp, @stefanprobst, @vicasas, @vladjerca, @ZeeshanTamboli
|
|
103
|
+
|
|
3
104
|
## 5.6.4
|
|
4
105
|
|
|
5
106
|
<!-- generated comparing v5.6.3..master -->
|
|
@@ -16,7 +16,7 @@ export interface ThemeProviderProps<Theme = DefaultTheme> {
|
|
|
16
16
|
* It should preferably be used at **the root of your component tree**.
|
|
17
17
|
* API:
|
|
18
18
|
*
|
|
19
|
-
* - [ThemeProvider API](/material-ui/customization/theming/#themeprovider)
|
|
19
|
+
* - [ThemeProvider API](https://mui.com/material-ui/customization/theming/#themeprovider)
|
|
20
20
|
*/
|
|
21
21
|
export default function ThemeProvider<T = DefaultTheme>(
|
|
22
22
|
props: ThemeProviderProps<T>,
|
package/createBox.spec.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
|
@@ -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;
|
|
@@ -51,6 +51,31 @@ export interface CreateCssVarsProviderResult<ColorScheme extends string, ThemeIn
|
|
|
51
51
|
* @default 'data-mui-color-scheme'
|
|
52
52
|
*/
|
|
53
53
|
attribute?: string;
|
|
54
|
+
/**
|
|
55
|
+
* The document used to perform `disableTransitionOnChange` feature
|
|
56
|
+
* @default document
|
|
57
|
+
*/
|
|
58
|
+
documentNode?: Document | null;
|
|
59
|
+
/**
|
|
60
|
+
* The node used to attach the color-scheme attribute
|
|
61
|
+
* @default document
|
|
62
|
+
*/
|
|
63
|
+
colorSchemeNode?: Document | HTMLElement | null;
|
|
64
|
+
/**
|
|
65
|
+
* The CSS selector for attaching the generated custom properties
|
|
66
|
+
* @default ':root'
|
|
67
|
+
*/
|
|
68
|
+
colorSchemeSelector?: string;
|
|
69
|
+
/**
|
|
70
|
+
* localStorage key used to store `colorScheme`
|
|
71
|
+
* @default 'mui-color-scheme'
|
|
72
|
+
*/
|
|
73
|
+
colorSchemeStorageKey?: string;
|
|
74
|
+
/**
|
|
75
|
+
* The window that attaches the 'storage' event listener
|
|
76
|
+
* @default window
|
|
77
|
+
*/
|
|
78
|
+
storageWindow?: Window | null;
|
|
54
79
|
}
|
|
55
80
|
>,
|
|
56
81
|
) => React.ReactElement;
|
|
@@ -74,11 +74,16 @@ function createCssVarsProvider(options) {
|
|
|
74
74
|
theme: themeProp = defaultTheme,
|
|
75
75
|
prefix = designSystemPrefix,
|
|
76
76
|
modeStorageKey = _getInitColorSchemeScript.DEFAULT_MODE_STORAGE_KEY,
|
|
77
|
+
colorSchemeStorageKey = _getInitColorSchemeScript.DEFAULT_COLOR_SCHEME_STORAGE_KEY,
|
|
77
78
|
attribute = _getInitColorSchemeScript.DEFAULT_ATTRIBUTE,
|
|
78
79
|
defaultMode = desisgnSystemMode,
|
|
79
80
|
defaultColorScheme = designSystemColorScheme,
|
|
80
81
|
disableTransitionOnChange = designSystemTransitionOnChange,
|
|
81
|
-
enableColorScheme = designSystemEnableColorScheme
|
|
82
|
+
enableColorScheme = designSystemEnableColorScheme,
|
|
83
|
+
storageWindow = typeof window === 'undefined' ? undefined : window,
|
|
84
|
+
documentNode = typeof document === 'undefined' ? undefined : document,
|
|
85
|
+
colorSchemeNode = typeof document === 'undefined' ? undefined : document.documentElement,
|
|
86
|
+
colorSchemeSelector = ':root'
|
|
82
87
|
}) {
|
|
83
88
|
const hasMounted = React.useRef(false);
|
|
84
89
|
const {
|
|
@@ -102,7 +107,9 @@ function createCssVarsProvider(options) {
|
|
|
102
107
|
defaultLightColorScheme,
|
|
103
108
|
defaultDarkColorScheme,
|
|
104
109
|
modeStorageKey,
|
|
105
|
-
|
|
110
|
+
colorSchemeStorageKey,
|
|
111
|
+
defaultMode,
|
|
112
|
+
storageWindow
|
|
106
113
|
});
|
|
107
114
|
|
|
108
115
|
const resolvedColorScheme = (() => {
|
|
@@ -172,54 +179,54 @@ function createCssVarsProvider(options) {
|
|
|
172
179
|
})();
|
|
173
180
|
|
|
174
181
|
if (key === resolvedDefaultColorScheme) {
|
|
175
|
-
styleSheet[
|
|
182
|
+
styleSheet[colorSchemeSelector] = css;
|
|
176
183
|
} else {
|
|
177
|
-
styleSheet[
|
|
184
|
+
styleSheet[`${colorSchemeSelector === ':root' ? '' : colorSchemeSelector}[${attribute}="${key}"]`] = css;
|
|
178
185
|
}
|
|
179
186
|
});
|
|
180
187
|
React.useEffect(() => {
|
|
181
|
-
if (colorScheme) {
|
|
188
|
+
if (colorScheme && colorSchemeNode) {
|
|
182
189
|
// attaches attribute to <html> because the css variables are attached to :root (html)
|
|
183
|
-
|
|
190
|
+
colorSchemeNode.setAttribute(attribute, colorScheme);
|
|
184
191
|
}
|
|
185
|
-
}, [colorScheme, attribute]);
|
|
192
|
+
}, [colorScheme, attribute, colorSchemeNode]);
|
|
186
193
|
(0, _utils.unstable_useEnhancedEffect)(() => {
|
|
187
|
-
if (!mode || !enableColorScheme) {
|
|
194
|
+
if (!mode || !enableColorScheme || !colorSchemeNode) {
|
|
188
195
|
return undefined;
|
|
189
196
|
}
|
|
190
197
|
|
|
191
|
-
const priorColorScheme =
|
|
198
|
+
const priorColorScheme = colorSchemeNode.style.getPropertyValue('color-scheme'); // `color-scheme` tells browser to render built-in elements according to its value: `light` or `dark`
|
|
192
199
|
|
|
193
200
|
if (mode === 'system') {
|
|
194
|
-
|
|
201
|
+
colorSchemeNode.style.setProperty('color-scheme', systemMode);
|
|
195
202
|
} else {
|
|
196
|
-
|
|
203
|
+
colorSchemeNode.style.setProperty('color-scheme', mode);
|
|
197
204
|
}
|
|
198
205
|
|
|
199
206
|
return () => {
|
|
200
|
-
|
|
207
|
+
colorSchemeNode.style.setProperty('color-scheme', priorColorScheme);
|
|
201
208
|
};
|
|
202
|
-
}, [mode, systemMode, enableColorScheme]);
|
|
209
|
+
}, [mode, systemMode, enableColorScheme, colorSchemeNode]);
|
|
203
210
|
React.useEffect(() => {
|
|
204
211
|
let timer;
|
|
205
212
|
|
|
206
|
-
if (disableTransitionOnChange && hasMounted.current) {
|
|
213
|
+
if (disableTransitionOnChange && hasMounted.current && documentNode) {
|
|
207
214
|
// credit: https://github.com/pacocoursey/next-themes/blob/b5c2bad50de2d61ad7b52a9c5cdc801a78507d7a/index.tsx#L313
|
|
208
|
-
const css =
|
|
209
|
-
css.appendChild(
|
|
210
|
-
|
|
215
|
+
const css = documentNode.createElement('style');
|
|
216
|
+
css.appendChild(documentNode.createTextNode(DISABLE_CSS_TRANSITION));
|
|
217
|
+
documentNode.head.appendChild(css); // Force browser repaint
|
|
211
218
|
|
|
212
|
-
(() => window.getComputedStyle(
|
|
219
|
+
(() => window.getComputedStyle(documentNode.body))();
|
|
213
220
|
|
|
214
221
|
timer = setTimeout(() => {
|
|
215
|
-
|
|
222
|
+
documentNode.head.removeChild(css);
|
|
216
223
|
}, 1);
|
|
217
224
|
}
|
|
218
225
|
|
|
219
226
|
return () => {
|
|
220
227
|
clearTimeout(timer);
|
|
221
228
|
};
|
|
222
|
-
}, [colorScheme, disableTransitionOnChange]);
|
|
229
|
+
}, [colorScheme, disableTransitionOnChange, documentNode]);
|
|
223
230
|
React.useEffect(() => {
|
|
224
231
|
hasMounted.current = true;
|
|
225
232
|
return () => {
|
|
@@ -238,7 +245,7 @@ function createCssVarsProvider(options) {
|
|
|
238
245
|
},
|
|
239
246
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_styledEngine.GlobalStyles, {
|
|
240
247
|
styles: {
|
|
241
|
-
|
|
248
|
+
[colorSchemeSelector]: rootCss
|
|
242
249
|
}
|
|
243
250
|
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_styledEngine.GlobalStyles, {
|
|
244
251
|
styles: styleSheet
|
|
@@ -260,6 +267,21 @@ function createCssVarsProvider(options) {
|
|
|
260
267
|
*/
|
|
261
268
|
children: _propTypes.default.node,
|
|
262
269
|
|
|
270
|
+
/**
|
|
271
|
+
* The node used to attach the color-scheme attribute
|
|
272
|
+
*/
|
|
273
|
+
colorSchemeNode: _propTypes.default.any,
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* The CSS selector for attaching the generated custom properties
|
|
277
|
+
*/
|
|
278
|
+
colorSchemeSelector: _propTypes.default.string,
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* localStorage key used to store `colorScheme`
|
|
282
|
+
*/
|
|
283
|
+
colorSchemeStorageKey: _propTypes.default.string,
|
|
284
|
+
|
|
263
285
|
/**
|
|
264
286
|
* The initial color scheme used.
|
|
265
287
|
*/
|
|
@@ -275,6 +297,11 @@ function createCssVarsProvider(options) {
|
|
|
275
297
|
*/
|
|
276
298
|
disableTransitionOnChange: _propTypes.default.bool,
|
|
277
299
|
|
|
300
|
+
/**
|
|
301
|
+
* The document to attach the attribute to
|
|
302
|
+
*/
|
|
303
|
+
documentNode: _propTypes.default.any,
|
|
304
|
+
|
|
278
305
|
/**
|
|
279
306
|
* Indicate to the browser which color scheme is used (light or dark) for rendering built-in UI
|
|
280
307
|
*/
|
|
@@ -290,6 +317,12 @@ function createCssVarsProvider(options) {
|
|
|
290
317
|
*/
|
|
291
318
|
prefix: _propTypes.default.string,
|
|
292
319
|
|
|
320
|
+
/**
|
|
321
|
+
* The window that attaches the 'storage' event listener
|
|
322
|
+
* @default window
|
|
323
|
+
*/
|
|
324
|
+
storageWindow: _propTypes.default.any,
|
|
325
|
+
|
|
293
326
|
/**
|
|
294
327
|
* The calculated theme object that will be passed through context.
|
|
295
328
|
*/
|
|
@@ -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;
|
|
@@ -1,70 +1,70 @@
|
|
|
1
|
-
declare type NestedRecord<V = any> = {
|
|
2
|
-
[k: string | number]: NestedRecord<V> | V;
|
|
3
|
-
};
|
|
4
|
-
/**
|
|
5
|
-
* This function create an object from keys, value and then assign to target
|
|
6
|
-
*
|
|
7
|
-
* @param {Object} obj : the target object to be assigned
|
|
8
|
-
* @param {string[]} keys
|
|
9
|
-
* @param {string | number} value
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* const source = {}
|
|
13
|
-
* assignNestedKeys(source, ['palette', 'primary'], 'var(--palette-primary)')
|
|
14
|
-
* console.log(source) // { palette: { primary: 'var(--palette-primary)' } }
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* const source = { palette: { primary: 'var(--palette-primary)' } }
|
|
18
|
-
* assignNestedKeys(source, ['palette', 'secondary'], 'var(--palette-secondary)')
|
|
19
|
-
* console.log(source) // { palette: { primary: 'var(--palette-primary)', secondary: 'var(--palette-secondary)' } }
|
|
20
|
-
*/
|
|
21
|
-
export declare const assignNestedKeys: <Object_1 = NestedRecord<any>, Value = any>(obj: Object_1, keys: Array<string>, value: Value, arrayKeys?: Array<string>) => void;
|
|
22
|
-
/**
|
|
23
|
-
*
|
|
24
|
-
* @param {Object} obj : source object
|
|
25
|
-
* @param {Function} callback : a function that will be called when
|
|
26
|
-
* - the deepest key in source object is reached
|
|
27
|
-
* - the value of the deepest key is NOT `undefined` | `null`
|
|
28
|
-
*
|
|
29
|
-
* @example
|
|
30
|
-
* walkObjectDeep({ palette: { primary: { main: '#000000' } } }, console.log)
|
|
31
|
-
* // ['palette', 'primary', 'main'] '#000000'
|
|
32
|
-
*/
|
|
33
|
-
export declare const walkObjectDeep: <Value, T = Record<string, any>>(obj: T, callback: (keys: Array<string>, value: Value, arrayKeys: Array<string>) => void, shouldSkipPaths?: ((keys: Array<string>) => boolean) | undefined) => void;
|
|
34
|
-
/**
|
|
35
|
-
* a function that parse theme and return { css, vars }
|
|
36
|
-
*
|
|
37
|
-
* @param {Object} theme
|
|
38
|
-
* @param {{
|
|
39
|
-
* prefix?: string,
|
|
40
|
-
* basePrefix?: string,
|
|
41
|
-
* shouldSkipGeneratingVar?: (objectPathKeys: Array<string>, value: string | number) => boolean
|
|
42
|
-
* }} options.
|
|
43
|
-
* `basePrefix`: defined by design system.
|
|
44
|
-
* `prefix`: defined by application
|
|
45
|
-
*
|
|
46
|
-
* the CSS variable value will be adjusted based on the provided `basePrefix` & `prefix` which can be found in `parsedTheme`.
|
|
47
|
-
*
|
|
48
|
-
* @returns {{ css: Object, vars: Object, parsedTheme: typeof theme }} `css` is the stylesheet, `vars` is an object to get css variable (same structure as theme), and `parsedTheme` is the cloned version of theme.
|
|
49
|
-
*
|
|
50
|
-
* @example
|
|
51
|
-
* const { css, vars, parsedTheme } = parser({
|
|
52
|
-
* fontSize: 12,
|
|
53
|
-
* lineHeight: 1.2,
|
|
54
|
-
* palette: { primary: { 500: 'var(--color)' } }
|
|
55
|
-
* }, { prefix: 'foo' })
|
|
56
|
-
*
|
|
57
|
-
* console.log(css) // { '--foo-fontSize': '12px', '--foo-lineHeight': 1.2, '--foo-palette-primary-500': 'var(--foo-color)' }
|
|
58
|
-
* console.log(vars) // { fontSize: '--foo-fontSize', lineHeight: '--foo-lineHeight', palette: { primary: { 500: 'var(--foo-palette-primary-500)' } } }
|
|
59
|
-
* console.log(parsedTheme) // { fontSize: 12, lineHeight: 1.2, palette: { primary: { 500: 'var(--foo-color)' } } }
|
|
60
|
-
*/
|
|
61
|
-
export default function cssVarsParser<T extends Record<string, any>>(theme: T, options?: {
|
|
62
|
-
prefix?: string;
|
|
63
|
-
basePrefix?: string;
|
|
64
|
-
shouldSkipGeneratingVar?: (objectPathKeys: Array<string>, value: string | number) => boolean;
|
|
65
|
-
}): {
|
|
66
|
-
css: NestedRecord<string>;
|
|
67
|
-
vars: NestedRecord<string>;
|
|
68
|
-
parsedTheme: T;
|
|
69
|
-
};
|
|
70
|
-
export {};
|
|
1
|
+
declare type NestedRecord<V = any> = {
|
|
2
|
+
[k: string | number]: NestedRecord<V> | V;
|
|
3
|
+
};
|
|
4
|
+
/**
|
|
5
|
+
* This function create an object from keys, value and then assign to target
|
|
6
|
+
*
|
|
7
|
+
* @param {Object} obj : the target object to be assigned
|
|
8
|
+
* @param {string[]} keys
|
|
9
|
+
* @param {string | number} value
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* const source = {}
|
|
13
|
+
* assignNestedKeys(source, ['palette', 'primary'], 'var(--palette-primary)')
|
|
14
|
+
* console.log(source) // { palette: { primary: 'var(--palette-primary)' } }
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* const source = { palette: { primary: 'var(--palette-primary)' } }
|
|
18
|
+
* assignNestedKeys(source, ['palette', 'secondary'], 'var(--palette-secondary)')
|
|
19
|
+
* console.log(source) // { palette: { primary: 'var(--palette-primary)', secondary: 'var(--palette-secondary)' } }
|
|
20
|
+
*/
|
|
21
|
+
export declare const assignNestedKeys: <Object_1 = NestedRecord<any>, Value = any>(obj: Object_1, keys: Array<string>, value: Value, arrayKeys?: Array<string>) => void;
|
|
22
|
+
/**
|
|
23
|
+
*
|
|
24
|
+
* @param {Object} obj : source object
|
|
25
|
+
* @param {Function} callback : a function that will be called when
|
|
26
|
+
* - the deepest key in source object is reached
|
|
27
|
+
* - the value of the deepest key is NOT `undefined` | `null`
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* walkObjectDeep({ palette: { primary: { main: '#000000' } } }, console.log)
|
|
31
|
+
* // ['palette', 'primary', 'main'] '#000000'
|
|
32
|
+
*/
|
|
33
|
+
export declare const walkObjectDeep: <Value, T = Record<string, any>>(obj: T, callback: (keys: Array<string>, value: Value, arrayKeys: Array<string>) => void, shouldSkipPaths?: ((keys: Array<string>) => boolean) | undefined) => void;
|
|
34
|
+
/**
|
|
35
|
+
* a function that parse theme and return { css, vars }
|
|
36
|
+
*
|
|
37
|
+
* @param {Object} theme
|
|
38
|
+
* @param {{
|
|
39
|
+
* prefix?: string,
|
|
40
|
+
* basePrefix?: string,
|
|
41
|
+
* shouldSkipGeneratingVar?: (objectPathKeys: Array<string>, value: string | number) => boolean
|
|
42
|
+
* }} options.
|
|
43
|
+
* `basePrefix`: defined by design system.
|
|
44
|
+
* `prefix`: defined by application
|
|
45
|
+
*
|
|
46
|
+
* the CSS variable value will be adjusted based on the provided `basePrefix` & `prefix` which can be found in `parsedTheme`.
|
|
47
|
+
*
|
|
48
|
+
* @returns {{ css: Object, vars: Object, parsedTheme: typeof theme }} `css` is the stylesheet, `vars` is an object to get css variable (same structure as theme), and `parsedTheme` is the cloned version of theme.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* const { css, vars, parsedTheme } = parser({
|
|
52
|
+
* fontSize: 12,
|
|
53
|
+
* lineHeight: 1.2,
|
|
54
|
+
* palette: { primary: { 500: 'var(--color)' } }
|
|
55
|
+
* }, { prefix: 'foo' })
|
|
56
|
+
*
|
|
57
|
+
* console.log(css) // { '--foo-fontSize': '12px', '--foo-lineHeight': 1.2, '--foo-palette-primary-500': 'var(--foo-color)' }
|
|
58
|
+
* console.log(vars) // { fontSize: '--foo-fontSize', lineHeight: '--foo-lineHeight', palette: { primary: { 500: 'var(--foo-palette-primary-500)' } } }
|
|
59
|
+
* console.log(parsedTheme) // { fontSize: 12, lineHeight: 1.2, palette: { primary: { 500: 'var(--foo-color)' } } }
|
|
60
|
+
*/
|
|
61
|
+
export default function cssVarsParser<T extends Record<string, any>>(theme: T, options?: {
|
|
62
|
+
prefix?: string;
|
|
63
|
+
basePrefix?: string;
|
|
64
|
+
shouldSkipGeneratingVar?: (objectPathKeys: Array<string>, value: string | number) => boolean;
|
|
65
|
+
}): {
|
|
66
|
+
css: NestedRecord<string>;
|
|
67
|
+
vars: NestedRecord<string>;
|
|
68
|
+
parsedTheme: T;
|
|
69
|
+
};
|
|
70
|
+
export {};
|
|
@@ -1,12 +1,40 @@
|
|
|
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
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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 interface GetInitColorSchemeScriptOptions {
|
|
6
|
+
/**
|
|
7
|
+
* If `true`, the initial color scheme is set to the user's prefers-color-scheme mode
|
|
8
|
+
* @default false
|
|
9
|
+
*/
|
|
10
|
+
enableSystem?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* The default color scheme to be used on the light mode
|
|
13
|
+
*/
|
|
14
|
+
defaultLightColorScheme?: string;
|
|
15
|
+
/**
|
|
16
|
+
* The default color scheme to be used on the dark mode
|
|
17
|
+
*/
|
|
18
|
+
defaultDarkColorScheme?: string;
|
|
19
|
+
/**
|
|
20
|
+
* The node (provided as string) used to attach the color-scheme attribute
|
|
21
|
+
* @default 'document.documentElement'
|
|
22
|
+
*/
|
|
23
|
+
colorSchemeNode?: string;
|
|
24
|
+
/**
|
|
25
|
+
* localStorage key used to store `mode`
|
|
26
|
+
* @default 'mui-mode'
|
|
27
|
+
*/
|
|
28
|
+
modeStorageKey?: string;
|
|
29
|
+
/**
|
|
30
|
+
* localStorage key used to store `colorScheme`
|
|
31
|
+
* @default 'mui-color-scheme'
|
|
32
|
+
*/
|
|
33
|
+
colorSchemeStorageKey?: string;
|
|
34
|
+
/**
|
|
35
|
+
* DOM attribute for applying color scheme
|
|
36
|
+
* @default 'data-mui-color-scheme'
|
|
37
|
+
*/
|
|
38
|
+
attribute?: string;
|
|
39
|
+
}
|
|
40
|
+
export default function getInitColorSchemeScript(options?: GetInitColorSchemeScriptOptions): JSX.Element;
|
|
@@ -23,12 +23,13 @@ exports.DEFAULT_ATTRIBUTE = DEFAULT_ATTRIBUTE;
|
|
|
23
23
|
|
|
24
24
|
function getInitColorSchemeScript(options) {
|
|
25
25
|
const {
|
|
26
|
-
enableSystem,
|
|
26
|
+
enableSystem = false,
|
|
27
27
|
defaultLightColorScheme = 'light',
|
|
28
28
|
defaultDarkColorScheme = 'dark',
|
|
29
29
|
modeStorageKey = DEFAULT_MODE_STORAGE_KEY,
|
|
30
30
|
colorSchemeStorageKey = DEFAULT_COLOR_SCHEME_STORAGE_KEY,
|
|
31
|
-
attribute = DEFAULT_ATTRIBUTE
|
|
31
|
+
attribute = DEFAULT_ATTRIBUTE,
|
|
32
|
+
colorSchemeNode = 'document.documentElement'
|
|
32
33
|
} = options || {};
|
|
33
34
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("script", {
|
|
34
35
|
// eslint-disable-next-line react/no-danger
|
|
@@ -52,7 +53,7 @@ function getInitColorSchemeScript(options) {
|
|
|
52
53
|
colorScheme = localStorage.getItem('${colorSchemeStorageKey}-dark') || '${defaultDarkColorScheme}';
|
|
53
54
|
}
|
|
54
55
|
if (colorScheme) {
|
|
55
|
-
|
|
56
|
+
${colorSchemeNode}.setAttribute('${attribute}', colorScheme);
|
|
56
57
|
}
|
|
57
58
|
} catch (e) {} })();`
|
|
58
59
|
}
|
package/cssVars/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { default } from './createCssVarsProvider';
|
|
2
|
-
export type { CreateCssVarsProviderResult } from './createCssVarsProvider';
|
|
1
|
+
export { default } from './createCssVarsProvider';
|
|
2
|
+
export type { CreateCssVarsProviderResult } from './createCssVarsProvider';
|