@mui/system 5.0.4 → 5.0.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/CHANGELOG.md +79 -0
- package/createStyled.d.ts +16 -190
- package/cssVars/createCssVarsProvider.d.ts +81 -0
- package/cssVars/createCssVarsProvider.js +206 -0
- package/cssVars/createCssVarsProvider.spec.d.ts +1 -0
- package/cssVars/cssVarsParser.d.ts +57 -0
- package/cssVars/cssVarsParser.js +126 -0
- package/cssVars/getInitColorSchemeScript.d.ts +7 -0
- package/cssVars/getInitColorSchemeScript.js +38 -0
- package/cssVars/index.d.ts +2 -0
- package/cssVars/index.js +15 -0
- package/cssVars/package.json +6 -0
- package/esm/cssVars/createCssVarsProvider.js +188 -0
- package/esm/cssVars/cssVarsParser.js +112 -0
- package/esm/cssVars/getInitColorSchemeScript.js +21 -0
- package/esm/cssVars/index.js +1 -0
- package/esm/index.js +2 -1
- package/esm/styleFunctionSx/styleFunctionSx.js +6 -6
- package/index.d.ts +6 -0
- package/index.js +11 -2
- package/legacy/cssVars/createCssVarsProvider.js +202 -0
- package/legacy/cssVars/cssVarsParser.js +125 -0
- package/legacy/cssVars/getInitColorSchemeScript.js +18 -0
- package/legacy/cssVars/index.js +1 -0
- package/legacy/index.js +3 -2
- package/legacy/styleFunctionSx/styleFunctionSx.js +6 -6
- package/modern/cssVars/createCssVarsProvider.js +188 -0
- package/modern/cssVars/cssVarsParser.js +112 -0
- package/modern/cssVars/getInitColorSchemeScript.js +21 -0
- package/modern/cssVars/index.js +1 -0
- package/modern/index.js +3 -2
- package/modern/styleFunctionSx/styleFunctionSx.js +6 -6
- package/package.json +2 -3
- package/style.d.ts +1 -1
- package/styleFunctionSx/styleFunctionSx.d.ts +6 -1
- package/styleFunctionSx/styleFunctionSx.js +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,84 @@
|
|
|
1
1
|
### [Versions](https://mui.com/versions/)
|
|
2
2
|
|
|
3
|
+
## 5.0.5
|
|
4
|
+
|
|
5
|
+
<!-- generated comparing v5.0.4..master -->
|
|
6
|
+
|
|
7
|
+
_Oct 26, 2021_
|
|
8
|
+
|
|
9
|
+
A big thanks to the 19 contributors who made this release possible. Here are some highlights ✨:
|
|
10
|
+
|
|
11
|
+
- 🔧 Implement `Masonry` using Flexbox by @hbjORbj.
|
|
12
|
+
- 🧪 Add three components to `@mui/core` by @rebeccahongsf and @hbjORbj.
|
|
13
|
+
|
|
14
|
+
### `@mui/codemod@5.0.5`
|
|
15
|
+
|
|
16
|
+
- ​<!-- 38 -->[codemod] Support new package name in `link-underline-hover` transformer (#29214) @siriwatknp
|
|
17
|
+
|
|
18
|
+
### `@mui/core@5.0.0-alpha.52`
|
|
19
|
+
|
|
20
|
+
- ​<!-- 39 -->[ClickAwayListener] Move to the core package (#29186) @hbjORbj
|
|
21
|
+
- ​<!-- 13 -->[Popper] Move from mui-material to mui-core (#28923) @rebeccahongsf
|
|
22
|
+
- ​<!-- 04 -->[TextareaAutosize] Move to the core package (#29148) @hbjORbj
|
|
23
|
+
|
|
24
|
+
### `@mui/lab@5.0.0-alpha.52`
|
|
25
|
+
|
|
26
|
+
- ​<!-- 16 -->[Masonry] Improve demo styles (#29218) @hbjORbj
|
|
27
|
+
- ​<!-- 15 -->[Masonry] Implement Masonry using Flexbox (#28059) @hbjORbj
|
|
28
|
+
|
|
29
|
+
### `@mui/icons@5.0.5`
|
|
30
|
+
|
|
31
|
+
- ​<!-- 19 -->[icons] Add TipsAndUpdates icon (#29004) @hbjORbj
|
|
32
|
+
|
|
33
|
+
### `@mui/material@5.0.5`
|
|
34
|
+
|
|
35
|
+
- ​<!-- 40 -->[CardMedia] Apply specified `img` role instead of custom `image` role (#29172) @eps1lon
|
|
36
|
+
- ​<!-- 32 -->[CSSBaseline] Remove incorrect @deprecated annotation (#29069) @adamfitzgibbon
|
|
37
|
+
- ​<!-- 20 -->[Grid] Support custom columns with nested grid (#28743) @Devesh21700Kumar
|
|
38
|
+
- ​<!-- 18 -->[InputBase] Remove wrong theme overriding with MUI's default theme (#29157) @hbjORbj
|
|
39
|
+
- ​<!-- 17 -->[LoadingButton] Fix `fullWidth` styling (#28652) @nikitabobers
|
|
40
|
+
- ​<!-- 16 -->[Popper] make Popper display:none whenever it's closed (#29233) @adamfitzgibbon
|
|
41
|
+
- ​<!-- 14 -->[Menu] Reduce min-height & padding in menu-item with dense property (#29180) @jatinsandilya
|
|
42
|
+
- ​<!-- 07 -->[Tab] `iconPosition` prop added in Tab (#28764) @deepanshu2506
|
|
43
|
+
- ​<!-- 03 -->[Tooltip] Correct inconsistent prop precedence (#29132) @michaldudak
|
|
44
|
+
|
|
45
|
+
### `@mui/system@5.0.5`
|
|
46
|
+
|
|
47
|
+
- ​<!-- 11 -->[system] Allow function type for `sx` prop (#29198) @hbjORbj
|
|
48
|
+
- ​<!-- 10 -->[system] Fix various issues reported by using @mui/styled-engine-sc (#29035) @mnajdova
|
|
49
|
+
- ​<!-- 09 -->[system] Fix `colorScheme` conflict between application (#29139) @siriwatknp
|
|
50
|
+
- ​<!-- 08 -->[system] Add `unstable_createCssVarsProvider` api (#28965) @siriwatknp
|
|
51
|
+
|
|
52
|
+
### Documentation
|
|
53
|
+
|
|
54
|
+
- ​<!-- 31 -->[docs] Fix path to `DataGrid` CSV export options page (#29220) @DanailH
|
|
55
|
+
- ​<!-- 30 -->[docs] Give anonymous components a name (#29189) @eps1lon
|
|
56
|
+
- ​<!-- 29 -->[docs] Add deploy context variables (#29195) @siriwatknp
|
|
57
|
+
- ​<!-- 28 -->[docs] Add MUI packages explanation (#29073) @siriwatknp
|
|
58
|
+
- ​<!-- 27 -->[docs] Fix typo in CSP policy (#29187) @JuliaNeumann
|
|
59
|
+
- ​<!-- 26 -->[docs] Dark mode conditional content rendering (#28665) @michal-perlakowski
|
|
60
|
+
- ​<!-- 25 -->[docs] Fix ClassNameGenerator introduced version #29177 @siriwatknp
|
|
61
|
+
- ​<!-- 24 -->[docs] Add missing `justifyContent` values and update box styling (#29117) @omarmosid
|
|
62
|
+
- ​<!-- 23 -->[docs] Make landing page hero section scrollable (#29141) @waxidiotic
|
|
63
|
+
- ​<!-- 22 -->[docs] Discourage importing different bundles directly (#29133) @eps1lon
|
|
64
|
+
- ​<!-- 21 -->[docs] Update module augmentation reference url (#29064) @gnowland
|
|
65
|
+
- ​<!-- 12 -->[pricing] Add tooltip to pricing icon (#28959) @siriwatknp
|
|
66
|
+
- ​<!-- 07 -->[Team] Add Alexandre in the about page (#29289)
|
|
67
|
+
- ​<!-- 02 -->[website] Fix status label overflow in AdvancedShowcase (#29143) @LorenzHenk
|
|
68
|
+
- ​<!-- 01 -->[website] Update legacy logos (#28908) @michaldudak
|
|
69
|
+
|
|
70
|
+
### Core
|
|
71
|
+
|
|
72
|
+
- ​<!-- 37 -->[core] Order repro methods by preference (#29156) @eps1lon
|
|
73
|
+
- ​<!-- 36 -->[core] Remove unnecessary usages of `useEventCallback` (#28910) @NMinhNguyen
|
|
74
|
+
- ​<!-- 35 -->[core] add `unstable_ClassNameGenerator` API (#29051) @siriwatknp
|
|
75
|
+
- ​<!-- 34 -->[core] Fix issues when using styled-components (#29048) @mnajdova
|
|
76
|
+
- ​<!-- 33 -->[core] replace hard-coded classname with classes (#29070) @siriwatknp
|
|
77
|
+
- ​<!-- 06 -->[test] Add documentation for visual regression tests (#29154) @eps1lon
|
|
78
|
+
- ​<!-- 05 -->[test] Enable "missing act" warnings using new proposal (#29167) @eps1lon
|
|
79
|
+
|
|
80
|
+
All contributors of this release in alphabetical order: @adamfitzgibbon, @DanailH, @deepanshu2506, @Devesh21700Kumar, @eps1lon, @gnowland, @hbjORbj, @jatinsandilya, @JuliaNeumann, @LorenzHenk, @michal-perlakowski, @michaldudak, @mnajdova, @nikitabobers, @NMinhNguyen, @omarmosid, @rebeccahongsf, @siriwatknp, @waxidiotic
|
|
81
|
+
|
|
3
82
|
## 5.0.4
|
|
4
83
|
|
|
5
84
|
<!-- generated comparing v5.0.3..master -->
|
package/createStyled.d.ts
CHANGED
|
@@ -1,208 +1,34 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import
|
|
2
|
+
import {
|
|
3
|
+
CreateMUIStyled as CreateMUIStyledStyledEngine,
|
|
4
|
+
CSSInterpolation,
|
|
5
|
+
} from '@mui/styled-engine';
|
|
3
6
|
import { SxProps } from './styleFunctionSx';
|
|
4
7
|
import { Theme as DefaultTheme } from './createTheme';
|
|
5
8
|
|
|
6
|
-
export
|
|
7
|
-
name: string;
|
|
8
|
-
styles: string;
|
|
9
|
-
map?: string;
|
|
10
|
-
next?: SerializedStyles;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export type CSSProperties = CSS.PropertiesFallback<number | string>;
|
|
14
|
-
export type CSSPropertiesWithMultiValues = {
|
|
15
|
-
[K in keyof CSSProperties]: CSSProperties[K] | Array<Extract<CSSProperties[K], string>>;
|
|
16
|
-
};
|
|
17
|
-
export type CSSPseudos = { [K in CSS.Pseudos]?: unknown | CSSObject };
|
|
18
|
-
|
|
19
|
-
export interface CSSOthersObject {
|
|
20
|
-
[propertiesName: string]: unknown | CSSInterpolation;
|
|
21
|
-
}
|
|
22
|
-
export type CSSPseudosForCSSObject = { [K in CSS.Pseudos]?: CSSObject };
|
|
23
|
-
|
|
24
|
-
export interface ArrayCSSInterpolation extends Array<CSSInterpolation> {}
|
|
25
|
-
|
|
26
|
-
export interface CSSOthersObjectForCSSObject {
|
|
27
|
-
[propertiesName: string]: CSSInterpolation;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export interface CSSObject extends CSSPropertiesWithMultiValues, CSSPseudos, CSSOthersObject {}
|
|
31
|
-
|
|
32
|
-
export interface ComponentSelector {
|
|
33
|
-
__emotion_styles: any;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export type Keyframes = {
|
|
37
|
-
name: string;
|
|
38
|
-
styles: string;
|
|
39
|
-
anim: number;
|
|
40
|
-
toString: () => string;
|
|
41
|
-
} & string;
|
|
42
|
-
|
|
43
|
-
export type Equal<A, B, T, F> = A extends B ? (B extends A ? T : F) : F;
|
|
44
|
-
|
|
45
|
-
export type InterpolationPrimitive =
|
|
46
|
-
| null
|
|
47
|
-
| undefined
|
|
48
|
-
| boolean
|
|
49
|
-
| number
|
|
50
|
-
| string
|
|
51
|
-
| ComponentSelector
|
|
52
|
-
| Keyframes
|
|
53
|
-
| SerializedStyles
|
|
54
|
-
| CSSObject;
|
|
55
|
-
|
|
56
|
-
export type CSSInterpolation = InterpolationPrimitive | ArrayCSSInterpolation;
|
|
57
|
-
|
|
58
|
-
export interface FunctionInterpolation<Props> {
|
|
59
|
-
(props: Props): Interpolation<Props>;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export interface ArrayInterpolation<Props> extends Array<Interpolation<Props>> {}
|
|
63
|
-
|
|
64
|
-
export type Interpolation<Props> =
|
|
65
|
-
| InterpolationPrimitive
|
|
66
|
-
| ArrayInterpolation<Props>
|
|
67
|
-
| FunctionInterpolation<Props>;
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* @desc Utility type for getting props type of React component.
|
|
71
|
-
* It takes `defaultProps` into an account - making props with defaults optional.
|
|
72
|
-
*/
|
|
73
|
-
export type PropsOf<C extends keyof JSX.IntrinsicElements | React.JSXElementConstructor<any>> =
|
|
74
|
-
JSX.LibraryManagedAttributes<C, React.ComponentProps<C>>;
|
|
75
|
-
|
|
76
|
-
export type Overwrapped<T, U> = Pick<T, Extract<keyof T, keyof U>>;
|
|
77
|
-
|
|
78
|
-
export interface StyledComponent<InnerProps, OwnerState, Theme extends object>
|
|
79
|
-
extends React.FunctionComponent<InnerProps & OwnerState & { theme?: Theme }>,
|
|
80
|
-
ComponentSelector {}
|
|
9
|
+
export function shouldForwardProp(propName: PropertyKey): boolean;
|
|
81
10
|
|
|
82
|
-
export interface
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
11
|
+
export interface MUIStyledCommonProps<Theme extends object = DefaultTheme> {
|
|
12
|
+
theme?: Theme;
|
|
13
|
+
as?: React.ElementType;
|
|
14
|
+
sx?: SxProps<Theme>;
|
|
86
15
|
}
|
|
87
16
|
|
|
88
17
|
export interface MuiStyledOptions {
|
|
89
18
|
name?: string;
|
|
90
19
|
slot?: string;
|
|
20
|
+
// The difference between Interpolation and CSSInterpolation is that the former supports functions based on props
|
|
21
|
+
// If we want to support props in the overrides, we will need to change the CSSInterpolation to Interpolation<Props>
|
|
91
22
|
overridesResolver?: (props: any, styles: Record<string, CSSInterpolation>) => CSSInterpolation;
|
|
92
23
|
skipVariantsResolver?: boolean;
|
|
93
24
|
skipSx?: boolean;
|
|
94
25
|
}
|
|
95
26
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* @typeparam ComponentProps Props which will be included when withComponent is called
|
|
105
|
-
* @typeparam SpecificComponentProps Props which will *not* be included when withComponent is called
|
|
106
|
-
*/
|
|
107
|
-
export interface CreateStyledComponent<
|
|
108
|
-
ComponentProps extends {},
|
|
109
|
-
SpecificComponentProps extends {} = {},
|
|
110
|
-
JSXProps extends {} = {},
|
|
111
|
-
> {
|
|
112
|
-
/**
|
|
113
|
-
* @typeparam AdditionalProps Additional props to add to your styled component
|
|
114
|
-
*/
|
|
115
|
-
<AdditionalProps extends {} = {}>(
|
|
116
|
-
...styles: Array<
|
|
117
|
-
Interpolation<
|
|
118
|
-
ComponentProps & SpecificComponentProps & AdditionalProps & { theme: DefaultTheme }
|
|
119
|
-
>
|
|
120
|
-
>
|
|
121
|
-
): StyledComponent<ComponentProps & AdditionalProps, SpecificComponentProps, JSXProps>;
|
|
122
|
-
|
|
123
|
-
(
|
|
124
|
-
template: TemplateStringsArray,
|
|
125
|
-
...styles: Array<
|
|
126
|
-
Interpolation<ComponentProps & SpecificComponentProps & { theme: DefaultTheme }>
|
|
127
|
-
>
|
|
128
|
-
): StyledComponent<ComponentProps, SpecificComponentProps, JSXProps>;
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* @typeparam AdditionalProps Additional props to add to your styled component
|
|
132
|
-
*/
|
|
133
|
-
<AdditionalProps extends {}>(
|
|
134
|
-
template: TemplateStringsArray,
|
|
135
|
-
...styles: Array<
|
|
136
|
-
Interpolation<
|
|
137
|
-
ComponentProps & SpecificComponentProps & AdditionalProps & { theme: DefaultTheme }
|
|
138
|
-
>
|
|
139
|
-
>
|
|
140
|
-
): StyledComponent<ComponentProps & AdditionalProps, SpecificComponentProps, JSXProps>;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
export interface MUIStyledCommonProps<Theme extends object = DefaultTheme> {
|
|
144
|
-
theme?: Theme;
|
|
145
|
-
as?: React.ElementType;
|
|
146
|
-
sx?: SxProps<Theme>;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
export interface CreateMUIStyled<Theme extends object = DefaultTheme> {
|
|
150
|
-
<
|
|
151
|
-
C extends React.ComponentClass<React.ComponentProps<C>>,
|
|
152
|
-
ForwardedProps extends keyof React.ComponentProps<C> = keyof React.ComponentProps<C>,
|
|
153
|
-
>(
|
|
154
|
-
component: C,
|
|
155
|
-
options: FilteringStyledOptions<React.ComponentProps<C>, ForwardedProps> & MuiStyledOptions,
|
|
156
|
-
): CreateStyledComponent<
|
|
157
|
-
Pick<PropsOf<C>, ForwardedProps> & MUIStyledCommonProps<Theme>,
|
|
158
|
-
{},
|
|
159
|
-
{
|
|
160
|
-
ref?: React.Ref<InstanceType<C>>;
|
|
161
|
-
}
|
|
162
|
-
>;
|
|
163
|
-
|
|
164
|
-
<C extends React.ComponentClass<React.ComponentProps<C>>>(
|
|
165
|
-
component: C,
|
|
166
|
-
options?: StyledOptions & MuiStyledOptions,
|
|
167
|
-
): CreateStyledComponent<
|
|
168
|
-
PropsOf<C> & MUIStyledCommonProps<Theme>,
|
|
169
|
-
{},
|
|
170
|
-
{
|
|
171
|
-
ref?: React.Ref<InstanceType<C>>;
|
|
172
|
-
}
|
|
173
|
-
>;
|
|
174
|
-
|
|
175
|
-
<
|
|
176
|
-
C extends React.JSXElementConstructor<React.ComponentProps<C>>,
|
|
177
|
-
ForwardedProps extends keyof React.ComponentProps<C> = keyof React.ComponentProps<C>,
|
|
178
|
-
>(
|
|
179
|
-
component: C,
|
|
180
|
-
options: FilteringStyledOptions<React.ComponentProps<C>, ForwardedProps> & MuiStyledOptions,
|
|
181
|
-
): CreateStyledComponent<Pick<PropsOf<C>, ForwardedProps> & MUIStyledCommonProps<Theme>>;
|
|
182
|
-
|
|
183
|
-
<C extends React.JSXElementConstructor<React.ComponentProps<C>>>(
|
|
184
|
-
component: C,
|
|
185
|
-
options?: StyledOptions & MuiStyledOptions,
|
|
186
|
-
): CreateStyledComponent<PropsOf<C> & MUIStyledCommonProps<Theme>>;
|
|
187
|
-
|
|
188
|
-
<
|
|
189
|
-
Tag extends keyof JSX.IntrinsicElements,
|
|
190
|
-
ForwardedProps extends keyof JSX.IntrinsicElements[Tag] = keyof JSX.IntrinsicElements[Tag],
|
|
191
|
-
>(
|
|
192
|
-
tag: Tag,
|
|
193
|
-
options: FilteringStyledOptions<JSX.IntrinsicElements[Tag], ForwardedProps> & MuiStyledOptions,
|
|
194
|
-
): CreateStyledComponent<
|
|
195
|
-
MUIStyledCommonProps<Theme>,
|
|
196
|
-
Pick<JSX.IntrinsicElements[Tag], ForwardedProps>
|
|
197
|
-
>;
|
|
198
|
-
|
|
199
|
-
<Tag extends keyof JSX.IntrinsicElements>(
|
|
200
|
-
tag: Tag,
|
|
201
|
-
options?: StyledOptions & MuiStyledOptions,
|
|
202
|
-
): CreateStyledComponent<MUIStyledCommonProps<Theme>, JSX.IntrinsicElements[Tag]>;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
export function shouldForwardProp(propName: PropertyKey): boolean;
|
|
27
|
+
export type CreateMUIStyled<T extends object = DefaultTheme> = CreateMUIStyledStyledEngine<
|
|
28
|
+
MUIStyledCommonProps<T>,
|
|
29
|
+
MuiStyledOptions,
|
|
30
|
+
T
|
|
31
|
+
>;
|
|
206
32
|
|
|
207
33
|
export default function createStyled<T extends object = DefaultTheme>(options?: {
|
|
208
34
|
defaultTheme?: T;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
type PartialDeep<T> = {
|
|
4
|
+
[K in keyof T]?: PartialDeep<T[K]>;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export type BuildCssVarsTheme<ThemeInput> = ThemeInput extends {
|
|
8
|
+
colorSchemes: Record<string, infer Colors>;
|
|
9
|
+
}
|
|
10
|
+
? Omit<ThemeInput, 'colorSchemes'> & { vars: Omit<ThemeInput, 'colorSchemes'> & Colors }
|
|
11
|
+
: never;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* DesignSystemColorScheme: is what a design system provide by default. Mostly, `light` and `dark`
|
|
15
|
+
* ApplicationColorScheme: is what developer can extend from a design system. Ex, `comfort` `trueDark` ...any name that they want
|
|
16
|
+
*
|
|
17
|
+
* This type enhance customization experience by checking if developer has extended the colorScheme or not (usually via module augmentation)
|
|
18
|
+
* If yes, they must provide the palette of the extended colorScheme. Otherwise `theme` is optional.
|
|
19
|
+
*/
|
|
20
|
+
type DecideTheme<
|
|
21
|
+
Theme extends { colorSchemes: Record<DesignSystemColorScheme | ApplicationColorScheme, any> },
|
|
22
|
+
DesignSystemColorScheme extends string,
|
|
23
|
+
ApplicationColorScheme extends string | never,
|
|
24
|
+
> = [ApplicationColorScheme] extends [never]
|
|
25
|
+
? { theme?: PartialDeep<Theme> }
|
|
26
|
+
: {
|
|
27
|
+
theme: PartialDeep<Omit<Theme, 'colorSchemes'>> & {
|
|
28
|
+
colorSchemes: PartialDeep<
|
|
29
|
+
Record<DesignSystemColorScheme, Theme['colorSchemes'][DesignSystemColorScheme]>
|
|
30
|
+
> &
|
|
31
|
+
Record<ApplicationColorScheme, Theme['colorSchemes'][ApplicationColorScheme]>;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export interface ColorSchemeContextValue<DesignSystemColorScheme extends string> {
|
|
36
|
+
allColorSchemes: DesignSystemColorScheme[];
|
|
37
|
+
colorScheme: DesignSystemColorScheme | undefined;
|
|
38
|
+
setColorScheme: React.Dispatch<React.SetStateAction<DesignSystemColorScheme | undefined>>;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export default function createCssVarsProvider<
|
|
42
|
+
ThemeInput extends {
|
|
43
|
+
colorSchemes: Record<DesignSystemColorScheme | ApplicationColorScheme, any>;
|
|
44
|
+
},
|
|
45
|
+
DesignSystemColorScheme extends string,
|
|
46
|
+
ApplicationColorScheme extends string = never,
|
|
47
|
+
>(
|
|
48
|
+
ThemeContext: React.Context<BuildCssVarsTheme<ThemeInput> | undefined>,
|
|
49
|
+
options: {
|
|
50
|
+
theme: Omit<ThemeInput, 'colorSchemes'> & {
|
|
51
|
+
colorSchemes: Record<
|
|
52
|
+
DesignSystemColorScheme,
|
|
53
|
+
ThemeInput['colorSchemes'][DesignSystemColorScheme]
|
|
54
|
+
> &
|
|
55
|
+
Partial<
|
|
56
|
+
Record<
|
|
57
|
+
ApplicationColorScheme,
|
|
58
|
+
ThemeInput['colorSchemes'][DesignSystemColorScheme | ApplicationColorScheme]
|
|
59
|
+
>
|
|
60
|
+
>;
|
|
61
|
+
};
|
|
62
|
+
defaultColorScheme: DesignSystemColorScheme;
|
|
63
|
+
prefix?: string;
|
|
64
|
+
},
|
|
65
|
+
): {
|
|
66
|
+
CssVarsProvider: (
|
|
67
|
+
props: React.PropsWithChildren<
|
|
68
|
+
{
|
|
69
|
+
defaultColorScheme?: DesignSystemColorScheme | ApplicationColorScheme;
|
|
70
|
+
storageKey?: string;
|
|
71
|
+
attribute?: string;
|
|
72
|
+
prefix?: string;
|
|
73
|
+
} & DecideTheme<ThemeInput, DesignSystemColorScheme, ApplicationColorScheme>
|
|
74
|
+
>,
|
|
75
|
+
) => React.ReactElement;
|
|
76
|
+
useColorScheme: () => ColorSchemeContextValue<DesignSystemColorScheme | ApplicationColorScheme>;
|
|
77
|
+
getInitColorSchemeScript: () => React.ReactElement;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
// disable automatic export
|
|
81
|
+
export {};
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = createCssVarsProvider;
|
|
9
|
+
|
|
10
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
11
|
+
|
|
12
|
+
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
|
|
13
|
+
|
|
14
|
+
var _utils = require("@mui/utils");
|
|
15
|
+
|
|
16
|
+
var React = _interopRequireWildcard(require("react"));
|
|
17
|
+
|
|
18
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
19
|
+
|
|
20
|
+
var _styledEngine = require("@mui/styled-engine");
|
|
21
|
+
|
|
22
|
+
var _cssVarsParser = _interopRequireDefault(require("./cssVarsParser"));
|
|
23
|
+
|
|
24
|
+
var _getInitColorSchemeScript = _interopRequireWildcard(require("./getInitColorSchemeScript"));
|
|
25
|
+
|
|
26
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
27
|
+
|
|
28
|
+
const _excluded = ["colorSchemes"],
|
|
29
|
+
_excluded2 = ["colorSchemes"];
|
|
30
|
+
|
|
31
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
32
|
+
|
|
33
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
34
|
+
|
|
35
|
+
const resolveMode = (key, fallback, supportedColorSchemes) => {
|
|
36
|
+
if (typeof window === 'undefined') {
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
let value;
|
|
41
|
+
|
|
42
|
+
try {
|
|
43
|
+
value = localStorage.getItem(key) || undefined;
|
|
44
|
+
|
|
45
|
+
if (!supportedColorSchemes.includes(value)) {
|
|
46
|
+
value = undefined;
|
|
47
|
+
}
|
|
48
|
+
} catch (e) {// Unsupported
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return value || fallback;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
function createCssVarsProvider(ThemeContext, options) {
|
|
55
|
+
const {
|
|
56
|
+
theme: baseTheme = {},
|
|
57
|
+
defaultColorScheme: designSystemColorScheme,
|
|
58
|
+
prefix: designSystemPrefix = ''
|
|
59
|
+
} = options;
|
|
60
|
+
|
|
61
|
+
if (!baseTheme.colorSchemes || !baseTheme.colorSchemes[designSystemColorScheme]) {
|
|
62
|
+
console.error(`MUI: \`${designSystemColorScheme}\` does not exist in \`theme.colorSchemes\`.`);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const ColorSchemeContext = /*#__PURE__*/React.createContext(undefined);
|
|
66
|
+
|
|
67
|
+
const useColorScheme = () => {
|
|
68
|
+
const value = React.useContext(ColorSchemeContext);
|
|
69
|
+
|
|
70
|
+
if (!value) {
|
|
71
|
+
throw new Error(process.env.NODE_ENV !== "production" ? `MUI: \`useColorScheme\` must be called under <CssVarsProvider />` : (0, _utils.formatMuiErrorMessage)(19));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return value;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
function CssVarsProvider({
|
|
78
|
+
children,
|
|
79
|
+
theme: themeProp = {},
|
|
80
|
+
prefix = designSystemPrefix,
|
|
81
|
+
storageKey = _getInitColorSchemeScript.DEFAULT_STORAGE_KEY,
|
|
82
|
+
attribute = _getInitColorSchemeScript.DEFAULT_ATTRIBUTE,
|
|
83
|
+
defaultColorScheme = designSystemColorScheme
|
|
84
|
+
}) {
|
|
85
|
+
const {
|
|
86
|
+
colorSchemes: baseColorSchemes = {}
|
|
87
|
+
} = baseTheme,
|
|
88
|
+
restBaseTheme = (0, _objectWithoutPropertiesLoose2.default)(baseTheme, _excluded);
|
|
89
|
+
const {
|
|
90
|
+
colorSchemes: colorSchemesProp = {}
|
|
91
|
+
} = themeProp,
|
|
92
|
+
restThemeProp = (0, _objectWithoutPropertiesLoose2.default)(themeProp, _excluded2);
|
|
93
|
+
let mergedTheme = (0, _utils.deepmerge)(restBaseTheme, restThemeProp);
|
|
94
|
+
const colorSchemes = (0, _utils.deepmerge)(baseColorSchemes, colorSchemesProp);
|
|
95
|
+
const allColorSchemes = Object.keys(colorSchemes);
|
|
96
|
+
const joinedColorSchemes = allColorSchemes.join(',');
|
|
97
|
+
const [colorScheme, setColorScheme] = React.useState(() => resolveMode(storageKey, defaultColorScheme, allColorSchemes));
|
|
98
|
+
const resolvedColorScheme = colorScheme || defaultColorScheme;
|
|
99
|
+
const {
|
|
100
|
+
css: rootCss,
|
|
101
|
+
vars: rootVars
|
|
102
|
+
} = (0, _cssVarsParser.default)(mergedTheme, {
|
|
103
|
+
prefix
|
|
104
|
+
});
|
|
105
|
+
mergedTheme = (0, _extends2.default)({}, mergedTheme, colorSchemes[resolvedColorScheme], {
|
|
106
|
+
vars: rootVars
|
|
107
|
+
});
|
|
108
|
+
const styleSheet = {};
|
|
109
|
+
Object.entries(colorSchemes).forEach(([key, scheme]) => {
|
|
110
|
+
const {
|
|
111
|
+
css,
|
|
112
|
+
vars
|
|
113
|
+
} = (0, _cssVarsParser.default)(scheme, {
|
|
114
|
+
prefix
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
if (key === resolvedColorScheme) {
|
|
118
|
+
mergedTheme.vars = (0, _extends2.default)({}, mergedTheme.vars, vars);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (key === defaultColorScheme) {
|
|
122
|
+
styleSheet[':root'] = (0, _utils.deepmerge)(rootCss, css);
|
|
123
|
+
} else {
|
|
124
|
+
styleSheet[`[${attribute}="${key}"]`] = css;
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
React.useEffect(() => {
|
|
128
|
+
if (colorScheme) {
|
|
129
|
+
document.body.setAttribute(attribute, colorScheme);
|
|
130
|
+
localStorage.setItem(storageKey, colorScheme);
|
|
131
|
+
}
|
|
132
|
+
}, [colorScheme, attribute, storageKey]); // local storage modified in the context of another document
|
|
133
|
+
|
|
134
|
+
React.useEffect(() => {
|
|
135
|
+
const handleStorage = event => {
|
|
136
|
+
const storageColorScheme = event.newValue;
|
|
137
|
+
|
|
138
|
+
if (event.key === storageKey && joinedColorSchemes.match(storageColorScheme)) {
|
|
139
|
+
if (storageColorScheme) {
|
|
140
|
+
setColorScheme(storageColorScheme);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
window.addEventListener('storage', handleStorage);
|
|
146
|
+
return () => window.removeEventListener('storage', handleStorage);
|
|
147
|
+
}, [setColorScheme, storageKey, joinedColorSchemes]);
|
|
148
|
+
const wrappedSetColorScheme = React.useCallback(val => {
|
|
149
|
+
if (typeof val === 'string' && !allColorSchemes.includes(val)) {
|
|
150
|
+
console.error(`\`${val}\` does not exist in \`theme.colorSchemes\`.`);
|
|
151
|
+
} else {
|
|
152
|
+
setColorScheme(val);
|
|
153
|
+
}
|
|
154
|
+
}, [setColorScheme, allColorSchemes]);
|
|
155
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(ColorSchemeContext.Provider, {
|
|
156
|
+
value: {
|
|
157
|
+
colorScheme,
|
|
158
|
+
setColorScheme: wrappedSetColorScheme,
|
|
159
|
+
allColorSchemes
|
|
160
|
+
},
|
|
161
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_styledEngine.GlobalStyles, {
|
|
162
|
+
styles: styleSheet
|
|
163
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(ThemeContext.Provider, {
|
|
164
|
+
value: mergedTheme,
|
|
165
|
+
children: children
|
|
166
|
+
})]
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
process.env.NODE_ENV !== "production" ? CssVarsProvider.propTypes = {
|
|
171
|
+
/**
|
|
172
|
+
* The body attribute name to attach colorScheme.
|
|
173
|
+
*/
|
|
174
|
+
attribute: _propTypes.default.string,
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Your component tree.
|
|
178
|
+
*/
|
|
179
|
+
children: _propTypes.default.node,
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* The initial color scheme used.
|
|
183
|
+
*/
|
|
184
|
+
defaultColorScheme: _propTypes.default.string,
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* css variable prefix
|
|
188
|
+
*/
|
|
189
|
+
prefix: _propTypes.default.string,
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* The key in the local storage used to store current color scheme.
|
|
193
|
+
*/
|
|
194
|
+
storageKey: _propTypes.default.string,
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* The calculated theme object that will be passed through context.
|
|
198
|
+
*/
|
|
199
|
+
theme: _propTypes.default.object
|
|
200
|
+
} : void 0;
|
|
201
|
+
return {
|
|
202
|
+
CssVarsProvider,
|
|
203
|
+
useColorScheme,
|
|
204
|
+
getInitColorSchemeScript: _getInitColorSchemeScript.default
|
|
205
|
+
};
|
|
206
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
declare type NestedRecord<V = any> = {
|
|
2
|
+
[k: string | number]: NestedRecord<V> | V;
|
|
3
|
+
};
|
|
4
|
+
/**
|
|
5
|
+
* This function create an object from keys, value and then assign to target
|
|
6
|
+
*
|
|
7
|
+
* @param {Object} obj : the target object to be assigned
|
|
8
|
+
* @param {string[]} keys
|
|
9
|
+
* @param {string | number} value
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* const source = {}
|
|
13
|
+
* assignNestedKeys(source, ['palette', 'primary'], 'var(--palette-primary)')
|
|
14
|
+
* console.log(source) // { palette: { primary: 'var(--palette-primary)' } }
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* const source = { palette: { primary: 'var(--palette-primary)' } }
|
|
18
|
+
* assignNestedKeys(source, ['palette', 'secondary'], 'var(--palette-secondary)')
|
|
19
|
+
* console.log(source) // { palette: { primary: 'var(--palette-primary)', secondary: 'var(--palette-secondary)' } }
|
|
20
|
+
*/
|
|
21
|
+
export declare const assignNestedKeys: <Object_1 = NestedRecord<any>, Value = any>(obj: Object_1, keys: Array<string>, value: Value) => void;
|
|
22
|
+
/**
|
|
23
|
+
*
|
|
24
|
+
* @param {Object} obj : source object
|
|
25
|
+
* @param {Function} callback : a function that will be called when
|
|
26
|
+
* - the deepest key in source object is reached
|
|
27
|
+
* - the value of the deepest key is NOT `undefined` | `null`
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* walkObjectDeep({ palette: { primary: { main: '#000000' } } }, console.log)
|
|
31
|
+
* // ['palette', 'primary', 'main'] '#000000'
|
|
32
|
+
*/
|
|
33
|
+
export declare const walkObjectDeep: <Value, T = Record<string, any>>(obj: T, callback: (keys: Array<string>, value: Value) => void) => void;
|
|
34
|
+
/**
|
|
35
|
+
* a function that parse theme and return { css, vars }
|
|
36
|
+
*
|
|
37
|
+
* @param {Object} theme
|
|
38
|
+
* @param {{ prefix?: string }} options
|
|
39
|
+
* @returns {{ css: Object, vars: Object }} `css` is the stylesheet, `vars` is an object to get css variable (same structure as theme)
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* const { css, vars } = parser({
|
|
43
|
+
* fontSize: 12,
|
|
44
|
+
* lineHeight: 1.2,
|
|
45
|
+
* palette: { primary: { 500: '#000000' } }
|
|
46
|
+
* })
|
|
47
|
+
*
|
|
48
|
+
* console.log(css) // { '--fontSize': '12px', '--lineHeight': 1.2, '--palette-primary-500': '#000000' }
|
|
49
|
+
* console.log(vars) // { fontSize: '--fontSize', lineHeight: '--lineHeight', palette: { primary: { 500: 'var(--palette-primary-500)' } } }
|
|
50
|
+
*/
|
|
51
|
+
export default function cssVarsParser(obj: Record<string, any>, options?: {
|
|
52
|
+
prefix?: string;
|
|
53
|
+
}): {
|
|
54
|
+
css: NestedRecord<string>;
|
|
55
|
+
vars: NestedRecord<string>;
|
|
56
|
+
};
|
|
57
|
+
export {};
|