@mui/system 5.8.5 → 5.8.6
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 +65 -0
- package/Container/Container.d.ts +13 -13
- package/Container/ContainerProps.d.ts +40 -40
- package/Container/containerClasses.d.ts +22 -22
- package/Container/createContainer.d.ts +18 -18
- package/createBox.spec.d.ts +1 -1
- package/createTheme/createSpacing.d.ts +10 -10
- package/cssVars/createCssVarsProvider.js +2 -1
- 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 +45 -40
- package/cssVars/getInitColorSchemeScript.js +7 -0
- package/cssVars/index.d.ts +2 -2
- package/cssVars/useCurrentColorScheme.d.ts +53 -53
- package/esm/cssVars/createCssVarsProvider.js +2 -1
- package/esm/cssVars/getInitColorSchemeScript.js +7 -0
- package/index.js +1 -1
- package/index.spec.d.ts +1 -1
- package/legacy/cssVars/createCssVarsProvider.js +2 -1
- package/legacy/cssVars/getInitColorSchemeScript.js +3 -1
- package/legacy/index.js +1 -1
- package/modern/cssVars/createCssVarsProvider.js +2 -1
- package/modern/cssVars/getInitColorSchemeScript.js +7 -0
- package/modern/index.js +1 -1
- package/package.json +3 -3
- 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,70 @@
|
|
|
1
1
|
# [Versions](https://mui.com/versions/)
|
|
2
2
|
|
|
3
|
+
## 5.8.6
|
|
4
|
+
|
|
5
|
+
<!-- generated comparing v5.8.5..master -->
|
|
6
|
+
|
|
7
|
+
_Jun 27, 2022_
|
|
8
|
+
|
|
9
|
+
A big thanks to the 13 contributors who made this release possible. Here are some highlights ✨:
|
|
10
|
+
|
|
11
|
+
- ⚒️ Fixed React 18 issues in few components
|
|
12
|
+
- 🚀 Improved the TypeScript augmentation when using CSS variables with `@mui/material`
|
|
13
|
+
- many other 🐛 bug fixes and 📚 documentation improvements
|
|
14
|
+
|
|
15
|
+
### `@mui/material@5.8.6`
|
|
16
|
+
|
|
17
|
+
- ​<!-- 27 -->[Alert] Add support for CSS vars (#32624) @haneenmahd
|
|
18
|
+
- ​<!-- 26 -->[Alert] Use `getContrastText` for filled variant font color (#29813) @SamoraMabuya
|
|
19
|
+
|
|
20
|
+
Note: The color of the text in the warning contained `Alert` in dark mode was changed to black in order to improve the color contrast ratio
|
|
21
|
+
|
|
22
|
+
- ​<!-- 11 -->[OutlinedInput] Fix `ownerState` undefined in theme style overrides (#33241) @siriwatknp
|
|
23
|
+
- ​<!-- 08 -->[Tabs] Fix crash when used with React 18 & Suspense (#33277) @mnajdova
|
|
24
|
+
- ​<!-- 05 -->[TypeScript] Add CSS vars type augmentation for Material UI (#33211) @siriwatknp
|
|
25
|
+
|
|
26
|
+
### `@mui/system@5.8.6`
|
|
27
|
+
|
|
28
|
+
- ​<!-- 09 -->[system] Add enableColorScheme option to getInitColorSchemeScript (#33261) @siriwatknp
|
|
29
|
+
|
|
30
|
+
### `@mui/utils@5.8.6`
|
|
31
|
+
|
|
32
|
+
- ​<!-- 04 -->[utils] Allow state prefix to be configurable (#32972) @siriwatknp
|
|
33
|
+
|
|
34
|
+
### `@mui/base@5.0.0-alpha.87`
|
|
35
|
+
|
|
36
|
+
- ​<!-- 25 -->[base] Improve the return type of useSlotProps (#33279) @michaldudak
|
|
37
|
+
- ​<!-- 24 -->[base] Improve some types (#33270) @mnajdova
|
|
38
|
+
- ​<!-- 13 -->[MenuUnstyled] Fix keyboard accessibility of menu items (#33145) @michaldudak
|
|
39
|
+
- ​<!-- 12 -->[ModalManager] Lock body scroll when container is inside shadow DOM (#33168) @jacobweberbowery
|
|
40
|
+
- ​<!-- 10 -->[SliderUnstyled] Use useSlotProps (#33132) @michaldudak
|
|
41
|
+
- ​<!-- 07 -->[TextareaAutosize] Fix crash when used with React 18 & Suspense (#33238) @howlettt
|
|
42
|
+
- ​<!-- 06 -->[TextareaAutosize] Fix warnings for too many renders in React 18 (#33253) @mnajdova
|
|
43
|
+
|
|
44
|
+
### `@mui/joy@5.0.0-alpha.34`
|
|
45
|
+
|
|
46
|
+
- ​<!-- 14 -->[Joy] Add `Sheet` doc (#32820) @hbjORbj
|
|
47
|
+
|
|
48
|
+
### Docs
|
|
49
|
+
|
|
50
|
+
- ​<!-- 23 -->[blog] Polish Why you should migrate to Material UI v5 today (#33244) @oliviertassinari
|
|
51
|
+
- ​<!-- 21 -->[docs] Add note in docs about `componentsProps.root` taking precedence (#33097) @ZeeshanTamboli
|
|
52
|
+
- ​<!-- 20 -->[docs] Remove a note about Base components being reexported from Material UI (#33265) @michaldudak
|
|
53
|
+
- ​<!-- 19 -->[docs] Update code snippet in docs for custom color palette (#32946) @ZeeshanTamboli
|
|
54
|
+
- ​<!-- 18 -->[docs] Fix the docs for production class generation (#31933) @Fafruch
|
|
55
|
+
- ​<!-- 17 -->[docs] Fix internal link in Box page (#33149) @davidgarciab
|
|
56
|
+
- ​<!-- 16 -->[docs] Badge component link in Base docs should be under Data Display section (#33249) @ZeeshanTamboli
|
|
57
|
+
- ​<!-- 15 -->[examples] Fix comment typo (#33256) @WinmezzZ
|
|
58
|
+
|
|
59
|
+
### Core
|
|
60
|
+
|
|
61
|
+
- ​<!-- 22 -->[core] Remove dead code (#33243) @oliviertassinari
|
|
62
|
+
- ​<!-- 03 -->[website] Fix the scroll-top for all the website (#33215) @oliviertassinari
|
|
63
|
+
- ​<!-- 02 -->[website] List new core role @oliviertassinari
|
|
64
|
+
- ​<!-- 01 -->[website] Fix navigation menu close behavior (#33203) @oliviertassinari
|
|
65
|
+
|
|
66
|
+
All contributors of this release in alphabetical order: @davidgarciab, @Fafruch, @haneenmahd, @hbjORbj, @howlettt, @jacobweberbowery, @michaldudak, @mnajdova, @oliviertassinari, @SamoraMabuya, @siriwatknp, @WinmezzZ, @ZeeshanTamboli
|
|
67
|
+
|
|
3
68
|
## 5.8.5
|
|
4
69
|
|
|
5
70
|
<!-- generated comparing v5.8.4..master -->
|
package/Container/Container.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* Demos:
|
|
4
|
-
*
|
|
5
|
-
* - [Container (Material UI)](https://mui.com/material-ui/react-container/)
|
|
6
|
-
* - [Container (MUI System)](https://mui.com/system/react-container/)
|
|
7
|
-
*
|
|
8
|
-
* API:
|
|
9
|
-
*
|
|
10
|
-
* - [Container API](https://mui.com/system/api/container/)
|
|
11
|
-
*/
|
|
12
|
-
declare const Container: import("@mui/types").OverridableComponent<import("./ContainerProps").ContainerTypeMap<{}, "div">>;
|
|
13
|
-
export default Container;
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* Demos:
|
|
4
|
+
*
|
|
5
|
+
* - [Container (Material UI)](https://mui.com/material-ui/react-container/)
|
|
6
|
+
* - [Container (MUI System)](https://mui.com/system/react-container/)
|
|
7
|
+
*
|
|
8
|
+
* API:
|
|
9
|
+
*
|
|
10
|
+
* - [Container API](https://mui.com/system/api/container/)
|
|
11
|
+
*/
|
|
12
|
+
declare const Container: import("@mui/types").OverridableComponent<import("./ContainerProps").ContainerTypeMap<{}, "div">>;
|
|
13
|
+
export default Container;
|
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { OverrideProps } from '@mui/types';
|
|
3
|
-
import { SxProps } from '../styleFunctionSx';
|
|
4
|
-
import { Theme, Breakpoint } from '../createTheme';
|
|
5
|
-
import { ContainerClasses } from './containerClasses';
|
|
6
|
-
export interface ContainerTypeMap<P = {}, D extends React.ElementType = 'div'> {
|
|
7
|
-
props: P & {
|
|
8
|
-
children?: React.ReactNode;
|
|
9
|
-
/**
|
|
10
|
-
* Override or extend the styles applied to the component.
|
|
11
|
-
*/
|
|
12
|
-
classes?: Partial<ContainerClasses>;
|
|
13
|
-
/**
|
|
14
|
-
* If `true`, the left and right padding is removed.
|
|
15
|
-
* @default false
|
|
16
|
-
*/
|
|
17
|
-
disableGutters?: boolean;
|
|
18
|
-
/**
|
|
19
|
-
* Set the max-width to match the min-width of the current breakpoint.
|
|
20
|
-
* This is useful if you'd prefer to design for a fixed set of sizes
|
|
21
|
-
* instead of trying to accommodate a fully fluid viewport.
|
|
22
|
-
* It's fluid by default.
|
|
23
|
-
* @default false
|
|
24
|
-
*/
|
|
25
|
-
fixed?: boolean;
|
|
26
|
-
/**
|
|
27
|
-
* Determine the max-width of the container.
|
|
28
|
-
* The container width grows with the size of the screen.
|
|
29
|
-
* Set to `false` to disable `maxWidth`.
|
|
30
|
-
* @default 'lg'
|
|
31
|
-
*/
|
|
32
|
-
maxWidth?: Breakpoint | false;
|
|
33
|
-
/**
|
|
34
|
-
* The system prop that allows defining system overrides as well as additional CSS styles.
|
|
35
|
-
*/
|
|
36
|
-
sx?: SxProps<Theme>;
|
|
37
|
-
};
|
|
38
|
-
defaultComponent: D;
|
|
39
|
-
}
|
|
40
|
-
export declare type ContainerProps<D extends React.ElementType = ContainerTypeMap['defaultComponent'], P = {}> = OverrideProps<ContainerTypeMap<P, D>, D>;
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { OverrideProps } from '@mui/types';
|
|
3
|
+
import { SxProps } from '../styleFunctionSx';
|
|
4
|
+
import { Theme, Breakpoint } from '../createTheme';
|
|
5
|
+
import { ContainerClasses } from './containerClasses';
|
|
6
|
+
export interface ContainerTypeMap<P = {}, D extends React.ElementType = 'div'> {
|
|
7
|
+
props: P & {
|
|
8
|
+
children?: React.ReactNode;
|
|
9
|
+
/**
|
|
10
|
+
* Override or extend the styles applied to the component.
|
|
11
|
+
*/
|
|
12
|
+
classes?: Partial<ContainerClasses>;
|
|
13
|
+
/**
|
|
14
|
+
* If `true`, the left and right padding is removed.
|
|
15
|
+
* @default false
|
|
16
|
+
*/
|
|
17
|
+
disableGutters?: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Set the max-width to match the min-width of the current breakpoint.
|
|
20
|
+
* This is useful if you'd prefer to design for a fixed set of sizes
|
|
21
|
+
* instead of trying to accommodate a fully fluid viewport.
|
|
22
|
+
* It's fluid by default.
|
|
23
|
+
* @default false
|
|
24
|
+
*/
|
|
25
|
+
fixed?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Determine the max-width of the container.
|
|
28
|
+
* The container width grows with the size of the screen.
|
|
29
|
+
* Set to `false` to disable `maxWidth`.
|
|
30
|
+
* @default 'lg'
|
|
31
|
+
*/
|
|
32
|
+
maxWidth?: Breakpoint | false;
|
|
33
|
+
/**
|
|
34
|
+
* The system prop that allows defining system overrides as well as additional CSS styles.
|
|
35
|
+
*/
|
|
36
|
+
sx?: SxProps<Theme>;
|
|
37
|
+
};
|
|
38
|
+
defaultComponent: D;
|
|
39
|
+
}
|
|
40
|
+
export declare type ContainerProps<D extends React.ElementType = ContainerTypeMap['defaultComponent'], P = {}> = OverrideProps<ContainerTypeMap<P, D>, D>;
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
export interface ContainerClasses {
|
|
2
|
-
/** Styles applied to the root element. */
|
|
3
|
-
root: string;
|
|
4
|
-
/** Styles applied to the root element if `disableGutters={true}`. */
|
|
5
|
-
disableGutters: string;
|
|
6
|
-
/** Styles applied to the root element if `fixed={true}`. */
|
|
7
|
-
fixed: string;
|
|
8
|
-
/** Styles applied to the root element if `maxWidth="xs"`. */
|
|
9
|
-
maxWidthXs: string;
|
|
10
|
-
/** Styles applied to the root element if `maxWidth="sm"`. */
|
|
11
|
-
maxWidthSm: string;
|
|
12
|
-
/** Styles applied to the root element if `maxWidth="md"`. */
|
|
13
|
-
maxWidthMd: string;
|
|
14
|
-
/** Styles applied to the root element if `maxWidth="lg"`. */
|
|
15
|
-
maxWidthLg: string;
|
|
16
|
-
/** Styles applied to the root element if `maxWidth="xl"`. */
|
|
17
|
-
maxWidthXl: string;
|
|
18
|
-
}
|
|
19
|
-
export declare type ContainerClassKey = keyof ContainerClasses;
|
|
20
|
-
export declare function getContainerUtilityClass(slot: string): string;
|
|
21
|
-
declare const containerClasses: ContainerClasses;
|
|
22
|
-
export default containerClasses;
|
|
1
|
+
export interface ContainerClasses {
|
|
2
|
+
/** Styles applied to the root element. */
|
|
3
|
+
root: string;
|
|
4
|
+
/** Styles applied to the root element if `disableGutters={true}`. */
|
|
5
|
+
disableGutters: string;
|
|
6
|
+
/** Styles applied to the root element if `fixed={true}`. */
|
|
7
|
+
fixed: string;
|
|
8
|
+
/** Styles applied to the root element if `maxWidth="xs"`. */
|
|
9
|
+
maxWidthXs: string;
|
|
10
|
+
/** Styles applied to the root element if `maxWidth="sm"`. */
|
|
11
|
+
maxWidthSm: string;
|
|
12
|
+
/** Styles applied to the root element if `maxWidth="md"`. */
|
|
13
|
+
maxWidthMd: string;
|
|
14
|
+
/** Styles applied to the root element if `maxWidth="lg"`. */
|
|
15
|
+
maxWidthLg: string;
|
|
16
|
+
/** Styles applied to the root element if `maxWidth="xl"`. */
|
|
17
|
+
maxWidthXl: string;
|
|
18
|
+
}
|
|
19
|
+
export declare type ContainerClassKey = keyof ContainerClasses;
|
|
20
|
+
export declare function getContainerUtilityClass(slot: string): string;
|
|
21
|
+
declare const containerClasses: ContainerClasses;
|
|
22
|
+
export default containerClasses;
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { Interpolation, StyledComponent } from '@mui/styled-engine';
|
|
3
|
-
import { OverridableComponent } from '@mui/types';
|
|
4
|
-
import { ContainerProps, ContainerTypeMap } from './ContainerProps';
|
|
5
|
-
import { Theme as DefaultTheme } from '../createTheme';
|
|
6
|
-
interface StyleFnProps<Theme> extends ContainerProps {
|
|
7
|
-
theme: Theme;
|
|
8
|
-
ownerState: ContainerProps;
|
|
9
|
-
}
|
|
10
|
-
declare type RequiredThemeStructure = Pick<DefaultTheme, 'breakpoints' | 'spacing'>;
|
|
11
|
-
export default function createContainer<Theme extends RequiredThemeStructure = DefaultTheme>(options?: {
|
|
12
|
-
createStyledComponent?: (...styles: Array<Interpolation<StyleFnProps<Theme>>>) => StyledComponent<ContainerProps>;
|
|
13
|
-
useThemeProps?: (inProps: ContainerProps) => ContainerProps & {
|
|
14
|
-
component?: React.ElementType;
|
|
15
|
-
};
|
|
16
|
-
componentName?: string;
|
|
17
|
-
}): OverridableComponent<ContainerTypeMap<{}, "div">>;
|
|
18
|
-
export {};
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { Interpolation, StyledComponent } from '@mui/styled-engine';
|
|
3
|
+
import { OverridableComponent } from '@mui/types';
|
|
4
|
+
import { ContainerProps, ContainerTypeMap } from './ContainerProps';
|
|
5
|
+
import { Theme as DefaultTheme } from '../createTheme';
|
|
6
|
+
interface StyleFnProps<Theme> extends ContainerProps {
|
|
7
|
+
theme: Theme;
|
|
8
|
+
ownerState: ContainerProps;
|
|
9
|
+
}
|
|
10
|
+
declare type RequiredThemeStructure = Pick<DefaultTheme, 'breakpoints' | 'spacing'>;
|
|
11
|
+
export default function createContainer<Theme extends RequiredThemeStructure = DefaultTheme>(options?: {
|
|
12
|
+
createStyledComponent?: (...styles: Array<Interpolation<StyleFnProps<Theme>>>) => StyledComponent<ContainerProps>;
|
|
13
|
+
useThemeProps?: (inProps: ContainerProps) => ContainerProps & {
|
|
14
|
+
component?: React.ElementType;
|
|
15
|
+
};
|
|
16
|
+
componentName?: string;
|
|
17
|
+
}): OverridableComponent<ContainerTypeMap<{}, "div">>;
|
|
18
|
+
export {};
|
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;
|
|
@@ -339,7 +339,8 @@ function createCssVarsProvider(options) {
|
|
|
339
339
|
const getInitColorSchemeScript = params => (0, _getInitColorSchemeScript.default)((0, _extends2.default)({
|
|
340
340
|
attribute: defaultAttribute,
|
|
341
341
|
colorSchemeStorageKey: defaultColorSchemeStorageKey,
|
|
342
|
-
modeStorageKey: defaultModeStorageKey
|
|
342
|
+
modeStorageKey: defaultModeStorageKey,
|
|
343
|
+
enableColorScheme: designSystemEnableColorScheme
|
|
343
344
|
}, params));
|
|
344
345
|
|
|
345
346
|
return {
|
|
@@ -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,40 +1,45 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
export declare const DEFAULT_MODE_STORAGE_KEY = "mode";
|
|
3
|
-
export declare const DEFAULT_COLOR_SCHEME_STORAGE_KEY = "color-scheme";
|
|
4
|
-
export declare const DEFAULT_ATTRIBUTE = "data-color-scheme";
|
|
5
|
-
export interface GetInitColorSchemeScriptOptions {
|
|
6
|
-
/**
|
|
7
|
-
*
|
|
8
|
-
* @default
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
*
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
*
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
*
|
|
26
|
-
* @default '
|
|
27
|
-
*/
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* localStorage key used to store `
|
|
31
|
-
* @default '
|
|
32
|
-
*/
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
*
|
|
36
|
-
* @default '
|
|
37
|
-
*/
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export declare const DEFAULT_MODE_STORAGE_KEY = "mode";
|
|
3
|
+
export declare const DEFAULT_COLOR_SCHEME_STORAGE_KEY = "color-scheme";
|
|
4
|
+
export declare const DEFAULT_ATTRIBUTE = "data-color-scheme";
|
|
5
|
+
export interface GetInitColorSchemeScriptOptions {
|
|
6
|
+
/**
|
|
7
|
+
* Indicate to the browser which color scheme is used (light or dark) for rendering built-in UI
|
|
8
|
+
* @default true
|
|
9
|
+
*/
|
|
10
|
+
enableColorScheme?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* If `true`, the initial color scheme is set to the user's prefers-color-scheme mode
|
|
13
|
+
* @default false
|
|
14
|
+
*/
|
|
15
|
+
enableSystem?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* The default color scheme to be used on the light mode
|
|
18
|
+
*/
|
|
19
|
+
defaultLightColorScheme?: string;
|
|
20
|
+
/**
|
|
21
|
+
* The default color scheme to be used on the dark mode
|
|
22
|
+
*/
|
|
23
|
+
defaultDarkColorScheme?: string;
|
|
24
|
+
/**
|
|
25
|
+
* The node (provided as string) used to attach the color-scheme attribute
|
|
26
|
+
* @default 'document.documentElement'
|
|
27
|
+
*/
|
|
28
|
+
colorSchemeNode?: string;
|
|
29
|
+
/**
|
|
30
|
+
* localStorage key used to store `mode`
|
|
31
|
+
* @default 'mode'
|
|
32
|
+
*/
|
|
33
|
+
modeStorageKey?: string;
|
|
34
|
+
/**
|
|
35
|
+
* localStorage key used to store `colorScheme`
|
|
36
|
+
* @default 'color-scheme'
|
|
37
|
+
*/
|
|
38
|
+
colorSchemeStorageKey?: string;
|
|
39
|
+
/**
|
|
40
|
+
* DOM attribute for applying color scheme
|
|
41
|
+
* @default 'data-color-scheme'
|
|
42
|
+
*/
|
|
43
|
+
attribute?: string;
|
|
44
|
+
}
|
|
45
|
+
export default function getInitColorSchemeScript(options?: GetInitColorSchemeScriptOptions): JSX.Element;
|
|
@@ -23,6 +23,7 @@ exports.DEFAULT_ATTRIBUTE = DEFAULT_ATTRIBUTE;
|
|
|
23
23
|
|
|
24
24
|
function getInitColorSchemeScript(options) {
|
|
25
25
|
const {
|
|
26
|
+
enableColorScheme = true,
|
|
26
27
|
enableSystem = false,
|
|
27
28
|
defaultLightColorScheme = 'light',
|
|
28
29
|
defaultDarkColorScheme = 'dark',
|
|
@@ -36,13 +37,16 @@ function getInitColorSchemeScript(options) {
|
|
|
36
37
|
dangerouslySetInnerHTML: {
|
|
37
38
|
__html: `(function() { try {
|
|
38
39
|
var mode = localStorage.getItem('${modeStorageKey}');
|
|
40
|
+
var cssColorScheme = mode;
|
|
39
41
|
var colorScheme = '';
|
|
40
42
|
if (mode === 'system' || (!mode && !!${enableSystem})) {
|
|
41
43
|
// handle system mode
|
|
42
44
|
var mql = window.matchMedia('(prefers-color-scheme: dark)');
|
|
43
45
|
if (mql.matches) {
|
|
46
|
+
cssColorScheme = 'dark';
|
|
44
47
|
colorScheme = localStorage.getItem('${colorSchemeStorageKey}-dark') || '${defaultDarkColorScheme}';
|
|
45
48
|
} else {
|
|
49
|
+
cssColorScheme = 'light';
|
|
46
50
|
colorScheme = localStorage.getItem('${colorSchemeStorageKey}-light') || '${defaultLightColorScheme}';
|
|
47
51
|
}
|
|
48
52
|
}
|
|
@@ -55,6 +59,9 @@ function getInitColorSchemeScript(options) {
|
|
|
55
59
|
if (colorScheme) {
|
|
56
60
|
${colorSchemeNode}.setAttribute('${attribute}', colorScheme);
|
|
57
61
|
}
|
|
62
|
+
if (${enableColorScheme} && !!cssColorScheme) {
|
|
63
|
+
${colorSchemeNode}.style.setProperty('color-scheme', cssColorScheme);
|
|
64
|
+
}
|
|
58
65
|
} catch (e) {} })();`
|
|
59
66
|
}
|
|
60
67
|
});
|
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';
|
|
@@ -1,53 +1,53 @@
|
|
|
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
|
-
interface UseCurrentColoSchemeOptions<SupportedColorScheme extends string> {
|
|
44
|
-
defaultLightColorScheme: SupportedColorScheme;
|
|
45
|
-
defaultDarkColorScheme: SupportedColorScheme;
|
|
46
|
-
supportedColorSchemes: Array<SupportedColorScheme>;
|
|
47
|
-
defaultMode?: Mode;
|
|
48
|
-
modeStorageKey?: string;
|
|
49
|
-
colorSchemeStorageKey?: string;
|
|
50
|
-
storageWindow?: Window | null;
|
|
51
|
-
}
|
|
52
|
-
export default function useCurrentColorScheme<SupportedColorScheme extends string>(options: UseCurrentColoSchemeOptions<SupportedColorScheme>): Result<SupportedColorScheme>;
|
|
53
|
-
export {};
|
|
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
|
+
interface UseCurrentColoSchemeOptions<SupportedColorScheme extends string> {
|
|
44
|
+
defaultLightColorScheme: SupportedColorScheme;
|
|
45
|
+
defaultDarkColorScheme: SupportedColorScheme;
|
|
46
|
+
supportedColorSchemes: Array<SupportedColorScheme>;
|
|
47
|
+
defaultMode?: Mode;
|
|
48
|
+
modeStorageKey?: string;
|
|
49
|
+
colorSchemeStorageKey?: string;
|
|
50
|
+
storageWindow?: Window | null;
|
|
51
|
+
}
|
|
52
|
+
export default function useCurrentColorScheme<SupportedColorScheme extends string>(options: UseCurrentColoSchemeOptions<SupportedColorScheme>): Result<SupportedColorScheme>;
|
|
53
|
+
export {};
|
|
@@ -314,7 +314,8 @@ export default function createCssVarsProvider(options) {
|
|
|
314
314
|
const getInitColorSchemeScript = params => systemGetInitColorSchemeScript(_extends({
|
|
315
315
|
attribute: defaultAttribute,
|
|
316
316
|
colorSchemeStorageKey: defaultColorSchemeStorageKey,
|
|
317
|
-
modeStorageKey: defaultModeStorageKey
|
|
317
|
+
modeStorageKey: defaultModeStorageKey,
|
|
318
|
+
enableColorScheme: designSystemEnableColorScheme
|
|
318
319
|
}, params));
|
|
319
320
|
|
|
320
321
|
return {
|
|
@@ -5,6 +5,7 @@ export const DEFAULT_COLOR_SCHEME_STORAGE_KEY = 'color-scheme';
|
|
|
5
5
|
export const DEFAULT_ATTRIBUTE = 'data-color-scheme';
|
|
6
6
|
export default function getInitColorSchemeScript(options) {
|
|
7
7
|
const {
|
|
8
|
+
enableColorScheme = true,
|
|
8
9
|
enableSystem = false,
|
|
9
10
|
defaultLightColorScheme = 'light',
|
|
10
11
|
defaultDarkColorScheme = 'dark',
|
|
@@ -18,13 +19,16 @@ export default function getInitColorSchemeScript(options) {
|
|
|
18
19
|
dangerouslySetInnerHTML: {
|
|
19
20
|
__html: `(function() { try {
|
|
20
21
|
var mode = localStorage.getItem('${modeStorageKey}');
|
|
22
|
+
var cssColorScheme = mode;
|
|
21
23
|
var colorScheme = '';
|
|
22
24
|
if (mode === 'system' || (!mode && !!${enableSystem})) {
|
|
23
25
|
// handle system mode
|
|
24
26
|
var mql = window.matchMedia('(prefers-color-scheme: dark)');
|
|
25
27
|
if (mql.matches) {
|
|
28
|
+
cssColorScheme = 'dark';
|
|
26
29
|
colorScheme = localStorage.getItem('${colorSchemeStorageKey}-dark') || '${defaultDarkColorScheme}';
|
|
27
30
|
} else {
|
|
31
|
+
cssColorScheme = 'light';
|
|
28
32
|
colorScheme = localStorage.getItem('${colorSchemeStorageKey}-light') || '${defaultLightColorScheme}';
|
|
29
33
|
}
|
|
30
34
|
}
|
|
@@ -37,6 +41,9 @@ export default function getInitColorSchemeScript(options) {
|
|
|
37
41
|
if (colorScheme) {
|
|
38
42
|
${colorSchemeNode}.setAttribute('${attribute}', colorScheme);
|
|
39
43
|
}
|
|
44
|
+
if (${enableColorScheme} && !!cssColorScheme) {
|
|
45
|
+
${colorSchemeNode}.style.setProperty('color-scheme', cssColorScheme);
|
|
46
|
+
}
|
|
40
47
|
} catch (e) {} })();`
|
|
41
48
|
}
|
|
42
49
|
});
|
package/index.js
CHANGED
package/index.spec.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
|
@@ -342,7 +342,8 @@ export default function createCssVarsProvider(options) {
|
|
|
342
342
|
return systemGetInitColorSchemeScript(_extends({
|
|
343
343
|
attribute: defaultAttribute,
|
|
344
344
|
colorSchemeStorageKey: defaultColorSchemeStorageKey,
|
|
345
|
-
modeStorageKey: defaultModeStorageKey
|
|
345
|
+
modeStorageKey: defaultModeStorageKey,
|
|
346
|
+
enableColorScheme: designSystemEnableColorScheme
|
|
346
347
|
}, params));
|
|
347
348
|
};
|
|
348
349
|
|
|
@@ -5,6 +5,8 @@ export var DEFAULT_COLOR_SCHEME_STORAGE_KEY = 'color-scheme';
|
|
|
5
5
|
export var DEFAULT_ATTRIBUTE = 'data-color-scheme';
|
|
6
6
|
export default function getInitColorSchemeScript(options) {
|
|
7
7
|
var _ref = options || {},
|
|
8
|
+
_ref$enableColorSchem = _ref.enableColorScheme,
|
|
9
|
+
enableColorScheme = _ref$enableColorSchem === void 0 ? true : _ref$enableColorSchem,
|
|
8
10
|
_ref$enableSystem = _ref.enableSystem,
|
|
9
11
|
enableSystem = _ref$enableSystem === void 0 ? false : _ref$enableSystem,
|
|
10
12
|
_ref$defaultLightColo = _ref.defaultLightColorScheme,
|
|
@@ -23,7 +25,7 @@ export default function getInitColorSchemeScript(options) {
|
|
|
23
25
|
return /*#__PURE__*/_jsx("script", {
|
|
24
26
|
// eslint-disable-next-line react/no-danger
|
|
25
27
|
dangerouslySetInnerHTML: {
|
|
26
|
-
__html: "(function() { try {\n var mode = localStorage.getItem('".concat(modeStorageKey, "');\n var colorScheme = '';\n if (mode === 'system' || (!mode && !!").concat(enableSystem, ")) {\n // handle system mode\n var mql = window.matchMedia('(prefers-color-scheme: dark)');\n if (mql.matches) {\n colorScheme = localStorage.getItem('").concat(colorSchemeStorageKey, "-dark') || '").concat(defaultDarkColorScheme, "';\n } else {\n colorScheme = localStorage.getItem('").concat(colorSchemeStorageKey, "-light') || '").concat(defaultLightColorScheme, "';\n }\n }\n if (mode === 'light') {\n colorScheme = localStorage.getItem('").concat(colorSchemeStorageKey, "-light') || '").concat(defaultLightColorScheme, "';\n }\n if (mode === 'dark') {\n colorScheme = localStorage.getItem('").concat(colorSchemeStorageKey, "-dark') || '").concat(defaultDarkColorScheme, "';\n }\n if (colorScheme) {\n ").concat(colorSchemeNode, ".setAttribute('").concat(attribute, "', colorScheme);\n }\n } catch (e) {} })();")
|
|
28
|
+
__html: "(function() { try {\n var mode = localStorage.getItem('".concat(modeStorageKey, "');\n var cssColorScheme = mode;\n var colorScheme = '';\n if (mode === 'system' || (!mode && !!").concat(enableSystem, ")) {\n // handle system mode\n var mql = window.matchMedia('(prefers-color-scheme: dark)');\n if (mql.matches) {\n cssColorScheme = 'dark';\n colorScheme = localStorage.getItem('").concat(colorSchemeStorageKey, "-dark') || '").concat(defaultDarkColorScheme, "';\n } else {\n cssColorScheme = 'light';\n colorScheme = localStorage.getItem('").concat(colorSchemeStorageKey, "-light') || '").concat(defaultLightColorScheme, "';\n }\n }\n if (mode === 'light') {\n colorScheme = localStorage.getItem('").concat(colorSchemeStorageKey, "-light') || '").concat(defaultLightColorScheme, "';\n }\n if (mode === 'dark') {\n colorScheme = localStorage.getItem('").concat(colorSchemeStorageKey, "-dark') || '").concat(defaultDarkColorScheme, "';\n }\n if (colorScheme) {\n ").concat(colorSchemeNode, ".setAttribute('").concat(attribute, "', colorScheme);\n }\n if (").concat(enableColorScheme, " && !!cssColorScheme) {\n ").concat(colorSchemeNode, ".style.setProperty('color-scheme', cssColorScheme);\n }\n } catch (e) {} })();")
|
|
27
29
|
}
|
|
28
30
|
});
|
|
29
31
|
}
|
package/legacy/index.js
CHANGED
|
@@ -314,7 +314,8 @@ export default function createCssVarsProvider(options) {
|
|
|
314
314
|
const getInitColorSchemeScript = params => systemGetInitColorSchemeScript(_extends({
|
|
315
315
|
attribute: defaultAttribute,
|
|
316
316
|
colorSchemeStorageKey: defaultColorSchemeStorageKey,
|
|
317
|
-
modeStorageKey: defaultModeStorageKey
|
|
317
|
+
modeStorageKey: defaultModeStorageKey,
|
|
318
|
+
enableColorScheme: designSystemEnableColorScheme
|
|
318
319
|
}, params));
|
|
319
320
|
|
|
320
321
|
return {
|
|
@@ -5,6 +5,7 @@ export const DEFAULT_COLOR_SCHEME_STORAGE_KEY = 'color-scheme';
|
|
|
5
5
|
export const DEFAULT_ATTRIBUTE = 'data-color-scheme';
|
|
6
6
|
export default function getInitColorSchemeScript(options) {
|
|
7
7
|
const {
|
|
8
|
+
enableColorScheme = true,
|
|
8
9
|
enableSystem = false,
|
|
9
10
|
defaultLightColorScheme = 'light',
|
|
10
11
|
defaultDarkColorScheme = 'dark',
|
|
@@ -18,13 +19,16 @@ export default function getInitColorSchemeScript(options) {
|
|
|
18
19
|
dangerouslySetInnerHTML: {
|
|
19
20
|
__html: `(function() { try {
|
|
20
21
|
var mode = localStorage.getItem('${modeStorageKey}');
|
|
22
|
+
var cssColorScheme = mode;
|
|
21
23
|
var colorScheme = '';
|
|
22
24
|
if (mode === 'system' || (!mode && !!${enableSystem})) {
|
|
23
25
|
// handle system mode
|
|
24
26
|
var mql = window.matchMedia('(prefers-color-scheme: dark)');
|
|
25
27
|
if (mql.matches) {
|
|
28
|
+
cssColorScheme = 'dark';
|
|
26
29
|
colorScheme = localStorage.getItem('${colorSchemeStorageKey}-dark') || '${defaultDarkColorScheme}';
|
|
27
30
|
} else {
|
|
31
|
+
cssColorScheme = 'light';
|
|
28
32
|
colorScheme = localStorage.getItem('${colorSchemeStorageKey}-light') || '${defaultLightColorScheme}';
|
|
29
33
|
}
|
|
30
34
|
}
|
|
@@ -37,6 +41,9 @@ export default function getInitColorSchemeScript(options) {
|
|
|
37
41
|
if (colorScheme) {
|
|
38
42
|
${colorSchemeNode}.setAttribute('${attribute}', colorScheme);
|
|
39
43
|
}
|
|
44
|
+
if (${enableColorScheme} && !!cssColorScheme) {
|
|
45
|
+
${colorSchemeNode}.style.setProperty('color-scheme', cssColorScheme);
|
|
46
|
+
}
|
|
40
47
|
} catch (e) {} })();`
|
|
41
48
|
}
|
|
42
49
|
});
|
package/modern/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mui/system",
|
|
3
|
-
"version": "5.8.
|
|
3
|
+
"version": "5.8.6",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": "MUI Team",
|
|
6
6
|
"description": "CSS utilities for rapidly laying out custom designs.",
|
|
@@ -44,10 +44,10 @@
|
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"@babel/runtime": "^7.17.2",
|
|
47
|
-
"@mui/private-theming": "^5.8.
|
|
47
|
+
"@mui/private-theming": "^5.8.6",
|
|
48
48
|
"@mui/styled-engine": "^5.8.0",
|
|
49
49
|
"@mui/types": "^7.1.4",
|
|
50
|
-
"@mui/utils": "^5.8.
|
|
50
|
+
"@mui/utils": "^5.8.6",
|
|
51
51
|
"clsx": "^1.1.1",
|
|
52
52
|
"csstype": "^3.1.0",
|
|
53
53
|
"prop-types": "^15.8.1"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|