@mui/system 5.10.2 → 5.10.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Box/Box.d.ts +10 -10
- package/CHANGELOG.md +159 -0
- package/Stack/Stack.d.ts +1 -0
- package/Stack/Stack.js +1 -0
- package/Stack/createStack.d.ts +1 -1
- package/Unstable_Grid/createGrid.d.ts +1 -1
- package/cssVars/cssVarsParser.d.ts +1 -1
- package/cssVars/useCurrentColorScheme.js +53 -52
- package/esm/Stack/Stack.js +1 -0
- package/esm/cssVars/useCurrentColorScheme.js +54 -51
- package/index.js +1 -1
- package/legacy/Stack/Stack.js +1 -0
- package/legacy/cssVars/useCurrentColorScheme.js +54 -51
- package/legacy/index.js +1 -1
- package/modern/Stack/Stack.js +1 -0
- package/modern/cssVars/useCurrentColorScheme.js +54 -51
- package/modern/index.js +1 -1
- package/package.json +6 -6
- package/useThemeProps/getThemeProps.d.ts +5 -5
package/Box/Box.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ export type SimpleStyleFunction<PropKey extends keyof any> = StyleFunction<
|
|
|
18
18
|
> & { filterProps: string[] };
|
|
19
19
|
|
|
20
20
|
// borders.js
|
|
21
|
-
export const borders: SimpleStyleFunction<
|
|
21
|
+
export declare const borders: SimpleStyleFunction<
|
|
22
22
|
| 'border'
|
|
23
23
|
| 'borderTop'
|
|
24
24
|
| 'borderRight'
|
|
@@ -28,11 +28,11 @@ export const borders: SimpleStyleFunction<
|
|
|
28
28
|
| 'borderRadius'
|
|
29
29
|
>;
|
|
30
30
|
|
|
31
|
-
export const display: SimpleStyleFunction<
|
|
31
|
+
export declare const display: SimpleStyleFunction<
|
|
32
32
|
'display' | 'displayPrint' | 'overflow' | 'textOverflow' | 'visibility' | 'whiteSpace'
|
|
33
33
|
>;
|
|
34
34
|
|
|
35
|
-
export const flexbox: SimpleStyleFunction<
|
|
35
|
+
export declare const flexbox: SimpleStyleFunction<
|
|
36
36
|
| 'flexBasis'
|
|
37
37
|
| 'flexDirection'
|
|
38
38
|
| 'flexWrap'
|
|
@@ -48,7 +48,7 @@ export const flexbox: SimpleStyleFunction<
|
|
|
48
48
|
| 'justifySelf'
|
|
49
49
|
>;
|
|
50
50
|
|
|
51
|
-
export const grid: SimpleStyleFunction<
|
|
51
|
+
export declare const grid: SimpleStyleFunction<
|
|
52
52
|
| 'gap'
|
|
53
53
|
| 'columnGap'
|
|
54
54
|
| 'rowGap'
|
|
@@ -63,15 +63,15 @@ export const grid: SimpleStyleFunction<
|
|
|
63
63
|
| 'gridArea'
|
|
64
64
|
>;
|
|
65
65
|
|
|
66
|
-
export const palette: SimpleStyleFunction<'bgcolor' | 'color'>;
|
|
66
|
+
export declare const palette: SimpleStyleFunction<'bgcolor' | 'color'>;
|
|
67
67
|
|
|
68
|
-
export const positions: SimpleStyleFunction<
|
|
68
|
+
export declare const positions: SimpleStyleFunction<
|
|
69
69
|
'zIndex' | 'position' | 'top' | 'right' | 'bottom' | 'left'
|
|
70
70
|
>;
|
|
71
71
|
|
|
72
|
-
export const shadows: SimpleStyleFunction<'boxShadow'>;
|
|
72
|
+
export declare const shadows: SimpleStyleFunction<'boxShadow'>;
|
|
73
73
|
|
|
74
|
-
export const sizing: SimpleStyleFunction<
|
|
74
|
+
export declare const sizing: SimpleStyleFunction<
|
|
75
75
|
| 'width'
|
|
76
76
|
| 'maxWidth'
|
|
77
77
|
| 'minWidth'
|
|
@@ -83,7 +83,7 @@ export const sizing: SimpleStyleFunction<
|
|
|
83
83
|
| 'boxSizing'
|
|
84
84
|
>;
|
|
85
85
|
|
|
86
|
-
export const spacing: SimpleStyleFunction<
|
|
86
|
+
export declare const spacing: SimpleStyleFunction<
|
|
87
87
|
| 'm'
|
|
88
88
|
| 'mt'
|
|
89
89
|
| 'mr'
|
|
@@ -114,7 +114,7 @@ export const spacing: SimpleStyleFunction<
|
|
|
114
114
|
| 'paddingY'
|
|
115
115
|
>;
|
|
116
116
|
|
|
117
|
-
export const typography: SimpleStyleFunction<
|
|
117
|
+
export declare const typography: SimpleStyleFunction<
|
|
118
118
|
| 'typography'
|
|
119
119
|
| 'fontFamily'
|
|
120
120
|
| 'fontSize'
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,164 @@
|
|
|
1
1
|
# [Versions](https://mui.com/versions/)
|
|
2
2
|
|
|
3
|
+
## 5.10.5
|
|
4
|
+
|
|
5
|
+
<!-- generated comparing v5.10.4..master -->
|
|
6
|
+
|
|
7
|
+
_Sep 12, 2022_
|
|
8
|
+
|
|
9
|
+
A big thanks to the 12 contributors who made this release possible. Here are some highlights ✨:
|
|
10
|
+
|
|
11
|
+
- 🚀 [Blog post](https://mui.com/blog/introducing-mui-base/) for announcing the release of the MUI Base package is out thanks to @michaldudak.
|
|
12
|
+
- 🚀 Added [`Alert`](https://mui.com/joy-ui/react-alert/), [`Modal`](https://mui.com/joy-ui/react-modal/), [`ListSubheader`](https://mui.com/joy-ui/react-list-subheader/), [`FormControl`](https://mui.com/joy-ui/react-form-control/), [`CircularProgress`](https://mui.com/joy-ui/react-circular-progress/) components to Joy UI (#33859) @hbjORbj @siriwatknp
|
|
13
|
+
- And more 🐛 bug fixes and 📚 documentation improvements.
|
|
14
|
+
|
|
15
|
+
### `@mui/material@5.10.5`
|
|
16
|
+
|
|
17
|
+
- ​<!-- 05 -->[ListItemText] Fix variant mapping in `primaryTypography` (#33880) @iamxukai
|
|
18
|
+
- ​<!-- 03 -->[Timeline] Add left and right aligned timeline demos in docs (#34156) @ZeeshanTamboli
|
|
19
|
+
|
|
20
|
+
### `@mui/joy@5.0.0-alpha.45`
|
|
21
|
+
|
|
22
|
+
- ​<!-- 20 -->[Joy UI] Add `CircularProgress` component (#33869) @hbjORbj
|
|
23
|
+
- ​<!-- 19 -->[Joy UI] Add `FormControl` component (#34187) @siriwatknp
|
|
24
|
+
- ​<!-- 18 -->[Joy UI] Add `ListSubheader` component (#34191) @siriwatknp
|
|
25
|
+
- ​<!-- 17 -->[Joy UI] Add `Modal` component (#34043) @siriwatknp
|
|
26
|
+
- ​<!-- 10 -->[Joy] Fix list value of false or 0 (zero) text is incorrectly grey (#34255) @kushagra010
|
|
27
|
+
- ​<!-- 09 -->[Joy] Adjust typography decorator margin (#34257) @siriwatknp
|
|
28
|
+
- ​<!-- 08 -->[Joy] Miscellaneous fixes (#34193) @siriwatknp
|
|
29
|
+
- ​<!-- 07 -->[Radio][joy] Integrate with form control (#34277) @siriwatknp
|
|
30
|
+
- ​<!-- 06 -->[Joy][textarea] Pass `textarea` props from `componentsProps` (#34223) @HexM7
|
|
31
|
+
|
|
32
|
+
### Docs
|
|
33
|
+
|
|
34
|
+
- ​<!-- 16 -->[blog] Introducing MUI Base (#33778) @michaldudak
|
|
35
|
+
- ​<!-- 13 -->[docs] Fix spelling error (#34209) @ChrystianDeMatos
|
|
36
|
+
- ​<!-- 12 -->[docs] Improve link to the security policy (#34219) @oliviertassinari
|
|
37
|
+
- ​<!-- 11 -->[docs] Fix typo in Joy UI's `Usage` docs (#34200) @zillion504
|
|
38
|
+
- ​<!-- 02 -->[website] Add Lukas to the about page (#34284) @LukasTy
|
|
39
|
+
- ​<!-- 01 -->[website] Update diamond sponsor URL (#34256) @oliviertassinari
|
|
40
|
+
|
|
41
|
+
### Core
|
|
42
|
+
|
|
43
|
+
- ​<!-- 04 -->[test] Replace argos-cli with @argos-ci/core (#34178) @michaldudak
|
|
44
|
+
- ​<!-- 15 -->[core] Create a script to generate codeowners (#34175) @michaldudak
|
|
45
|
+
- ​<!-- 14 -->[core] Add RFC GH issue template (#33871) @bytasv
|
|
46
|
+
|
|
47
|
+
All contributors of this release in alphabetical order: @bytasv, @ChrystianDeMatos, @hbjORbj, @HexM7, @iamxukai, @kushagra010, @LukasTy, @michaldudak, @oliviertassinari, @siriwatknp, @ZeeshanTamboli, @zillion504
|
|
48
|
+
|
|
49
|
+
## 5.10.4
|
|
50
|
+
|
|
51
|
+
<!-- generated comparing v5.10.3..master -->
|
|
52
|
+
|
|
53
|
+
_Sep 5, 2022_
|
|
54
|
+
|
|
55
|
+
A big thanks to the 11 contributors who made this release possible. Here are some highlights ✨:
|
|
56
|
+
|
|
57
|
+
- 🚀 Added [`Alert`](https://mui.com/joy-ui/react-alert/) component to Joy UI (#33859) @hbjORbj
|
|
58
|
+
- Many other 🐛 bug fixes, 📚 documentation, and ⚙️ infrastructure improvements
|
|
59
|
+
|
|
60
|
+
### `@mui/material@5.10.4`
|
|
61
|
+
|
|
62
|
+
- ​<!-- 22 -->[Avatar] Use structured / semantic markup for avatars and avatar groups (#33994) @paulschreiber
|
|
63
|
+
- ​<!-- 05 -->[Steps] Use structured / semantic markup for steps and steppers (#34138) @paulschreiber
|
|
64
|
+
|
|
65
|
+
### `@mui/joy@5.0.0-alpha.44`
|
|
66
|
+
|
|
67
|
+
- ​<!-- 23 -->[Alert][joy] Add `Alert` component (#33859) @hbjORbj
|
|
68
|
+
- ​<!-- 08 -->[Joy] Make the description of `componentsProps` generic (#34140) @hbjORbj
|
|
69
|
+
- ​<!-- 07 -->[Joy] Add tests / classes for `Breadcrumbs` component (#33860) @hbjORbj
|
|
70
|
+
- ​<!-- 06 -->[Select][joy] Fix forwarding listbox `component` prop (#34172) @siriwatknp
|
|
71
|
+
|
|
72
|
+
### `@mui/base@5.0.0-alpha.96`
|
|
73
|
+
|
|
74
|
+
- ​<!-- 21 -->[Select][base] Fix type issues that appeared with TS 4.8 (#34132) @michaldudak
|
|
75
|
+
|
|
76
|
+
### Docs
|
|
77
|
+
|
|
78
|
+
- ​<!-- 15 -->[docs] Add `mui-color-input`, `mui-chips-input` and `mui-tel-input` into the related projects page (#34123) @viclafouch
|
|
79
|
+
- ​<!-- 14 -->[docs] Update sponsors (#34157) @hbjORbj
|
|
80
|
+
- ​<!-- 13 -->[docs] Move 5 component names to Title Case (#34118) @oliviertassinari
|
|
81
|
+
- ​<!-- 12 -->[docs] Fix the color contrast on optional API methods (#34127) @oliviertassinari
|
|
82
|
+
- ​<!-- 11 -->[docs] Fix crash due to using wrong variable (#34171) @siriwatknp
|
|
83
|
+
- ​<!-- 10 -->[docs] Fix a few Base typos (#33986) @ropereraLK
|
|
84
|
+
- ​<!-- 09 -->[docs] Revise Joy UI "Overview" page copy (#34087) @samuelsycamore
|
|
85
|
+
- ​<!-- 20 -->[blog] Fix social cards (#34160) @oliviertassinari
|
|
86
|
+
- ​<!-- 03 -->[website] Allow deep linking to sponsors @oliviertassinari
|
|
87
|
+
- ​<!-- 02 -->[website] Update job descriptions (#34134) @DanailH
|
|
88
|
+
- ​<!-- 01 -->[website] Link Toolpad landing page @oliviertassinari
|
|
89
|
+
|
|
90
|
+
### Core
|
|
91
|
+
|
|
92
|
+
- ​<!-- 19 -->[core] Move renovate config to the repository root (#34180) @oliviertassinari
|
|
93
|
+
- ​<!-- 18 -->[core] Reinstate react/no-unused-prop-types eslint rule (#34125) @Janpot
|
|
94
|
+
- ​<!-- 17 -->[core] Do not append `types` field to packages without index.d.ts (#33952) @michaldudak
|
|
95
|
+
- ​<!-- 16 -->[core] Sanitize input in icon synonyms update script (#33989) @michaldudak
|
|
96
|
+
- ​<!-- 04 -->[test] Allow to pass options to `mousePress` function (#34124) @cherniavskii
|
|
97
|
+
|
|
98
|
+
All contributors of this release in alphabetical order: @cherniavskii, @DanailH, @hbjORbj, @Janpot, @michaldudak, @oliviertassinari, @paulschreiber, @ropereraLK, @samuelsycamore, @siriwatknp, @viclafouch
|
|
99
|
+
|
|
100
|
+
## 5.10.3
|
|
101
|
+
|
|
102
|
+
<!-- generated comparing v5.10.2..master -->
|
|
103
|
+
|
|
104
|
+
_Aug 29, 2022_
|
|
105
|
+
|
|
106
|
+
A big thanks to the 16 contributors who made this release possible. Here are some highlights ✨:
|
|
107
|
+
|
|
108
|
+
- ⚡ @mnajdova implemented an alternative to OverridableComponent to achieve better dev-time performance (#32735)
|
|
109
|
+
- Many other 🐛 bug fixes, 📚 documentation, and ⚙️ infrastructure improvements
|
|
110
|
+
|
|
111
|
+
### `@mui/material@5.10.3`
|
|
112
|
+
|
|
113
|
+
- [Autocomplete][material] Fix value overflow when `disableClearable` is used (#34053) @mnajdova
|
|
114
|
+
- [Autocomplete] Update unstyled demo to not import Material UI (#34060) @oliviertassinari
|
|
115
|
+
- [Slider] Remove SliderInput export from d.ts (#34055) @pieetrus
|
|
116
|
+
- [TablePagination] Fix select variant not working (#33974) @ZeeshanTamboli
|
|
117
|
+
|
|
118
|
+
### `@mui/system@5.10.3`
|
|
119
|
+
|
|
120
|
+
- [system] Fix mode blink when open multiple sessions (#33877) @siriwatknp
|
|
121
|
+
|
|
122
|
+
### `@mui/base@5.0.0-alpha.95`
|
|
123
|
+
|
|
124
|
+
- [Button][base] Prevent too many ref updates (#33882) @michaldudak
|
|
125
|
+
- [Select][base] Fix typo in listbox blur event handler (#34120) @ZeeshanTamboli
|
|
126
|
+
- [TrapFocus] Improve tab test and simplify demo (#34008) @EthanStandel
|
|
127
|
+
|
|
128
|
+
### `@mui/joy@5.0.0-alpha.43`
|
|
129
|
+
|
|
130
|
+
- [Joy] Fix `role` proptypes (#34119) @siriwatknp
|
|
131
|
+
- [Joy] Refine `componentsProps` for all components (#34077) @siriwatknp
|
|
132
|
+
- [Radio][joy] support `componentsProps` as a function (#34022) @siriwatknp
|
|
133
|
+
- [Select][joy] Improve the a11y on the select field demo (#34073) @mnajdova
|
|
134
|
+
- [Textarea][joy] Add `Textarea` component (#33975) @siriwatknp
|
|
135
|
+
|
|
136
|
+
### Docs
|
|
137
|
+
|
|
138
|
+
- [blog] Add Grid v2 announcement (#33926) @siriwatknp
|
|
139
|
+
- [blog] Making customizable components (#33183) @alexfauquette
|
|
140
|
+
- [blog] Improve SEO metadata (#33954) @oliviertassinari
|
|
141
|
+
- [docs] Add introduction Base component demos & general uplift (#33896) @danilo-leal
|
|
142
|
+
- [docs] Fix Gatsby sample config in CSS variables (#34024) @bicstone
|
|
143
|
+
- [docs] Fix 404 link from Joy to React Router (#34115) @oliviertassinari
|
|
144
|
+
- [docs] Fix typo in `Select` component (#34091) @HexM7
|
|
145
|
+
- [docs] Fix 301 links to tss's docs @oliviertassinari
|
|
146
|
+
- [docs] Fixing Joy UI usage snippet (#34049) @JonathanAsbury-SPS
|
|
147
|
+
- [docs] Fix missing JSX closing tag in Tooltip docs (#34064) @hoangph271
|
|
148
|
+
- [website] Add Toolpad to Navigation (#33937) @bharatkashyap
|
|
149
|
+
- [website] Improve SEO meta description for MUI X @oliviertassinari
|
|
150
|
+
- [website] Improve visual look of code demos (#34070) @oliviertassinari
|
|
151
|
+
- [website] Fix `DatePicker` component demo on the home page (#34054) @NaveenPantra
|
|
152
|
+
|
|
153
|
+
### Core
|
|
154
|
+
|
|
155
|
+
- [core] Offer alternative to `OverridableComponent` via module augmentation for better performance (#32735) @mnajdova
|
|
156
|
+
- [core] Fix prop-type warning in regression tests (#34086) @oliviertassinari
|
|
157
|
+
- [core] Specify code owners (#33995) @michaldudak
|
|
158
|
+
- [core] Fix scroll restoration (#34037) @oliviertassinari
|
|
159
|
+
|
|
160
|
+
All contributors of this release in alphabetical order: @alexfauquette, @bharatkashyap, @bicstone, @danilo-leal, @EthanStandel, @HexM7, @hoangph271, @JonathanAsbury-SPS, @michaldudak, @mnajdova, @NaveenPantra, @oliviertassinari, @pieetrus, @renovate[bot], @siriwatknp, @ZeeshanTamboli
|
|
161
|
+
|
|
3
162
|
## 5.10.2
|
|
4
163
|
|
|
5
164
|
<!-- generated comparing v5.10.1..master -->
|
package/Stack/Stack.d.ts
CHANGED
package/Stack/Stack.js
CHANGED
package/Stack/createStack.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ interface StyleFunctionProps {
|
|
|
11
11
|
ownerState: StackOwnerState;
|
|
12
12
|
}
|
|
13
13
|
declare const defaultCreateStyledComponent: import("@mui/styled-engine").CreateStyledComponent<import("../createStyled").MUIStyledCommonProps<any>, Pick<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, keyof React.ClassAttributes<HTMLDivElement> | keyof React.HTMLAttributes<HTMLDivElement>>, {}, any>;
|
|
14
|
-
declare function useThemePropsDefault<T>(props: T): T & {};
|
|
14
|
+
declare function useThemePropsDefault<T extends {}>(props: T): T & {};
|
|
15
15
|
export declare const style: ({ ownerState, theme }: StyleFunctionProps) => any;
|
|
16
16
|
export default function createStack(options?: {
|
|
17
17
|
createStyledComponent?: typeof defaultCreateStyledComponent;
|
|
@@ -2,7 +2,7 @@ import * as React from 'react';
|
|
|
2
2
|
import { OverridableComponent } from '@mui/types';
|
|
3
3
|
import { GridTypeMap } from './GridProps';
|
|
4
4
|
declare const defaultCreateStyledComponent: import("@mui/styled-engine").CreateStyledComponent<import("../createStyled").MUIStyledCommonProps<any>, Pick<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, keyof React.ClassAttributes<HTMLDivElement> | keyof React.HTMLAttributes<HTMLDivElement>>, {}, any>;
|
|
5
|
-
declare function useThemePropsDefault<T>(props: T): T & {};
|
|
5
|
+
declare function useThemePropsDefault<T extends {}>(props: T): T & {};
|
|
6
6
|
export default function createGrid(options?: {
|
|
7
7
|
createStyledComponent?: typeof defaultCreateStyledComponent;
|
|
8
8
|
useThemeProps?: typeof useThemePropsDefault;
|
|
@@ -18,7 +18,7 @@ declare type NestedRecord<V = any> = {
|
|
|
18
18
|
* assignNestedKeys(source, ['palette', 'secondary'], 'var(--palette-secondary)')
|
|
19
19
|
* console.log(source) // { palette: { primary: 'var(--palette-primary)', secondary: 'var(--palette-secondary)' } }
|
|
20
20
|
*/
|
|
21
|
-
export declare const assignNestedKeys: <
|
|
21
|
+
export declare const assignNestedKeys: <T extends string | Record<string, any> | null | undefined = NestedRecord<any>, Value = any>(obj: T, keys: Array<string>, value: Value, arrayKeys?: Array<string>) => void;
|
|
22
22
|
/**
|
|
23
23
|
*
|
|
24
24
|
* @param {Object} obj : source object
|
|
@@ -59,7 +59,7 @@ function getColorScheme(state) {
|
|
|
59
59
|
});
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
function
|
|
62
|
+
function initializeValue(key, defaultValue) {
|
|
63
63
|
if (typeof window === 'undefined') {
|
|
64
64
|
return undefined;
|
|
65
65
|
}
|
|
@@ -68,6 +68,11 @@ function resolveValue(key, defaultValue) {
|
|
|
68
68
|
|
|
69
69
|
try {
|
|
70
70
|
value = localStorage.getItem(key) || undefined;
|
|
71
|
+
|
|
72
|
+
if (!value) {
|
|
73
|
+
// the first time that user enters the site.
|
|
74
|
+
localStorage.setItem(key, defaultValue);
|
|
75
|
+
}
|
|
71
76
|
} catch (e) {// Unsupported
|
|
72
77
|
}
|
|
73
78
|
|
|
@@ -86,23 +91,26 @@ function useCurrentColorScheme(options) {
|
|
|
86
91
|
} = options;
|
|
87
92
|
const joinedColorSchemes = supportedColorSchemes.join(',');
|
|
88
93
|
const [state, setState] = React.useState(() => {
|
|
89
|
-
const initialMode =
|
|
94
|
+
const initialMode = initializeValue(modeStorageKey, defaultMode);
|
|
95
|
+
const lightColorScheme = initializeValue(`${colorSchemeStorageKey}-light`, defaultLightColorScheme);
|
|
96
|
+
const darkColorScheme = initializeValue(`${colorSchemeStorageKey}-dark`, defaultDarkColorScheme);
|
|
90
97
|
return {
|
|
91
98
|
mode: initialMode,
|
|
92
99
|
systemMode: getSystemMode(initialMode),
|
|
93
|
-
lightColorScheme
|
|
94
|
-
darkColorScheme
|
|
100
|
+
lightColorScheme,
|
|
101
|
+
darkColorScheme
|
|
95
102
|
};
|
|
96
103
|
});
|
|
97
104
|
const colorScheme = getColorScheme(state);
|
|
98
105
|
const setMode = React.useCallback(mode => {
|
|
99
106
|
setState(currentState => {
|
|
100
|
-
const newMode = !mode ? defaultMode : mode;
|
|
101
|
-
|
|
102
107
|
if (mode === currentState.mode) {
|
|
108
|
+
// do nothing if mode does not change
|
|
103
109
|
return currentState;
|
|
104
110
|
}
|
|
105
111
|
|
|
112
|
+
const newMode = !mode ? defaultMode : mode;
|
|
113
|
+
|
|
106
114
|
try {
|
|
107
115
|
localStorage.setItem(modeStorageKey, newMode);
|
|
108
116
|
} catch (e) {// Unsupported
|
|
@@ -115,20 +123,25 @@ function useCurrentColorScheme(options) {
|
|
|
115
123
|
});
|
|
116
124
|
}, [modeStorageKey, defaultMode]);
|
|
117
125
|
const setColorScheme = React.useCallback(value => {
|
|
118
|
-
if (!value
|
|
126
|
+
if (!value) {
|
|
127
|
+
setState(currentState => {
|
|
128
|
+
try {
|
|
129
|
+
localStorage.setItem(`${colorSchemeStorageKey}-light`, defaultLightColorScheme);
|
|
130
|
+
localStorage.setItem(`${colorSchemeStorageKey}-dark`, defaultDarkColorScheme);
|
|
131
|
+
} catch (e) {// Unsupported
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return (0, _extends2.default)({}, currentState, {
|
|
135
|
+
lightColorScheme: defaultLightColorScheme,
|
|
136
|
+
darkColorScheme: defaultDarkColorScheme
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
} else if (typeof value === 'string') {
|
|
119
140
|
if (value && !joinedColorSchemes.includes(value)) {
|
|
120
141
|
console.error(`\`${value}\` does not exist in \`theme.colorSchemes\`.`);
|
|
121
142
|
} else {
|
|
122
143
|
setState(currentState => {
|
|
123
144
|
const newState = (0, _extends2.default)({}, currentState);
|
|
124
|
-
|
|
125
|
-
if (!value) {
|
|
126
|
-
// reset to default color scheme
|
|
127
|
-
newState.lightColorScheme = defaultLightColorScheme;
|
|
128
|
-
newState.darkColorScheme = defaultDarkColorScheme;
|
|
129
|
-
return newState;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
145
|
processState(currentState, mode => {
|
|
133
146
|
try {
|
|
134
147
|
localStorage.setItem(`${colorSchemeStorageKey}-${mode}`, value);
|
|
@@ -146,33 +159,40 @@ function useCurrentColorScheme(options) {
|
|
|
146
159
|
return newState;
|
|
147
160
|
});
|
|
148
161
|
}
|
|
149
|
-
} else if (value.light && !joinedColorSchemes.includes(value.light) || value.dark && !joinedColorSchemes.includes(value.dark)) {
|
|
150
|
-
console.error(`\`${value}\` does not exist in \`theme.colorSchemes\`.`);
|
|
151
162
|
} else {
|
|
152
163
|
setState(currentState => {
|
|
153
164
|
const newState = (0, _extends2.default)({}, currentState);
|
|
165
|
+
const newLightColorScheme = value.light === null ? defaultLightColorScheme : value.light;
|
|
166
|
+
const newDarkColorScheme = value.dark === null ? defaultDarkColorScheme : value.dark;
|
|
154
167
|
|
|
155
|
-
if (
|
|
156
|
-
|
|
157
|
-
|
|
168
|
+
if (newLightColorScheme) {
|
|
169
|
+
if (!joinedColorSchemes.includes(newLightColorScheme)) {
|
|
170
|
+
console.error(`\`${newLightColorScheme}\` does not exist in \`theme.colorSchemes\`.`);
|
|
171
|
+
} else {
|
|
172
|
+
newState.lightColorScheme = newLightColorScheme;
|
|
158
173
|
|
|
159
|
-
|
|
160
|
-
|
|
174
|
+
try {
|
|
175
|
+
localStorage.setItem(`${colorSchemeStorageKey}-light`, newLightColorScheme);
|
|
176
|
+
} catch (error) {// Unsupported
|
|
177
|
+
}
|
|
178
|
+
}
|
|
161
179
|
}
|
|
162
180
|
|
|
163
|
-
|
|
164
|
-
|
|
181
|
+
if (newDarkColorScheme) {
|
|
182
|
+
if (!joinedColorSchemes.includes(newDarkColorScheme)) {
|
|
183
|
+
console.error(`\`${newDarkColorScheme}\` does not exist in \`theme.colorSchemes\`.`);
|
|
184
|
+
} else {
|
|
185
|
+
newState.darkColorScheme = newDarkColorScheme;
|
|
165
186
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
187
|
+
try {
|
|
188
|
+
localStorage.setItem(`${colorSchemeStorageKey}-dark`, newDarkColorScheme);
|
|
189
|
+
} catch (error) {// Unsupported
|
|
190
|
+
}
|
|
191
|
+
}
|
|
169
192
|
}
|
|
170
193
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
}
|
|
174
|
-
} catch (e) {// Unsupported
|
|
175
|
-
}
|
|
194
|
+
return newState;
|
|
195
|
+
});
|
|
176
196
|
}
|
|
177
197
|
}, [joinedColorSchemes, colorSchemeStorageKey, defaultLightColorScheme, defaultDarkColorScheme]);
|
|
178
198
|
const handleMediaQuery = React.useCallback(e => {
|
|
@@ -194,26 +214,7 @@ function useCurrentColorScheme(options) {
|
|
|
194
214
|
media.addListener(handler);
|
|
195
215
|
handler(media);
|
|
196
216
|
return () => media.removeListener(handler);
|
|
197
|
-
}, []); //
|
|
198
|
-
|
|
199
|
-
React.useEffect(() => {
|
|
200
|
-
try {
|
|
201
|
-
if (state.mode) {
|
|
202
|
-
localStorage.setItem(modeStorageKey, state.mode);
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
processState(state, mode => {
|
|
206
|
-
if (mode === 'light') {
|
|
207
|
-
localStorage.setItem(`${colorSchemeStorageKey}-light`, state.lightColorScheme);
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
if (mode === 'dark') {
|
|
211
|
-
localStorage.setItem(`${colorSchemeStorageKey}-dark`, state.darkColorScheme);
|
|
212
|
-
}
|
|
213
|
-
});
|
|
214
|
-
} catch (e) {// Unsupported
|
|
215
|
-
}
|
|
216
|
-
}, [state, colorSchemeStorageKey, modeStorageKey]); // Handle when localStorage has changed
|
|
217
|
+
}, []); // Handle when localStorage has changed
|
|
217
218
|
|
|
218
219
|
React.useEffect(() => {
|
|
219
220
|
const handleStorage = event => {
|
package/esm/Stack/Stack.js
CHANGED
|
@@ -41,7 +41,7 @@ export function getColorScheme(state) {
|
|
|
41
41
|
});
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
function
|
|
44
|
+
function initializeValue(key, defaultValue) {
|
|
45
45
|
if (typeof window === 'undefined') {
|
|
46
46
|
return undefined;
|
|
47
47
|
}
|
|
@@ -50,6 +50,11 @@ function resolveValue(key, defaultValue) {
|
|
|
50
50
|
|
|
51
51
|
try {
|
|
52
52
|
value = localStorage.getItem(key) || undefined;
|
|
53
|
+
|
|
54
|
+
if (!value) {
|
|
55
|
+
// the first time that user enters the site.
|
|
56
|
+
localStorage.setItem(key, defaultValue);
|
|
57
|
+
}
|
|
53
58
|
} catch (e) {// Unsupported
|
|
54
59
|
}
|
|
55
60
|
|
|
@@ -68,23 +73,26 @@ export default function useCurrentColorScheme(options) {
|
|
|
68
73
|
} = options;
|
|
69
74
|
const joinedColorSchemes = supportedColorSchemes.join(',');
|
|
70
75
|
const [state, setState] = React.useState(() => {
|
|
71
|
-
const initialMode =
|
|
76
|
+
const initialMode = initializeValue(modeStorageKey, defaultMode);
|
|
77
|
+
const lightColorScheme = initializeValue(`${colorSchemeStorageKey}-light`, defaultLightColorScheme);
|
|
78
|
+
const darkColorScheme = initializeValue(`${colorSchemeStorageKey}-dark`, defaultDarkColorScheme);
|
|
72
79
|
return {
|
|
73
80
|
mode: initialMode,
|
|
74
81
|
systemMode: getSystemMode(initialMode),
|
|
75
|
-
lightColorScheme
|
|
76
|
-
darkColorScheme
|
|
82
|
+
lightColorScheme,
|
|
83
|
+
darkColorScheme
|
|
77
84
|
};
|
|
78
85
|
});
|
|
79
86
|
const colorScheme = getColorScheme(state);
|
|
80
87
|
const setMode = React.useCallback(mode => {
|
|
81
88
|
setState(currentState => {
|
|
82
|
-
const newMode = !mode ? defaultMode : mode;
|
|
83
|
-
|
|
84
89
|
if (mode === currentState.mode) {
|
|
90
|
+
// do nothing if mode does not change
|
|
85
91
|
return currentState;
|
|
86
92
|
}
|
|
87
93
|
|
|
94
|
+
const newMode = !mode ? defaultMode : mode;
|
|
95
|
+
|
|
88
96
|
try {
|
|
89
97
|
localStorage.setItem(modeStorageKey, newMode);
|
|
90
98
|
} catch (e) {// Unsupported
|
|
@@ -97,20 +105,26 @@ export default function useCurrentColorScheme(options) {
|
|
|
97
105
|
});
|
|
98
106
|
}, [modeStorageKey, defaultMode]);
|
|
99
107
|
const setColorScheme = React.useCallback(value => {
|
|
100
|
-
if (!value
|
|
108
|
+
if (!value) {
|
|
109
|
+
setState(currentState => {
|
|
110
|
+
try {
|
|
111
|
+
localStorage.setItem(`${colorSchemeStorageKey}-light`, defaultLightColorScheme);
|
|
112
|
+
localStorage.setItem(`${colorSchemeStorageKey}-dark`, defaultDarkColorScheme);
|
|
113
|
+
} catch (e) {// Unsupported
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return _extends({}, currentState, {
|
|
117
|
+
lightColorScheme: defaultLightColorScheme,
|
|
118
|
+
darkColorScheme: defaultDarkColorScheme
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
} else if (typeof value === 'string') {
|
|
101
122
|
if (value && !joinedColorSchemes.includes(value)) {
|
|
102
123
|
console.error(`\`${value}\` does not exist in \`theme.colorSchemes\`.`);
|
|
103
124
|
} else {
|
|
104
125
|
setState(currentState => {
|
|
105
126
|
const newState = _extends({}, currentState);
|
|
106
127
|
|
|
107
|
-
if (!value) {
|
|
108
|
-
// reset to default color scheme
|
|
109
|
-
newState.lightColorScheme = defaultLightColorScheme;
|
|
110
|
-
newState.darkColorScheme = defaultDarkColorScheme;
|
|
111
|
-
return newState;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
128
|
processState(currentState, mode => {
|
|
115
129
|
try {
|
|
116
130
|
localStorage.setItem(`${colorSchemeStorageKey}-${mode}`, value);
|
|
@@ -128,33 +142,41 @@ export default function useCurrentColorScheme(options) {
|
|
|
128
142
|
return newState;
|
|
129
143
|
});
|
|
130
144
|
}
|
|
131
|
-
} else if (value.light && !joinedColorSchemes.includes(value.light) || value.dark && !joinedColorSchemes.includes(value.dark)) {
|
|
132
|
-
console.error(`\`${value}\` does not exist in \`theme.colorSchemes\`.`);
|
|
133
145
|
} else {
|
|
134
146
|
setState(currentState => {
|
|
135
147
|
const newState = _extends({}, currentState);
|
|
136
148
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
149
|
+
const newLightColorScheme = value.light === null ? defaultLightColorScheme : value.light;
|
|
150
|
+
const newDarkColorScheme = value.dark === null ? defaultDarkColorScheme : value.dark;
|
|
151
|
+
|
|
152
|
+
if (newLightColorScheme) {
|
|
153
|
+
if (!joinedColorSchemes.includes(newLightColorScheme)) {
|
|
154
|
+
console.error(`\`${newLightColorScheme}\` does not exist in \`theme.colorSchemes\`.`);
|
|
155
|
+
} else {
|
|
156
|
+
newState.lightColorScheme = newLightColorScheme;
|
|
140
157
|
|
|
141
|
-
|
|
142
|
-
|
|
158
|
+
try {
|
|
159
|
+
localStorage.setItem(`${colorSchemeStorageKey}-light`, newLightColorScheme);
|
|
160
|
+
} catch (error) {// Unsupported
|
|
161
|
+
}
|
|
162
|
+
}
|
|
143
163
|
}
|
|
144
164
|
|
|
145
|
-
|
|
146
|
-
|
|
165
|
+
if (newDarkColorScheme) {
|
|
166
|
+
if (!joinedColorSchemes.includes(newDarkColorScheme)) {
|
|
167
|
+
console.error(`\`${newDarkColorScheme}\` does not exist in \`theme.colorSchemes\`.`);
|
|
168
|
+
} else {
|
|
169
|
+
newState.darkColorScheme = newDarkColorScheme;
|
|
147
170
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
171
|
+
try {
|
|
172
|
+
localStorage.setItem(`${colorSchemeStorageKey}-dark`, newDarkColorScheme);
|
|
173
|
+
} catch (error) {// Unsupported
|
|
174
|
+
}
|
|
175
|
+
}
|
|
151
176
|
}
|
|
152
177
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
}
|
|
156
|
-
} catch (e) {// Unsupported
|
|
157
|
-
}
|
|
178
|
+
return newState;
|
|
179
|
+
});
|
|
158
180
|
}
|
|
159
181
|
}, [joinedColorSchemes, colorSchemeStorageKey, defaultLightColorScheme, defaultDarkColorScheme]);
|
|
160
182
|
const handleMediaQuery = React.useCallback(e => {
|
|
@@ -176,26 +198,7 @@ export default function useCurrentColorScheme(options) {
|
|
|
176
198
|
media.addListener(handler);
|
|
177
199
|
handler(media);
|
|
178
200
|
return () => media.removeListener(handler);
|
|
179
|
-
}, []); //
|
|
180
|
-
|
|
181
|
-
React.useEffect(() => {
|
|
182
|
-
try {
|
|
183
|
-
if (state.mode) {
|
|
184
|
-
localStorage.setItem(modeStorageKey, state.mode);
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
processState(state, mode => {
|
|
188
|
-
if (mode === 'light') {
|
|
189
|
-
localStorage.setItem(`${colorSchemeStorageKey}-light`, state.lightColorScheme);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
if (mode === 'dark') {
|
|
193
|
-
localStorage.setItem(`${colorSchemeStorageKey}-dark`, state.darkColorScheme);
|
|
194
|
-
}
|
|
195
|
-
});
|
|
196
|
-
} catch (e) {// Unsupported
|
|
197
|
-
}
|
|
198
|
-
}, [state, colorSchemeStorageKey, modeStorageKey]); // Handle when localStorage has changed
|
|
201
|
+
}, []); // Handle when localStorage has changed
|
|
199
202
|
|
|
200
203
|
React.useEffect(() => {
|
|
201
204
|
const handleStorage = event => {
|
package/index.js
CHANGED
package/legacy/Stack/Stack.js
CHANGED
|
@@ -41,7 +41,7 @@ export function getColorScheme(state) {
|
|
|
41
41
|
});
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
function
|
|
44
|
+
function initializeValue(key, defaultValue) {
|
|
45
45
|
if (typeof window === 'undefined') {
|
|
46
46
|
return undefined;
|
|
47
47
|
}
|
|
@@ -50,6 +50,11 @@ function resolveValue(key, defaultValue) {
|
|
|
50
50
|
|
|
51
51
|
try {
|
|
52
52
|
value = localStorage.getItem(key) || undefined;
|
|
53
|
+
|
|
54
|
+
if (!value) {
|
|
55
|
+
// the first time that user enters the site.
|
|
56
|
+
localStorage.setItem(key, defaultValue);
|
|
57
|
+
}
|
|
53
58
|
} catch (e) {// Unsupported
|
|
54
59
|
}
|
|
55
60
|
|
|
@@ -72,12 +77,14 @@ export default function useCurrentColorScheme(options) {
|
|
|
72
77
|
var joinedColorSchemes = supportedColorSchemes.join(',');
|
|
73
78
|
|
|
74
79
|
var _React$useState = React.useState(function () {
|
|
75
|
-
var initialMode =
|
|
80
|
+
var initialMode = initializeValue(modeStorageKey, defaultMode);
|
|
81
|
+
var lightColorScheme = initializeValue("".concat(colorSchemeStorageKey, "-light"), defaultLightColorScheme);
|
|
82
|
+
var darkColorScheme = initializeValue("".concat(colorSchemeStorageKey, "-dark"), defaultDarkColorScheme);
|
|
76
83
|
return {
|
|
77
84
|
mode: initialMode,
|
|
78
85
|
systemMode: getSystemMode(initialMode),
|
|
79
|
-
lightColorScheme:
|
|
80
|
-
darkColorScheme:
|
|
86
|
+
lightColorScheme: lightColorScheme,
|
|
87
|
+
darkColorScheme: darkColorScheme
|
|
81
88
|
};
|
|
82
89
|
}),
|
|
83
90
|
state = _React$useState[0],
|
|
@@ -86,12 +93,13 @@ export default function useCurrentColorScheme(options) {
|
|
|
86
93
|
var colorScheme = getColorScheme(state);
|
|
87
94
|
var setMode = React.useCallback(function (mode) {
|
|
88
95
|
setState(function (currentState) {
|
|
89
|
-
var newMode = !mode ? defaultMode : mode;
|
|
90
|
-
|
|
91
96
|
if (mode === currentState.mode) {
|
|
97
|
+
// do nothing if mode does not change
|
|
92
98
|
return currentState;
|
|
93
99
|
}
|
|
94
100
|
|
|
101
|
+
var newMode = !mode ? defaultMode : mode;
|
|
102
|
+
|
|
95
103
|
try {
|
|
96
104
|
localStorage.setItem(modeStorageKey, newMode);
|
|
97
105
|
} catch (e) {// Unsupported
|
|
@@ -104,20 +112,26 @@ export default function useCurrentColorScheme(options) {
|
|
|
104
112
|
});
|
|
105
113
|
}, [modeStorageKey, defaultMode]);
|
|
106
114
|
var setColorScheme = React.useCallback(function (value) {
|
|
107
|
-
if (!value
|
|
115
|
+
if (!value) {
|
|
116
|
+
setState(function (currentState) {
|
|
117
|
+
try {
|
|
118
|
+
localStorage.setItem("".concat(colorSchemeStorageKey, "-light"), defaultLightColorScheme);
|
|
119
|
+
localStorage.setItem("".concat(colorSchemeStorageKey, "-dark"), defaultDarkColorScheme);
|
|
120
|
+
} catch (e) {// Unsupported
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return _extends({}, currentState, {
|
|
124
|
+
lightColorScheme: defaultLightColorScheme,
|
|
125
|
+
darkColorScheme: defaultDarkColorScheme
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
} else if (typeof value === 'string') {
|
|
108
129
|
if (value && !joinedColorSchemes.includes(value)) {
|
|
109
130
|
console.error("`".concat(value, "` does not exist in `theme.colorSchemes`."));
|
|
110
131
|
} else {
|
|
111
132
|
setState(function (currentState) {
|
|
112
133
|
var newState = _extends({}, currentState);
|
|
113
134
|
|
|
114
|
-
if (!value) {
|
|
115
|
-
// reset to default color scheme
|
|
116
|
-
newState.lightColorScheme = defaultLightColorScheme;
|
|
117
|
-
newState.darkColorScheme = defaultDarkColorScheme;
|
|
118
|
-
return newState;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
135
|
processState(currentState, function (mode) {
|
|
122
136
|
try {
|
|
123
137
|
localStorage.setItem("".concat(colorSchemeStorageKey, "-").concat(mode), value);
|
|
@@ -135,33 +149,41 @@ export default function useCurrentColorScheme(options) {
|
|
|
135
149
|
return newState;
|
|
136
150
|
});
|
|
137
151
|
}
|
|
138
|
-
} else if (value.light && !joinedColorSchemes.includes(value.light) || value.dark && !joinedColorSchemes.includes(value.dark)) {
|
|
139
|
-
console.error("`".concat(value, "` does not exist in `theme.colorSchemes`."));
|
|
140
152
|
} else {
|
|
141
153
|
setState(function (currentState) {
|
|
142
154
|
var newState = _extends({}, currentState);
|
|
143
155
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
}
|
|
156
|
+
var newLightColorScheme = value.light === null ? defaultLightColorScheme : value.light;
|
|
157
|
+
var newDarkColorScheme = value.dark === null ? defaultDarkColorScheme : value.dark;
|
|
147
158
|
|
|
148
|
-
if (
|
|
149
|
-
|
|
159
|
+
if (newLightColorScheme) {
|
|
160
|
+
if (!joinedColorSchemes.includes(newLightColorScheme)) {
|
|
161
|
+
console.error("`".concat(newLightColorScheme, "` does not exist in `theme.colorSchemes`."));
|
|
162
|
+
} else {
|
|
163
|
+
newState.lightColorScheme = newLightColorScheme;
|
|
164
|
+
|
|
165
|
+
try {
|
|
166
|
+
localStorage.setItem("".concat(colorSchemeStorageKey, "-light"), newLightColorScheme);
|
|
167
|
+
} catch (error) {// Unsupported
|
|
168
|
+
}
|
|
169
|
+
}
|
|
150
170
|
}
|
|
151
171
|
|
|
152
|
-
|
|
153
|
-
|
|
172
|
+
if (newDarkColorScheme) {
|
|
173
|
+
if (!joinedColorSchemes.includes(newDarkColorScheme)) {
|
|
174
|
+
console.error("`".concat(newDarkColorScheme, "` does not exist in `theme.colorSchemes`."));
|
|
175
|
+
} else {
|
|
176
|
+
newState.darkColorScheme = newDarkColorScheme;
|
|
154
177
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
178
|
+
try {
|
|
179
|
+
localStorage.setItem("".concat(colorSchemeStorageKey, "-dark"), newDarkColorScheme);
|
|
180
|
+
} catch (error) {// Unsupported
|
|
181
|
+
}
|
|
182
|
+
}
|
|
158
183
|
}
|
|
159
184
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
}
|
|
163
|
-
} catch (e) {// Unsupported
|
|
164
|
-
}
|
|
185
|
+
return newState;
|
|
186
|
+
});
|
|
165
187
|
}
|
|
166
188
|
}, [joinedColorSchemes, colorSchemeStorageKey, defaultLightColorScheme, defaultDarkColorScheme]);
|
|
167
189
|
var handleMediaQuery = React.useCallback(function (e) {
|
|
@@ -189,26 +211,7 @@ export default function useCurrentColorScheme(options) {
|
|
|
189
211
|
return function () {
|
|
190
212
|
return media.removeListener(handler);
|
|
191
213
|
};
|
|
192
|
-
}, []); //
|
|
193
|
-
|
|
194
|
-
React.useEffect(function () {
|
|
195
|
-
try {
|
|
196
|
-
if (state.mode) {
|
|
197
|
-
localStorage.setItem(modeStorageKey, state.mode);
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
processState(state, function (mode) {
|
|
201
|
-
if (mode === 'light') {
|
|
202
|
-
localStorage.setItem("".concat(colorSchemeStorageKey, "-light"), state.lightColorScheme);
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
if (mode === 'dark') {
|
|
206
|
-
localStorage.setItem("".concat(colorSchemeStorageKey, "-dark"), state.darkColorScheme);
|
|
207
|
-
}
|
|
208
|
-
});
|
|
209
|
-
} catch (e) {// Unsupported
|
|
210
|
-
}
|
|
211
|
-
}, [state, colorSchemeStorageKey, modeStorageKey]); // Handle when localStorage has changed
|
|
214
|
+
}, []); // Handle when localStorage has changed
|
|
212
215
|
|
|
213
216
|
React.useEffect(function () {
|
|
214
217
|
var handleStorage = function handleStorage(event) {
|
package/legacy/index.js
CHANGED
package/modern/Stack/Stack.js
CHANGED
|
@@ -41,7 +41,7 @@ export function getColorScheme(state) {
|
|
|
41
41
|
});
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
function
|
|
44
|
+
function initializeValue(key, defaultValue) {
|
|
45
45
|
if (typeof window === 'undefined') {
|
|
46
46
|
return undefined;
|
|
47
47
|
}
|
|
@@ -50,6 +50,11 @@ function resolveValue(key, defaultValue) {
|
|
|
50
50
|
|
|
51
51
|
try {
|
|
52
52
|
value = localStorage.getItem(key) || undefined;
|
|
53
|
+
|
|
54
|
+
if (!value) {
|
|
55
|
+
// the first time that user enters the site.
|
|
56
|
+
localStorage.setItem(key, defaultValue);
|
|
57
|
+
}
|
|
53
58
|
} catch (e) {// Unsupported
|
|
54
59
|
}
|
|
55
60
|
|
|
@@ -68,23 +73,26 @@ export default function useCurrentColorScheme(options) {
|
|
|
68
73
|
} = options;
|
|
69
74
|
const joinedColorSchemes = supportedColorSchemes.join(',');
|
|
70
75
|
const [state, setState] = React.useState(() => {
|
|
71
|
-
const initialMode =
|
|
76
|
+
const initialMode = initializeValue(modeStorageKey, defaultMode);
|
|
77
|
+
const lightColorScheme = initializeValue(`${colorSchemeStorageKey}-light`, defaultLightColorScheme);
|
|
78
|
+
const darkColorScheme = initializeValue(`${colorSchemeStorageKey}-dark`, defaultDarkColorScheme);
|
|
72
79
|
return {
|
|
73
80
|
mode: initialMode,
|
|
74
81
|
systemMode: getSystemMode(initialMode),
|
|
75
|
-
lightColorScheme
|
|
76
|
-
darkColorScheme
|
|
82
|
+
lightColorScheme,
|
|
83
|
+
darkColorScheme
|
|
77
84
|
};
|
|
78
85
|
});
|
|
79
86
|
const colorScheme = getColorScheme(state);
|
|
80
87
|
const setMode = React.useCallback(mode => {
|
|
81
88
|
setState(currentState => {
|
|
82
|
-
const newMode = !mode ? defaultMode : mode;
|
|
83
|
-
|
|
84
89
|
if (mode === currentState.mode) {
|
|
90
|
+
// do nothing if mode does not change
|
|
85
91
|
return currentState;
|
|
86
92
|
}
|
|
87
93
|
|
|
94
|
+
const newMode = !mode ? defaultMode : mode;
|
|
95
|
+
|
|
88
96
|
try {
|
|
89
97
|
localStorage.setItem(modeStorageKey, newMode);
|
|
90
98
|
} catch (e) {// Unsupported
|
|
@@ -97,20 +105,26 @@ export default function useCurrentColorScheme(options) {
|
|
|
97
105
|
});
|
|
98
106
|
}, [modeStorageKey, defaultMode]);
|
|
99
107
|
const setColorScheme = React.useCallback(value => {
|
|
100
|
-
if (!value
|
|
108
|
+
if (!value) {
|
|
109
|
+
setState(currentState => {
|
|
110
|
+
try {
|
|
111
|
+
localStorage.setItem(`${colorSchemeStorageKey}-light`, defaultLightColorScheme);
|
|
112
|
+
localStorage.setItem(`${colorSchemeStorageKey}-dark`, defaultDarkColorScheme);
|
|
113
|
+
} catch (e) {// Unsupported
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return _extends({}, currentState, {
|
|
117
|
+
lightColorScheme: defaultLightColorScheme,
|
|
118
|
+
darkColorScheme: defaultDarkColorScheme
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
} else if (typeof value === 'string') {
|
|
101
122
|
if (value && !joinedColorSchemes.includes(value)) {
|
|
102
123
|
console.error(`\`${value}\` does not exist in \`theme.colorSchemes\`.`);
|
|
103
124
|
} else {
|
|
104
125
|
setState(currentState => {
|
|
105
126
|
const newState = _extends({}, currentState);
|
|
106
127
|
|
|
107
|
-
if (!value) {
|
|
108
|
-
// reset to default color scheme
|
|
109
|
-
newState.lightColorScheme = defaultLightColorScheme;
|
|
110
|
-
newState.darkColorScheme = defaultDarkColorScheme;
|
|
111
|
-
return newState;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
128
|
processState(currentState, mode => {
|
|
115
129
|
try {
|
|
116
130
|
localStorage.setItem(`${colorSchemeStorageKey}-${mode}`, value);
|
|
@@ -128,33 +142,41 @@ export default function useCurrentColorScheme(options) {
|
|
|
128
142
|
return newState;
|
|
129
143
|
});
|
|
130
144
|
}
|
|
131
|
-
} else if (value.light && !joinedColorSchemes.includes(value.light) || value.dark && !joinedColorSchemes.includes(value.dark)) {
|
|
132
|
-
console.error(`\`${value}\` does not exist in \`theme.colorSchemes\`.`);
|
|
133
145
|
} else {
|
|
134
146
|
setState(currentState => {
|
|
135
147
|
const newState = _extends({}, currentState);
|
|
136
148
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
149
|
+
const newLightColorScheme = value.light === null ? defaultLightColorScheme : value.light;
|
|
150
|
+
const newDarkColorScheme = value.dark === null ? defaultDarkColorScheme : value.dark;
|
|
151
|
+
|
|
152
|
+
if (newLightColorScheme) {
|
|
153
|
+
if (!joinedColorSchemes.includes(newLightColorScheme)) {
|
|
154
|
+
console.error(`\`${newLightColorScheme}\` does not exist in \`theme.colorSchemes\`.`);
|
|
155
|
+
} else {
|
|
156
|
+
newState.lightColorScheme = newLightColorScheme;
|
|
140
157
|
|
|
141
|
-
|
|
142
|
-
|
|
158
|
+
try {
|
|
159
|
+
localStorage.setItem(`${colorSchemeStorageKey}-light`, newLightColorScheme);
|
|
160
|
+
} catch (error) {// Unsupported
|
|
161
|
+
}
|
|
162
|
+
}
|
|
143
163
|
}
|
|
144
164
|
|
|
145
|
-
|
|
146
|
-
|
|
165
|
+
if (newDarkColorScheme) {
|
|
166
|
+
if (!joinedColorSchemes.includes(newDarkColorScheme)) {
|
|
167
|
+
console.error(`\`${newDarkColorScheme}\` does not exist in \`theme.colorSchemes\`.`);
|
|
168
|
+
} else {
|
|
169
|
+
newState.darkColorScheme = newDarkColorScheme;
|
|
147
170
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
171
|
+
try {
|
|
172
|
+
localStorage.setItem(`${colorSchemeStorageKey}-dark`, newDarkColorScheme);
|
|
173
|
+
} catch (error) {// Unsupported
|
|
174
|
+
}
|
|
175
|
+
}
|
|
151
176
|
}
|
|
152
177
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
}
|
|
156
|
-
} catch (e) {// Unsupported
|
|
157
|
-
}
|
|
178
|
+
return newState;
|
|
179
|
+
});
|
|
158
180
|
}
|
|
159
181
|
}, [joinedColorSchemes, colorSchemeStorageKey, defaultLightColorScheme, defaultDarkColorScheme]);
|
|
160
182
|
const handleMediaQuery = React.useCallback(e => {
|
|
@@ -176,26 +198,7 @@ export default function useCurrentColorScheme(options) {
|
|
|
176
198
|
media.addListener(handler);
|
|
177
199
|
handler(media);
|
|
178
200
|
return () => media.removeListener(handler);
|
|
179
|
-
}, []); //
|
|
180
|
-
|
|
181
|
-
React.useEffect(() => {
|
|
182
|
-
try {
|
|
183
|
-
if (state.mode) {
|
|
184
|
-
localStorage.setItem(modeStorageKey, state.mode);
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
processState(state, mode => {
|
|
188
|
-
if (mode === 'light') {
|
|
189
|
-
localStorage.setItem(`${colorSchemeStorageKey}-light`, state.lightColorScheme);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
if (mode === 'dark') {
|
|
193
|
-
localStorage.setItem(`${colorSchemeStorageKey}-dark`, state.darkColorScheme);
|
|
194
|
-
}
|
|
195
|
-
});
|
|
196
|
-
} catch (e) {// Unsupported
|
|
197
|
-
}
|
|
198
|
-
}, [state, colorSchemeStorageKey, modeStorageKey]); // Handle when localStorage has changed
|
|
201
|
+
}, []); // Handle when localStorage has changed
|
|
199
202
|
|
|
200
203
|
React.useEffect(() => {
|
|
201
204
|
const handleStorage = event => {
|
package/modern/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mui/system",
|
|
3
|
-
"version": "5.10.
|
|
3
|
+
"version": "5.10.5",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": "MUI Team",
|
|
6
6
|
"description": "CSS utilities for rapidly laying out custom designs.",
|
|
@@ -43,11 +43,11 @@
|
|
|
43
43
|
}
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@babel/runtime": "^7.
|
|
47
|
-
"@mui/private-theming": "^5.
|
|
48
|
-
"@mui/styled-engine": "^5.10.
|
|
49
|
-
"@mui/types": "^7.
|
|
50
|
-
"@mui/utils": "^5.
|
|
46
|
+
"@babel/runtime": "^7.18.9",
|
|
47
|
+
"@mui/private-theming": "^5.10.3",
|
|
48
|
+
"@mui/styled-engine": "^5.10.5",
|
|
49
|
+
"@mui/types": "^7.2.0",
|
|
50
|
+
"@mui/utils": "^5.10.3",
|
|
51
51
|
"clsx": "^1.2.1",
|
|
52
52
|
"csstype": "^3.1.0",
|
|
53
53
|
"prop-types": "^15.8.1"
|
|
@@ -10,8 +10,8 @@ type ThemedProps<Theme, Name extends keyof any> = Theme extends {
|
|
|
10
10
|
? Props
|
|
11
11
|
: {};
|
|
12
12
|
|
|
13
|
-
export default function getThemeProps<
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
export default function getThemeProps<Theme, Props, Name extends keyof any>(params: {
|
|
14
|
+
props: Props;
|
|
15
|
+
name: Name;
|
|
16
|
+
theme?: Theme;
|
|
17
|
+
}): Props & ThemedProps<Theme, Name>;
|