@mui/system 7.0.0-beta.2 → 7.0.0-beta.4
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/CHANGELOG.md +80 -0
- package/borders/borders.d.ts +3 -2
- package/cssGrid/cssGrid.d.ts +15 -2
- package/cssVars/createCssVarsProvider.d.ts +12 -0
- package/cssVars/createCssVarsProvider.js +21 -4
- package/cssVars/index.d.ts +2 -1
- package/cssVars/localStorageManager.d.ts +34 -0
- package/cssVars/localStorageManager.js +57 -0
- package/cssVars/useCurrentColorScheme.d.ts +2 -0
- package/cssVars/useCurrentColorScheme.js +50 -69
- package/display/display.d.ts +2 -1
- package/esm/borders/borders.d.ts +3 -2
- package/esm/cssGrid/cssGrid.d.ts +15 -2
- package/esm/cssVars/createCssVarsProvider.d.ts +12 -0
- package/esm/cssVars/createCssVarsProvider.js +21 -4
- package/esm/cssVars/index.d.ts +2 -1
- package/esm/cssVars/localStorageManager.d.ts +34 -0
- package/esm/cssVars/localStorageManager.js +51 -0
- package/esm/cssVars/useCurrentColorScheme.d.ts +2 -0
- package/esm/cssVars/useCurrentColorScheme.js +49 -69
- package/esm/display/display.d.ts +2 -1
- package/esm/flexbox/flexbox.d.ts +2 -1
- package/esm/index.d.ts +1 -0
- package/esm/index.js +1 -1
- package/esm/palette/palette.d.ts +2 -1
- package/esm/positions/positions.d.ts +2 -1
- package/esm/shadows/shadows.d.ts +2 -1
- package/esm/sizing/sizing.d.ts +2 -1
- package/esm/spacing/spacing.d.ts +2 -1
- package/esm/spacing/spacing.js +9 -0
- package/esm/style/style.d.ts +4 -4
- package/esm/typography/typography.d.ts +2 -1
- package/esm/version/index.js +2 -2
- package/flexbox/flexbox.d.ts +2 -1
- package/index.d.ts +1 -0
- package/index.js +1 -1
- package/modern/borders/borders.d.ts +3 -2
- package/modern/cssGrid/cssGrid.d.ts +15 -2
- package/modern/cssVars/createCssVarsProvider.d.ts +12 -0
- package/modern/cssVars/createCssVarsProvider.js +21 -4
- package/modern/cssVars/index.d.ts +2 -1
- package/modern/cssVars/localStorageManager.d.ts +34 -0
- package/modern/cssVars/localStorageManager.js +51 -0
- package/modern/cssVars/useCurrentColorScheme.d.ts +2 -0
- package/modern/cssVars/useCurrentColorScheme.js +49 -69
- package/modern/display/display.d.ts +2 -1
- package/modern/flexbox/flexbox.d.ts +2 -1
- package/modern/index.d.ts +1 -0
- package/modern/index.js +1 -1
- package/modern/palette/palette.d.ts +2 -1
- package/modern/positions/positions.d.ts +2 -1
- package/modern/shadows/shadows.d.ts +2 -1
- package/modern/sizing/sizing.d.ts +2 -1
- package/modern/spacing/spacing.d.ts +2 -1
- package/modern/spacing/spacing.js +9 -0
- package/modern/style/style.d.ts +4 -4
- package/modern/typography/typography.d.ts +2 -1
- package/modern/version/index.js +2 -2
- package/package.json +5 -5
- package/palette/palette.d.ts +2 -1
- package/positions/positions.d.ts +2 -1
- package/shadows/shadows.d.ts +2 -1
- package/sizing/sizing.d.ts +2 -1
- package/spacing/spacing.d.ts +2 -1
- package/spacing/spacing.js +9 -0
- package/style/style.d.ts +4 -4
- package/tsconfig.build.tsbuildinfo +1 -1
- package/typography/typography.d.ts +2 -1
- package/version/index.js +2 -2
|
@@ -50,12 +50,14 @@ export default function createCssVarsProvider(options) {
|
|
|
50
50
|
modeStorageKey = defaultModeStorageKey,
|
|
51
51
|
colorSchemeStorageKey = defaultColorSchemeStorageKey,
|
|
52
52
|
disableTransitionOnChange = designSystemTransitionOnChange,
|
|
53
|
+
storageManager,
|
|
53
54
|
storageWindow = typeof window === 'undefined' ? undefined : window,
|
|
54
55
|
documentNode = typeof document === 'undefined' ? undefined : document,
|
|
55
56
|
colorSchemeNode = typeof document === 'undefined' ? undefined : document.documentElement,
|
|
56
57
|
disableNestedContext = false,
|
|
57
58
|
disableStyleSheetGeneration = false,
|
|
58
59
|
defaultMode: initialMode = 'system',
|
|
60
|
+
forceThemeRerender = false,
|
|
59
61
|
noSsr
|
|
60
62
|
} = props;
|
|
61
63
|
const hasMounted = React.useRef(false);
|
|
@@ -97,6 +99,7 @@ export default function createCssVarsProvider(options) {
|
|
|
97
99
|
modeStorageKey,
|
|
98
100
|
colorSchemeStorageKey,
|
|
99
101
|
defaultMode,
|
|
102
|
+
storageManager,
|
|
100
103
|
storageWindow,
|
|
101
104
|
noSsr
|
|
102
105
|
});
|
|
@@ -106,10 +109,15 @@ export default function createCssVarsProvider(options) {
|
|
|
106
109
|
mode = ctx.mode;
|
|
107
110
|
colorScheme = ctx.colorScheme;
|
|
108
111
|
}
|
|
112
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
113
|
+
if (forceThemeRerender && !restThemeProp.vars) {
|
|
114
|
+
console.warn(['MUI: The `forceThemeRerender` prop should only be used with CSS theme variables.', 'Note that it will slow down the app when changing between modes, so only do this when you cannot find a better solution.'].join('\n'));
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
const calculatedColorScheme = forceThemeRerender && restThemeProp.vars ?
|
|
118
|
+
// `colorScheme` is undefined on the server and hydration phase
|
|
119
|
+
colorScheme || restThemeProp.defaultColorScheme : restThemeProp.defaultColorScheme;
|
|
109
120
|
const memoTheme = React.useMemo(() => {
|
|
110
|
-
// `colorScheme` is undefined on the server and hydration phase
|
|
111
|
-
const calculatedColorScheme = colorScheme || restThemeProp.defaultColorScheme;
|
|
112
|
-
|
|
113
121
|
// 2. get the `vars` object that refers to the CSS custom properties
|
|
114
122
|
const themeVars = restThemeProp.generateThemeVars?.() || restThemeProp.vars;
|
|
115
123
|
|
|
@@ -144,7 +152,7 @@ export default function createCssVarsProvider(options) {
|
|
|
144
152
|
}
|
|
145
153
|
}
|
|
146
154
|
return resolveTheme ? resolveTheme(theme) : theme;
|
|
147
|
-
}, [restThemeProp,
|
|
155
|
+
}, [restThemeProp, calculatedColorScheme, components, colorSchemes, cssVarPrefix]);
|
|
148
156
|
|
|
149
157
|
// 5. Declaring effects
|
|
150
158
|
// 5.1 Updates the selector value to use the current color scheme which tells CSS to use the proper stylesheet.
|
|
@@ -282,6 +290,10 @@ export default function createCssVarsProvider(options) {
|
|
|
282
290
|
* The document to attach the attribute to.
|
|
283
291
|
*/
|
|
284
292
|
documentNode: PropTypes.any,
|
|
293
|
+
/**
|
|
294
|
+
* If `true`, theme values are recalculated when the mode changes.
|
|
295
|
+
*/
|
|
296
|
+
forceThemeRerender: PropTypes.bool,
|
|
285
297
|
/**
|
|
286
298
|
* The key in the local storage used to store current color scheme.
|
|
287
299
|
*/
|
|
@@ -291,6 +303,11 @@ export default function createCssVarsProvider(options) {
|
|
|
291
303
|
* You should use this option in conjuction with `InitColorSchemeScript` component.
|
|
292
304
|
*/
|
|
293
305
|
noSsr: PropTypes.bool,
|
|
306
|
+
/**
|
|
307
|
+
* The storage manager to be used for storing the mode and color scheme
|
|
308
|
+
* @default using `window.localStorage`
|
|
309
|
+
*/
|
|
310
|
+
storageManager: PropTypes.func,
|
|
294
311
|
/**
|
|
295
312
|
* The window that attaches the 'storage' event listener.
|
|
296
313
|
* @default window
|
package/esm/cssVars/index.d.ts
CHANGED
|
@@ -4,4 +4,5 @@ export { default as prepareCssVars } from "./prepareCssVars.js";
|
|
|
4
4
|
export { default as prepareTypographyVars } from "./prepareTypographyVars.js";
|
|
5
5
|
export type { ExtractTypographyTokens } from "./prepareTypographyVars.js";
|
|
6
6
|
export { default as createCssVarsTheme } from "./createCssVarsTheme.js";
|
|
7
|
-
export { createGetColorSchemeSelector } from "./getColorSchemeSelector.js";
|
|
7
|
+
export { createGetColorSchemeSelector } from "./getColorSchemeSelector.js";
|
|
8
|
+
export type { StorageManager } from "./localStorageManager.js";
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export interface StorageManager {
|
|
2
|
+
(options: {
|
|
3
|
+
key: string;
|
|
4
|
+
storageWindow?: Window | null;
|
|
5
|
+
}): {
|
|
6
|
+
/**
|
|
7
|
+
* Function to get the value from the storage
|
|
8
|
+
* @param defaultValue The default value to be returned if the key is not found
|
|
9
|
+
* @returns The value from the storage or the default value
|
|
10
|
+
*/
|
|
11
|
+
get(defaultValue: any): any;
|
|
12
|
+
/**
|
|
13
|
+
* Function to set the value in the storage
|
|
14
|
+
* @param value The value to be set
|
|
15
|
+
* @returns void
|
|
16
|
+
*/
|
|
17
|
+
set(value: any): void;
|
|
18
|
+
/**
|
|
19
|
+
* Function to subscribe to the value of the specified key triggered by external events
|
|
20
|
+
* @param handler The function to be called when the value changes
|
|
21
|
+
* @returns A function to unsubscribe the handler
|
|
22
|
+
* @example
|
|
23
|
+
* React.useEffect(() => {
|
|
24
|
+
* const unsubscribe = storageManager.subscribe((value) => {
|
|
25
|
+
* console.log(value);
|
|
26
|
+
* });
|
|
27
|
+
* return unsubscribe;
|
|
28
|
+
* }, []);
|
|
29
|
+
*/
|
|
30
|
+
subscribe(handler: (value: any) => void): () => void;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
declare const localStorageManager: StorageManager;
|
|
34
|
+
export default localStorageManager;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
function noop() {}
|
|
2
|
+
const localStorageManager = ({
|
|
3
|
+
key,
|
|
4
|
+
storageWindow
|
|
5
|
+
}) => {
|
|
6
|
+
if (!storageWindow && typeof window !== 'undefined') {
|
|
7
|
+
storageWindow = window;
|
|
8
|
+
}
|
|
9
|
+
return {
|
|
10
|
+
get(defaultValue) {
|
|
11
|
+
if (typeof window === 'undefined') {
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
if (!storageWindow) {
|
|
15
|
+
return defaultValue;
|
|
16
|
+
}
|
|
17
|
+
let value;
|
|
18
|
+
try {
|
|
19
|
+
value = storageWindow.localStorage.getItem(key);
|
|
20
|
+
} catch {
|
|
21
|
+
// Unsupported
|
|
22
|
+
}
|
|
23
|
+
return value || defaultValue;
|
|
24
|
+
},
|
|
25
|
+
set: value => {
|
|
26
|
+
if (storageWindow) {
|
|
27
|
+
try {
|
|
28
|
+
storageWindow.localStorage.setItem(key, value);
|
|
29
|
+
} catch {
|
|
30
|
+
// Unsupported
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
subscribe: handler => {
|
|
35
|
+
if (!storageWindow) {
|
|
36
|
+
return noop;
|
|
37
|
+
}
|
|
38
|
+
const listener = event => {
|
|
39
|
+
const value = event.newValue;
|
|
40
|
+
if (event.key === key) {
|
|
41
|
+
handler(value);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
storageWindow.addEventListener('storage', listener);
|
|
45
|
+
return () => {
|
|
46
|
+
storageWindow.removeEventListener('storage', listener);
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
export default localStorageManager;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { StorageManager } from "./localStorageManager.js";
|
|
1
2
|
export type Mode = 'light' | 'dark' | 'system';
|
|
2
3
|
export type SystemMode = Exclude<Mode, 'system'>;
|
|
3
4
|
export interface State<SupportedColorScheme extends string> {
|
|
@@ -48,6 +49,7 @@ interface UseCurrentColoSchemeOptions<SupportedColorScheme extends string> {
|
|
|
48
49
|
modeStorageKey?: string;
|
|
49
50
|
colorSchemeStorageKey?: string;
|
|
50
51
|
storageWindow?: Window | null;
|
|
52
|
+
storageManager?: StorageManager | null;
|
|
51
53
|
noSsr?: boolean;
|
|
52
54
|
}
|
|
53
55
|
export default function useCurrentColorScheme<SupportedColorScheme extends string>(options: UseCurrentColoSchemeOptions<SupportedColorScheme>): Result<SupportedColorScheme>;
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
import * as React from 'react';
|
|
4
4
|
import { DEFAULT_MODE_STORAGE_KEY, DEFAULT_COLOR_SCHEME_STORAGE_KEY } from "../InitColorSchemeScript/InitColorSchemeScript.js";
|
|
5
|
+
import localStorageManager from "./localStorageManager.js";
|
|
6
|
+
function noop() {}
|
|
5
7
|
export function getSystemMode(mode) {
|
|
6
8
|
if (typeof window !== 'undefined' && typeof window.matchMedia === 'function' && mode === 'system') {
|
|
7
9
|
const mql = window.matchMedia('(prefers-color-scheme: dark)');
|
|
@@ -32,22 +34,6 @@ export function getColorScheme(state) {
|
|
|
32
34
|
return undefined;
|
|
33
35
|
});
|
|
34
36
|
}
|
|
35
|
-
function initializeValue(key, defaultValue) {
|
|
36
|
-
if (typeof window === 'undefined') {
|
|
37
|
-
return undefined;
|
|
38
|
-
}
|
|
39
|
-
let value;
|
|
40
|
-
try {
|
|
41
|
-
value = localStorage.getItem(key) || undefined;
|
|
42
|
-
if (!value) {
|
|
43
|
-
// the first time that user enters the site.
|
|
44
|
-
localStorage.setItem(key, defaultValue);
|
|
45
|
-
}
|
|
46
|
-
} catch {
|
|
47
|
-
// Unsupported
|
|
48
|
-
}
|
|
49
|
-
return value || defaultValue;
|
|
50
|
-
}
|
|
51
37
|
export default function useCurrentColorScheme(options) {
|
|
52
38
|
const {
|
|
53
39
|
defaultMode = 'light',
|
|
@@ -57,14 +43,27 @@ export default function useCurrentColorScheme(options) {
|
|
|
57
43
|
modeStorageKey = DEFAULT_MODE_STORAGE_KEY,
|
|
58
44
|
colorSchemeStorageKey = DEFAULT_COLOR_SCHEME_STORAGE_KEY,
|
|
59
45
|
storageWindow = typeof window === 'undefined' ? undefined : window,
|
|
46
|
+
storageManager = localStorageManager,
|
|
60
47
|
noSsr = false
|
|
61
48
|
} = options;
|
|
62
49
|
const joinedColorSchemes = supportedColorSchemes.join(',');
|
|
63
50
|
const isMultiSchemes = supportedColorSchemes.length > 1;
|
|
51
|
+
const modeStorage = React.useMemo(() => storageManager?.({
|
|
52
|
+
key: modeStorageKey,
|
|
53
|
+
storageWindow
|
|
54
|
+
}), [storageManager, modeStorageKey, storageWindow]);
|
|
55
|
+
const lightStorage = React.useMemo(() => storageManager?.({
|
|
56
|
+
key: `${colorSchemeStorageKey}-light`,
|
|
57
|
+
storageWindow
|
|
58
|
+
}), [storageManager, colorSchemeStorageKey, storageWindow]);
|
|
59
|
+
const darkStorage = React.useMemo(() => storageManager?.({
|
|
60
|
+
key: `${colorSchemeStorageKey}-dark`,
|
|
61
|
+
storageWindow
|
|
62
|
+
}), [storageManager, colorSchemeStorageKey, storageWindow]);
|
|
64
63
|
const [state, setState] = React.useState(() => {
|
|
65
|
-
const initialMode =
|
|
66
|
-
const lightColorScheme =
|
|
67
|
-
const darkColorScheme =
|
|
64
|
+
const initialMode = modeStorage?.get(defaultMode) || defaultMode;
|
|
65
|
+
const lightColorScheme = lightStorage?.get(defaultLightColorScheme) || defaultLightColorScheme;
|
|
66
|
+
const darkColorScheme = darkStorage?.get(defaultDarkColorScheme) || defaultDarkColorScheme;
|
|
68
67
|
return {
|
|
69
68
|
mode: initialMode,
|
|
70
69
|
systemMode: getSystemMode(initialMode),
|
|
@@ -84,27 +83,19 @@ export default function useCurrentColorScheme(options) {
|
|
|
84
83
|
return currentState;
|
|
85
84
|
}
|
|
86
85
|
const newMode = mode ?? defaultMode;
|
|
87
|
-
|
|
88
|
-
localStorage.setItem(modeStorageKey, newMode);
|
|
89
|
-
} catch {
|
|
90
|
-
// Unsupported
|
|
91
|
-
}
|
|
86
|
+
modeStorage?.set(newMode);
|
|
92
87
|
return {
|
|
93
88
|
...currentState,
|
|
94
89
|
mode: newMode,
|
|
95
90
|
systemMode: getSystemMode(newMode)
|
|
96
91
|
};
|
|
97
92
|
});
|
|
98
|
-
}, [
|
|
93
|
+
}, [modeStorage, defaultMode]);
|
|
99
94
|
const setColorScheme = React.useCallback(value => {
|
|
100
95
|
if (!value) {
|
|
101
96
|
setState(currentState => {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
localStorage.setItem(`${colorSchemeStorageKey}-dark`, defaultDarkColorScheme);
|
|
105
|
-
} catch {
|
|
106
|
-
// Unsupported
|
|
107
|
-
}
|
|
97
|
+
lightStorage?.set(defaultLightColorScheme);
|
|
98
|
+
darkStorage?.set(defaultDarkColorScheme);
|
|
108
99
|
return {
|
|
109
100
|
...currentState,
|
|
110
101
|
lightColorScheme: defaultLightColorScheme,
|
|
@@ -120,15 +111,12 @@ export default function useCurrentColorScheme(options) {
|
|
|
120
111
|
...currentState
|
|
121
112
|
};
|
|
122
113
|
processState(currentState, mode => {
|
|
123
|
-
try {
|
|
124
|
-
localStorage.setItem(`${colorSchemeStorageKey}-${mode}`, value);
|
|
125
|
-
} catch {
|
|
126
|
-
// Unsupported
|
|
127
|
-
}
|
|
128
114
|
if (mode === 'light') {
|
|
115
|
+
lightStorage?.set(value);
|
|
129
116
|
newState.lightColorScheme = value;
|
|
130
117
|
}
|
|
131
118
|
if (mode === 'dark') {
|
|
119
|
+
darkStorage?.set(value);
|
|
132
120
|
newState.darkColorScheme = value;
|
|
133
121
|
}
|
|
134
122
|
});
|
|
@@ -147,11 +135,7 @@ export default function useCurrentColorScheme(options) {
|
|
|
147
135
|
console.error(`\`${newLightColorScheme}\` does not exist in \`theme.colorSchemes\`.`);
|
|
148
136
|
} else {
|
|
149
137
|
newState.lightColorScheme = newLightColorScheme;
|
|
150
|
-
|
|
151
|
-
localStorage.setItem(`${colorSchemeStorageKey}-light`, newLightColorScheme);
|
|
152
|
-
} catch (error) {
|
|
153
|
-
// Unsupported
|
|
154
|
-
}
|
|
138
|
+
lightStorage?.set(newLightColorScheme);
|
|
155
139
|
}
|
|
156
140
|
}
|
|
157
141
|
if (newDarkColorScheme) {
|
|
@@ -159,17 +143,13 @@ export default function useCurrentColorScheme(options) {
|
|
|
159
143
|
console.error(`\`${newDarkColorScheme}\` does not exist in \`theme.colorSchemes\`.`);
|
|
160
144
|
} else {
|
|
161
145
|
newState.darkColorScheme = newDarkColorScheme;
|
|
162
|
-
|
|
163
|
-
localStorage.setItem(`${colorSchemeStorageKey}-dark`, newDarkColorScheme);
|
|
164
|
-
} catch (error) {
|
|
165
|
-
// Unsupported
|
|
166
|
-
}
|
|
146
|
+
darkStorage?.set(newDarkColorScheme);
|
|
167
147
|
}
|
|
168
148
|
}
|
|
169
149
|
return newState;
|
|
170
150
|
});
|
|
171
151
|
}
|
|
172
|
-
}, [joinedColorSchemes,
|
|
152
|
+
}, [joinedColorSchemes, lightStorage, darkStorage, defaultLightColorScheme, defaultDarkColorScheme]);
|
|
173
153
|
const handleMediaQuery = React.useCallback(event => {
|
|
174
154
|
if (state.mode === 'system') {
|
|
175
155
|
setState(currentState => {
|
|
@@ -209,34 +189,34 @@ export default function useCurrentColorScheme(options) {
|
|
|
209
189
|
|
|
210
190
|
// Handle when localStorage has changed
|
|
211
191
|
React.useEffect(() => {
|
|
212
|
-
if (
|
|
213
|
-
const
|
|
214
|
-
|
|
215
|
-
if (typeof event.key === 'string' && event.key.startsWith(colorSchemeStorageKey) && (!value || joinedColorSchemes.match(value))) {
|
|
216
|
-
// If the key is deleted, value will be null then reset color scheme to the default one.
|
|
217
|
-
if (event.key.endsWith('light')) {
|
|
218
|
-
setColorScheme({
|
|
219
|
-
light: value
|
|
220
|
-
});
|
|
221
|
-
}
|
|
222
|
-
if (event.key.endsWith('dark')) {
|
|
223
|
-
setColorScheme({
|
|
224
|
-
dark: value
|
|
225
|
-
});
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
if (event.key === modeStorageKey && (!value || ['light', 'dark', 'system'].includes(value))) {
|
|
192
|
+
if (isMultiSchemes) {
|
|
193
|
+
const unsubscribeMode = modeStorage?.subscribe(value => {
|
|
194
|
+
if (!value || ['light', 'dark', 'system'].includes(value)) {
|
|
229
195
|
setMode(value || defaultMode);
|
|
230
196
|
}
|
|
231
|
-
};
|
|
232
|
-
|
|
233
|
-
|
|
197
|
+
}) || noop;
|
|
198
|
+
const unsubscribeLight = lightStorage?.subscribe(value => {
|
|
199
|
+
if (!value || joinedColorSchemes.match(value)) {
|
|
200
|
+
setColorScheme({
|
|
201
|
+
light: value
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
}) || noop;
|
|
205
|
+
const unsubscribeDark = darkStorage?.subscribe(value => {
|
|
206
|
+
if (!value || joinedColorSchemes.match(value)) {
|
|
207
|
+
setColorScheme({
|
|
208
|
+
dark: value
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
}) || noop;
|
|
234
212
|
return () => {
|
|
235
|
-
|
|
213
|
+
unsubscribeMode();
|
|
214
|
+
unsubscribeLight();
|
|
215
|
+
unsubscribeDark();
|
|
236
216
|
};
|
|
237
217
|
}
|
|
238
218
|
return undefined;
|
|
239
|
-
}, [setColorScheme, setMode,
|
|
219
|
+
}, [setColorScheme, setMode, joinedColorSchemes, defaultMode, storageWindow, isMultiSchemes, modeStorage, lightStorage, darkStorage]);
|
|
240
220
|
return {
|
|
241
221
|
...state,
|
|
242
222
|
mode: isClient ? state.mode : undefined,
|
package/esm/display/display.d.ts
CHANGED
package/esm/flexbox/flexbox.d.ts
CHANGED
package/esm/index.d.ts
CHANGED
|
@@ -27,6 +27,7 @@ export { css, keyframes, StyledEngineProvider, Interpolation, CSSInterpolation,
|
|
|
27
27
|
export { default as GlobalStyles } from "./GlobalStyles/index.js";
|
|
28
28
|
export type { GlobalStylesProps } from "./GlobalStyles/index.js";
|
|
29
29
|
export * from "./style/index.js";
|
|
30
|
+
export { default as style } from "./style/index.js";
|
|
30
31
|
export * from "./spacing/index.js";
|
|
31
32
|
export { default as unstable_styleFunctionSx, unstable_createStyleFunctionSx, extendSxProp as unstable_extendSxProp, unstable_defaultSxConfig } from "./styleFunctionSx/index.js";
|
|
32
33
|
export * from "./styleFunctionSx/index.js";
|
package/esm/index.js
CHANGED
package/esm/palette/palette.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { PropsFor, SimpleStyleFunction, palette } from "../Box/index.js";
|
|
2
2
|
export const color: SimpleStyleFunction<'color'>;
|
|
3
3
|
export const bgcolor: SimpleStyleFunction<'bgcolor'>;
|
|
4
|
-
export type PaletteProps = PropsFor<typeof palette>;
|
|
4
|
+
export type PaletteProps = PropsFor<typeof palette>;
|
|
5
|
+
export default palette;
|
package/esm/shadows/shadows.d.ts
CHANGED
package/esm/sizing/sizing.d.ts
CHANGED
|
@@ -8,4 +8,5 @@ export const minHeight: SimpleStyleFunction<'minHeight'>;
|
|
|
8
8
|
export const sizeWidth: SimpleStyleFunction<'sizeWidth'>;
|
|
9
9
|
export const sizeHeight: SimpleStyleFunction<'sizeHeight'>;
|
|
10
10
|
export const boxSizing: SimpleStyleFunction<'boxSizing'>;
|
|
11
|
-
export type SizingProps = PropsFor<typeof sizing>;
|
|
11
|
+
export type SizingProps = PropsFor<typeof sizing>;
|
|
12
|
+
export default sizing;
|
package/esm/spacing/spacing.d.ts
CHANGED
|
@@ -15,4 +15,5 @@ export const margin: SimpleStyleFunction<'m' | 'mt' | 'mr' | 'mb' | 'ml' | 'mx'
|
|
|
15
15
|
export type MarginProps = PropsFor<typeof margin>;
|
|
16
16
|
export const padding: SimpleStyleFunction<'p' | 'pt' | 'pr' | 'pb' | 'pl' | 'px' | 'py' | 'padding' | 'paddingTop' | 'paddingRight' | 'paddingBottom' | 'paddingLeft' | 'paddingX' | 'paddingY' | 'paddingInline' | 'paddingInlineStart' | 'paddingInlineEnd' | 'paddingBlock' | 'paddingBlockStart' | 'paddingBlockEnd'>;
|
|
17
17
|
export function getValue(transformer: (prop: SpacingValueType) => SpacingValueType, propValue: SpacingValueType): SpacingValueType;
|
|
18
|
-
export type PaddingProps = PropsFor<typeof padding>;
|
|
18
|
+
export type PaddingProps = PropsFor<typeof padding>;
|
|
19
|
+
export default spacing;
|
package/esm/spacing/spacing.js
CHANGED
|
@@ -55,6 +55,12 @@ export function createUnaryUnit(theme, themeKey, defaultValue, propName) {
|
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
if (typeof themeSpacing === 'string') {
|
|
58
|
+
if (themeSpacing.startsWith('var(') && val === 0) {
|
|
59
|
+
return 0;
|
|
60
|
+
}
|
|
61
|
+
if (themeSpacing.startsWith('var(') && val === 1) {
|
|
62
|
+
return themeSpacing;
|
|
63
|
+
}
|
|
58
64
|
return `calc(${val} * ${themeSpacing})`;
|
|
59
65
|
}
|
|
60
66
|
return themeSpacing * val;
|
|
@@ -80,6 +86,9 @@ export function createUnaryUnit(theme, themeKey, defaultValue, propName) {
|
|
|
80
86
|
if (typeof transformed === 'number') {
|
|
81
87
|
return -transformed;
|
|
82
88
|
}
|
|
89
|
+
if (typeof transformed === 'string' && transformed.startsWith('var(')) {
|
|
90
|
+
return `calc(-1 * ${transformed})`;
|
|
91
|
+
}
|
|
83
92
|
return `-${transformed}`;
|
|
84
93
|
};
|
|
85
94
|
}
|
package/esm/style/style.d.ts
CHANGED
|
@@ -10,10 +10,10 @@ export interface StyleOptions<PropKey> {
|
|
|
10
10
|
themeKey?: string;
|
|
11
11
|
transform?: TransformFunction;
|
|
12
12
|
}
|
|
13
|
-
export function
|
|
13
|
+
export function getPath<T>(obj: T, path: string | undefined, checkVars?: boolean): null | unknown;
|
|
14
|
+
export function getStyleValue(themeMapping: object | ((arg: any) => any), transform: TransformFunction | null, propValueFinal: unknown, userValue?: unknown): any;
|
|
15
|
+
export default function style<PropKey extends string, Theme extends object>(options: StyleOptions<PropKey>): StyleFunction<{ [K in PropKey]?: unknown } & {
|
|
14
16
|
theme?: Theme;
|
|
15
17
|
}> & {
|
|
16
18
|
filterProps: string[];
|
|
17
|
-
};
|
|
18
|
-
export function getPath<T>(obj: T, path: string | undefined, checkVars?: boolean): null | unknown;
|
|
19
|
-
export function getStyleValue(themeMapping: object | ((arg: any) => any), transform: TransformFunction | null, propValueFinal: unknown, userValue?: unknown): any;
|
|
19
|
+
};
|
|
@@ -8,4 +8,5 @@ export const letterSpacing: SimpleStyleFunction<'letterSpacing'>;
|
|
|
8
8
|
export const lineHeight: SimpleStyleFunction<'lineHeight'>;
|
|
9
9
|
export const textAlign: SimpleStyleFunction<'textAlign'>;
|
|
10
10
|
export const textTransform: SimpleStyleFunction<'textTransform'>;
|
|
11
|
-
export type TypographyProps = PropsFor<typeof typography>;
|
|
11
|
+
export type TypographyProps = PropsFor<typeof typography>;
|
|
12
|
+
export default typography;
|
package/esm/version/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export const version = "7.0.0-beta.
|
|
1
|
+
export const version = "7.0.0-beta.4";
|
|
2
2
|
export const major = Number("7");
|
|
3
3
|
export const minor = Number("0");
|
|
4
4
|
export const patch = Number("0");
|
|
5
|
-
export const prerelease = "beta.
|
|
5
|
+
export const prerelease = "beta.4";
|
|
6
6
|
export default version;
|
package/flexbox/flexbox.d.ts
CHANGED
package/index.d.ts
CHANGED
|
@@ -27,6 +27,7 @@ export { css, keyframes, StyledEngineProvider, Interpolation, CSSInterpolation,
|
|
|
27
27
|
export { default as GlobalStyles } from "./GlobalStyles/index.js";
|
|
28
28
|
export type { GlobalStylesProps } from "./GlobalStyles/index.js";
|
|
29
29
|
export * from "./style/index.js";
|
|
30
|
+
export { default as style } from "./style/index.js";
|
|
30
31
|
export * from "./spacing/index.js";
|
|
31
32
|
export { default as unstable_styleFunctionSx, unstable_createStyleFunctionSx, extendSxProp as unstable_extendSxProp, unstable_defaultSxConfig } from "./styleFunctionSx/index.js";
|
|
32
33
|
export * from "./styleFunctionSx/index.js";
|
package/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PropsFor,
|
|
1
|
+
import { PropsFor, borders, SimpleStyleFunction } from "../Box/index.js";
|
|
2
2
|
export const border: SimpleStyleFunction<'border'>;
|
|
3
3
|
export const borderTop: SimpleStyleFunction<'borderTop'>;
|
|
4
4
|
export const borderRight: SimpleStyleFunction<'borderRight'>;
|
|
@@ -10,4 +10,5 @@ export const borderRightColor: SimpleStyleFunction<'borderRightColor'>;
|
|
|
10
10
|
export const borderBottomColor: SimpleStyleFunction<'borderBottomColor'>;
|
|
11
11
|
export const borderLeftColor: SimpleStyleFunction<'borderLeftColor'>;
|
|
12
12
|
export const borderRadius: SimpleStyleFunction<'borderRadius'>;
|
|
13
|
-
export type BordersProps = PropsFor<typeof borders>;
|
|
13
|
+
export type BordersProps = PropsFor<typeof borders>;
|
|
14
|
+
export default borders;
|
|
@@ -1,2 +1,15 @@
|
|
|
1
|
-
import { PropsFor, grid } from "../Box/index.js";
|
|
2
|
-
export
|
|
1
|
+
import { PropsFor, grid, SimpleStyleFunction } from "../Box/index.js";
|
|
2
|
+
export const gap: SimpleStyleFunction<'gap'>;
|
|
3
|
+
export const columnGap: SimpleStyleFunction<'columnGap'>;
|
|
4
|
+
export const rowGap: SimpleStyleFunction<'rowGap'>;
|
|
5
|
+
export const gridColumn: SimpleStyleFunction<'gridColumn'>;
|
|
6
|
+
export const gridRow: SimpleStyleFunction<'gridRow'>;
|
|
7
|
+
export const gridAutoFlow: SimpleStyleFunction<'gridAutoFlow'>;
|
|
8
|
+
export const gridAutoColumns: SimpleStyleFunction<'gridAutoColumns'>;
|
|
9
|
+
export const gridAutoRows: SimpleStyleFunction<'gridAutoRows'>;
|
|
10
|
+
export const gridTemplateColumns: SimpleStyleFunction<'gridTemplateColumns'>;
|
|
11
|
+
export const gridTemplateRows: SimpleStyleFunction<'gridTemplateRows'>;
|
|
12
|
+
export const gridTemplateAreas: SimpleStyleFunction<'gridTemplateAreas'>;
|
|
13
|
+
export const gridArea: SimpleStyleFunction<'gridArea'>;
|
|
14
|
+
export type CssGridProps = PropsFor<typeof grid>;
|
|
15
|
+
export default grid;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import InitColorSchemeScript from "../InitColorSchemeScript/index.js";
|
|
3
3
|
import { Result } from "./useCurrentColorScheme.js";
|
|
4
|
+
import type { StorageManager } from "./localStorageManager.js";
|
|
4
5
|
export interface ColorSchemeContextValue<SupportedColorScheme extends string> extends Result<SupportedColorScheme> {
|
|
5
6
|
allColorSchemes: SupportedColorScheme[];
|
|
6
7
|
}
|
|
@@ -34,6 +35,12 @@ export interface CssVarsProviderConfig<ColorScheme extends string> {
|
|
|
34
35
|
* @default false
|
|
35
36
|
*/
|
|
36
37
|
disableTransitionOnChange?: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* If `true`, theme values are recalculated when the mode changes.
|
|
40
|
+
* The `theme.colorSchemes.{mode}.*` nodes will be shallow merged to the top-level of the theme.
|
|
41
|
+
* @default false
|
|
42
|
+
*/
|
|
43
|
+
forceThemeRerender?: boolean;
|
|
37
44
|
}
|
|
38
45
|
type Identify<I extends string | undefined, T> = I extends string ? T | { [k in I]: T } : T;
|
|
39
46
|
export interface CreateCssVarsProviderResult<ColorScheme extends string, Identifier extends string | undefined = undefined> {
|
|
@@ -60,6 +67,11 @@ export interface CreateCssVarsProviderResult<ColorScheme extends string, Identif
|
|
|
60
67
|
* @default document
|
|
61
68
|
*/
|
|
62
69
|
colorSchemeNode?: Element | null;
|
|
70
|
+
/**
|
|
71
|
+
* The storage manager to be used for storing the mode and color scheme.
|
|
72
|
+
* @default using `window.localStorage`
|
|
73
|
+
*/
|
|
74
|
+
storageManager?: StorageManager | null;
|
|
63
75
|
/**
|
|
64
76
|
* The window that attaches the 'storage' event listener
|
|
65
77
|
* @default window
|