@mui/system 5.0.4 → 5.1.1
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 +287 -6
- package/breakpoints.js +41 -8
- package/createBox.d.ts +5 -1
- package/createBox.js +5 -3
- package/createStyled.d.ts +16 -190
- package/createStyled.js +5 -1
- package/createTheme/createBreakpoints.js +2 -2
- package/cssVars/createCssVarsProvider.d.ts +131 -0
- package/cssVars/createCssVarsProvider.js +228 -0
- package/cssVars/createCssVarsProvider.spec.d.ts +1 -0
- package/cssVars/cssVarsParser.d.ts +68 -0
- package/cssVars/cssVarsParser.js +156 -0
- package/cssVars/getInitColorSchemeScript.d.ts +12 -0
- package/cssVars/getInitColorSchemeScript.js +60 -0
- package/cssVars/index.d.ts +2 -0
- package/cssVars/index.js +15 -0
- package/cssVars/package.json +6 -0
- package/cssVars/useCurrentColorScheme.d.ts +50 -0
- package/cssVars/useCurrentColorScheme.js +235 -0
- package/esm/breakpoints.js +39 -8
- package/esm/createBox.js +5 -3
- package/esm/createStyled.js +5 -1
- package/esm/createTheme/createBreakpoints.js +2 -2
- package/esm/cssVars/createCssVarsProvider.js +207 -0
- package/esm/cssVars/cssVarsParser.js +141 -0
- package/esm/cssVars/getInitColorSchemeScript.js +42 -0
- package/esm/cssVars/index.js +1 -0
- package/esm/cssVars/useCurrentColorScheme.js +217 -0
- package/esm/index.js +2 -1
- package/esm/styleFunctionSx/extendSxProp.js +20 -1
- package/esm/styleFunctionSx/styleFunctionSx.js +45 -35
- package/index.d.ts +6 -0
- package/index.js +11 -2
- package/legacy/breakpoints.js +39 -8
- package/legacy/createBox.js +6 -3
- package/legacy/createStyled.js +5 -1
- package/legacy/createTheme/createBreakpoints.js +2 -2
- package/legacy/cssVars/createCssVarsProvider.js +215 -0
- package/legacy/cssVars/cssVarsParser.js +153 -0
- package/legacy/cssVars/getInitColorSchemeScript.js +27 -0
- package/legacy/cssVars/index.js +1 -0
- package/legacy/cssVars/useCurrentColorScheme.js +231 -0
- package/legacy/index.js +3 -2
- package/legacy/styleFunctionSx/extendSxProp.js +21 -1
- package/legacy/styleFunctionSx/styleFunctionSx.js +44 -34
- package/modern/breakpoints.js +39 -8
- package/modern/createBox.js +5 -3
- package/modern/createStyled.js +5 -1
- package/modern/createTheme/createBreakpoints.js +2 -2
- package/modern/cssVars/createCssVarsProvider.js +207 -0
- package/modern/cssVars/cssVarsParser.js +141 -0
- package/modern/cssVars/getInitColorSchemeScript.js +42 -0
- package/modern/cssVars/index.js +1 -0
- package/modern/cssVars/useCurrentColorScheme.js +217 -0
- package/modern/index.js +3 -2
- package/modern/styleFunctionSx/extendSxProp.js +20 -1
- package/modern/styleFunctionSx/styleFunctionSx.js +45 -35
- package/package.json +8 -9
- package/style.d.ts +1 -1
- package/styleFunctionSx/extendSxProp.js +21 -1
- package/styleFunctionSx/styleFunctionSx.d.ts +7 -1
- package/styleFunctionSx/styleFunctionSx.js +46 -36
- package/styleFunctionSx/styleFunctionSx.spec.d.ts +1 -0
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;
|
package/createStyled.js
CHANGED
|
@@ -134,7 +134,11 @@ function createStyled(input = {}) {
|
|
|
134
134
|
|
|
135
135
|
const muiStyledResolver = (styleArg, ...expressions) => {
|
|
136
136
|
const expressionsWithDefaultTheme = expressions ? expressions.map(stylesArg => {
|
|
137
|
-
|
|
137
|
+
// On the server emotion doesn't use React.forwardRef for creating components, so the created
|
|
138
|
+
// component stays as a function. This condition makes sure that we do not interpolate functions
|
|
139
|
+
// which are basically components used as a selectors.
|
|
140
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
141
|
+
return typeof stylesArg === 'function' && stylesArg.__emotion_real !== stylesArg ? _ref => {
|
|
138
142
|
let {
|
|
139
143
|
theme: themeInput
|
|
140
144
|
} = _ref,
|
|
@@ -27,12 +27,12 @@ function createBreakpoints(breakpoints) {
|
|
|
27
27
|
xs: 0,
|
|
28
28
|
// phone
|
|
29
29
|
sm: 600,
|
|
30
|
-
//
|
|
30
|
+
// tablet
|
|
31
31
|
md: 900,
|
|
32
32
|
// small laptop
|
|
33
33
|
lg: 1200,
|
|
34
34
|
// desktop
|
|
35
|
-
xl: 1536 // large
|
|
35
|
+
xl: 1536 // large screen
|
|
36
36
|
|
|
37
37
|
},
|
|
38
38
|
unit = 'px',
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { Result, Mode } from './useCurrentColorScheme';
|
|
3
|
+
|
|
4
|
+
type RequiredDeep<T> = {
|
|
5
|
+
[K in keyof T]-?: RequiredDeep<T[K]>;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export type BuildCssVarsTheme<ThemeInput> = ThemeInput extends {
|
|
9
|
+
colorSchemes: Record<string, infer ColorSystems>;
|
|
10
|
+
}
|
|
11
|
+
? Omit<ThemeInput, 'colorSchemes'> &
|
|
12
|
+
ColorSystems & { vars: Omit<ThemeInput, 'colorSchemes'> & ColorSystems }
|
|
13
|
+
: never;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* DesignSystemColorScheme: is what a design system provide by default. Mostly, `light` and `dark`
|
|
17
|
+
* ApplicationColorScheme: is what developer can extend from a design system. Ex, `comfort` `trueDark` ...any name that they want
|
|
18
|
+
*
|
|
19
|
+
* This type enhance customization experience by checking if developer has extended the colorScheme or not (usually via module augmentation)
|
|
20
|
+
* If yes, they must provide the palette of the extended colorScheme. Otherwise `theme` is optional.
|
|
21
|
+
*/
|
|
22
|
+
type DecideTheme<
|
|
23
|
+
DesignSystemTheme extends { colorSchemes: Record<DesignSystemColorScheme, any> },
|
|
24
|
+
DesignSystemColorScheme extends string,
|
|
25
|
+
ApplicationTheme extends { colorSchemes: Record<ApplicationColorScheme, any> },
|
|
26
|
+
ApplicationColorScheme extends string | never,
|
|
27
|
+
> = [ApplicationColorScheme] extends [never]
|
|
28
|
+
? { theme?: DesignSystemTheme }
|
|
29
|
+
: {
|
|
30
|
+
theme: Omit<ApplicationTheme, 'colorSchemes'> & {
|
|
31
|
+
colorSchemes: Partial<
|
|
32
|
+
Record<
|
|
33
|
+
DesignSystemColorScheme,
|
|
34
|
+
DesignSystemTheme['colorSchemes'][DesignSystemColorScheme]
|
|
35
|
+
>
|
|
36
|
+
> &
|
|
37
|
+
RequiredDeep<
|
|
38
|
+
Record<ApplicationColorScheme, ApplicationTheme['colorSchemes'][ApplicationColorScheme]>
|
|
39
|
+
>;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export interface ColorSchemeContextValue<SupportedColorScheme extends string>
|
|
44
|
+
extends Result<SupportedColorScheme> {
|
|
45
|
+
allColorSchemes: SupportedColorScheme[];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export default function createCssVarsProvider<
|
|
49
|
+
DesignSystemThemeInput extends {
|
|
50
|
+
colorSchemes: Record<DesignSystemColorScheme, any>;
|
|
51
|
+
},
|
|
52
|
+
DesignSystemColorScheme extends string,
|
|
53
|
+
ApplicationThemeInput extends {
|
|
54
|
+
colorSchemes: Record<ApplicationColorScheme, any>;
|
|
55
|
+
} = never,
|
|
56
|
+
ApplicationColorScheme extends string = never,
|
|
57
|
+
>(options: {
|
|
58
|
+
/**
|
|
59
|
+
* Design system default theme
|
|
60
|
+
*/
|
|
61
|
+
theme: DesignSystemThemeInput;
|
|
62
|
+
/**
|
|
63
|
+
* Design system default color scheme
|
|
64
|
+
*/
|
|
65
|
+
defaultColorScheme:
|
|
66
|
+
| DesignSystemColorScheme
|
|
67
|
+
| { light: DesignSystemColorScheme; dark: DesignSystemColorScheme };
|
|
68
|
+
/**
|
|
69
|
+
* Design system default mode
|
|
70
|
+
* @default 'light'
|
|
71
|
+
*/
|
|
72
|
+
defaultMode?: Mode;
|
|
73
|
+
/**
|
|
74
|
+
* CSS variable prefix
|
|
75
|
+
* @default ''
|
|
76
|
+
*/
|
|
77
|
+
prefix?: string;
|
|
78
|
+
/**
|
|
79
|
+
* A function to determine if the key, value should be attached as CSS Variable
|
|
80
|
+
* `keys` is an array that represents the object path keys.
|
|
81
|
+
* Ex, if the theme is { foo: { bar: 'var(--test)' } }
|
|
82
|
+
* then, keys = ['foo', 'bar']
|
|
83
|
+
* value = 'var(--test)'
|
|
84
|
+
*/
|
|
85
|
+
shouldSkipGeneratingVar?: (keys: string[], value: string | number) => boolean;
|
|
86
|
+
}): {
|
|
87
|
+
CssVarsProvider: (
|
|
88
|
+
props: React.PropsWithChildren<
|
|
89
|
+
{
|
|
90
|
+
/**
|
|
91
|
+
* Application default mode (overrides design system `defaultMode` if specified)
|
|
92
|
+
*/
|
|
93
|
+
defaultMode?: Mode;
|
|
94
|
+
/**
|
|
95
|
+
* Application default colorScheme (overrides design system `defaultColorScheme` if specified)
|
|
96
|
+
*/
|
|
97
|
+
defaultColorScheme?:
|
|
98
|
+
| DesignSystemColorScheme
|
|
99
|
+
| ApplicationColorScheme
|
|
100
|
+
| {
|
|
101
|
+
light: DesignSystemColorScheme | ApplicationColorScheme;
|
|
102
|
+
dark: DesignSystemColorScheme | ApplicationColorScheme;
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* localStorage key used to store application `mode`
|
|
106
|
+
* @default 'mui-mode'
|
|
107
|
+
*/
|
|
108
|
+
modeStorageKey?: string;
|
|
109
|
+
/**
|
|
110
|
+
* DOM attribute for applying color scheme
|
|
111
|
+
* @default 'data-mui-color-scheme'
|
|
112
|
+
*/
|
|
113
|
+
attribute?: string;
|
|
114
|
+
/**
|
|
115
|
+
* CSS variable prefix (overrides design system `prefix` if specified)
|
|
116
|
+
*/
|
|
117
|
+
prefix?: string;
|
|
118
|
+
} & DecideTheme<
|
|
119
|
+
DesignSystemThemeInput,
|
|
120
|
+
DesignSystemColorScheme,
|
|
121
|
+
ApplicationThemeInput,
|
|
122
|
+
ApplicationColorScheme
|
|
123
|
+
>
|
|
124
|
+
>,
|
|
125
|
+
) => React.ReactElement;
|
|
126
|
+
useColorScheme: () => ColorSchemeContextValue<DesignSystemColorScheme | ApplicationColorScheme>;
|
|
127
|
+
getInitColorSchemeScript: () => React.ReactElement;
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
// disable automatic export
|
|
131
|
+
export {};
|
|
@@ -0,0 +1,228 @@
|
|
|
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 _ThemeProvider = _interopRequireDefault(require("../ThemeProvider"));
|
|
25
|
+
|
|
26
|
+
var _getInitColorSchemeScript = _interopRequireWildcard(require("./getInitColorSchemeScript"));
|
|
27
|
+
|
|
28
|
+
var _useCurrentColorScheme = _interopRequireDefault(require("./useCurrentColorScheme"));
|
|
29
|
+
|
|
30
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
31
|
+
|
|
32
|
+
const _excluded = ["colorSchemes"],
|
|
33
|
+
_excluded2 = ["colorSchemes"];
|
|
34
|
+
|
|
35
|
+
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); }
|
|
36
|
+
|
|
37
|
+
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; }
|
|
38
|
+
|
|
39
|
+
function createCssVarsProvider(options) {
|
|
40
|
+
const {
|
|
41
|
+
theme: baseTheme = {},
|
|
42
|
+
defaultMode: desisgnSystemMode = 'light',
|
|
43
|
+
defaultColorScheme: designSystemColorScheme,
|
|
44
|
+
prefix: designSystemPrefix = '',
|
|
45
|
+
shouldSkipGeneratingVar
|
|
46
|
+
} = options;
|
|
47
|
+
|
|
48
|
+
if (!baseTheme.colorSchemes || typeof designSystemColorScheme === 'string' && !baseTheme.colorSchemes[designSystemColorScheme] || typeof designSystemColorScheme === 'object' && !baseTheme.colorSchemes[designSystemColorScheme == null ? void 0 : designSystemColorScheme.light] || typeof designSystemColorScheme === 'object' && !baseTheme.colorSchemes[designSystemColorScheme == null ? void 0 : designSystemColorScheme.dark]) {
|
|
49
|
+
console.error(`MUI: \`${designSystemColorScheme}\` does not exist in \`theme.colorSchemes\`.`);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const ColorSchemeContext = /*#__PURE__*/React.createContext(undefined);
|
|
53
|
+
|
|
54
|
+
const useColorScheme = () => {
|
|
55
|
+
const value = React.useContext(ColorSchemeContext);
|
|
56
|
+
|
|
57
|
+
if (!value) {
|
|
58
|
+
throw new Error(process.env.NODE_ENV !== "production" ? `MUI: \`useColorScheme\` must be called under <CssVarsProvider />` : (0, _utils.formatMuiErrorMessage)(19));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return value;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
function CssVarsProvider({
|
|
65
|
+
children,
|
|
66
|
+
theme: themeProp = {},
|
|
67
|
+
prefix = designSystemPrefix,
|
|
68
|
+
modeStorageKey = _getInitColorSchemeScript.DEFAULT_MODE_STORAGE_KEY,
|
|
69
|
+
attribute = _getInitColorSchemeScript.DEFAULT_ATTRIBUTE,
|
|
70
|
+
defaultMode = desisgnSystemMode,
|
|
71
|
+
defaultColorScheme = designSystemColorScheme
|
|
72
|
+
}) {
|
|
73
|
+
const {
|
|
74
|
+
colorSchemes: baseColorSchemes = {}
|
|
75
|
+
} = baseTheme,
|
|
76
|
+
restBaseTheme = (0, _objectWithoutPropertiesLoose2.default)(baseTheme, _excluded);
|
|
77
|
+
const {
|
|
78
|
+
colorSchemes: colorSchemesProp = {}
|
|
79
|
+
} = themeProp,
|
|
80
|
+
restThemeProp = (0, _objectWithoutPropertiesLoose2.default)(themeProp, _excluded2);
|
|
81
|
+
let mergedTheme = (0, _utils.deepmerge)(restBaseTheme, restThemeProp);
|
|
82
|
+
const colorSchemes = (0, _utils.deepmerge)(baseColorSchemes, colorSchemesProp);
|
|
83
|
+
const allColorSchemes = Object.keys(colorSchemes);
|
|
84
|
+
const defaultLightColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.light;
|
|
85
|
+
const defaultDarkColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.dark;
|
|
86
|
+
const {
|
|
87
|
+
mode,
|
|
88
|
+
setMode,
|
|
89
|
+
lightColorScheme,
|
|
90
|
+
darkColorScheme,
|
|
91
|
+
colorScheme,
|
|
92
|
+
setColorScheme
|
|
93
|
+
} = (0, _useCurrentColorScheme.default)({
|
|
94
|
+
supportedColorSchemes: allColorSchemes,
|
|
95
|
+
defaultLightColorScheme,
|
|
96
|
+
defaultDarkColorScheme,
|
|
97
|
+
modeStorageKey,
|
|
98
|
+
defaultMode
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
const resolvedColorScheme = (() => {
|
|
102
|
+
if (!colorScheme) {
|
|
103
|
+
// This scope occurs on the server
|
|
104
|
+
if (defaultMode === 'dark') {
|
|
105
|
+
return defaultDarkColorScheme;
|
|
106
|
+
} // use light color scheme, if default mode is 'light' | 'auto'
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
return defaultLightColorScheme;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return colorScheme;
|
|
113
|
+
})();
|
|
114
|
+
|
|
115
|
+
const {
|
|
116
|
+
css: rootCss,
|
|
117
|
+
vars: rootVars
|
|
118
|
+
} = (0, _cssVarsParser.default)(mergedTheme, {
|
|
119
|
+
prefix,
|
|
120
|
+
basePrefix: designSystemPrefix,
|
|
121
|
+
shouldSkipGeneratingVar
|
|
122
|
+
});
|
|
123
|
+
mergedTheme = (0, _extends2.default)({}, mergedTheme, colorSchemes[resolvedColorScheme], {
|
|
124
|
+
vars: rootVars
|
|
125
|
+
});
|
|
126
|
+
const styleSheet = {};
|
|
127
|
+
Object.entries(colorSchemes).forEach(([key, scheme]) => {
|
|
128
|
+
const {
|
|
129
|
+
css,
|
|
130
|
+
vars
|
|
131
|
+
} = (0, _cssVarsParser.default)(scheme, {
|
|
132
|
+
prefix,
|
|
133
|
+
basePrefix: designSystemPrefix,
|
|
134
|
+
shouldSkipGeneratingVar
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
if (key === resolvedColorScheme) {
|
|
138
|
+
mergedTheme.vars = (0, _extends2.default)({}, mergedTheme.vars, vars);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const resolvedDefaultColorScheme = (() => {
|
|
142
|
+
if (typeof defaultColorScheme === 'string') {
|
|
143
|
+
return defaultColorScheme;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (defaultMode === 'dark') {
|
|
147
|
+
return defaultColorScheme.dark;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return defaultColorScheme.light;
|
|
151
|
+
})();
|
|
152
|
+
|
|
153
|
+
if (key === resolvedDefaultColorScheme) {
|
|
154
|
+
styleSheet[':root'] = css;
|
|
155
|
+
} else {
|
|
156
|
+
styleSheet[`[${attribute}="${key}"]`] = css;
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
React.useEffect(() => {
|
|
160
|
+
if (colorScheme) {
|
|
161
|
+
document.body.setAttribute(attribute, colorScheme);
|
|
162
|
+
}
|
|
163
|
+
}, [colorScheme, attribute]);
|
|
164
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(ColorSchemeContext.Provider, {
|
|
165
|
+
value: {
|
|
166
|
+
mode,
|
|
167
|
+
setMode,
|
|
168
|
+
lightColorScheme,
|
|
169
|
+
darkColorScheme,
|
|
170
|
+
colorScheme,
|
|
171
|
+
setColorScheme,
|
|
172
|
+
allColorSchemes
|
|
173
|
+
},
|
|
174
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_styledEngine.GlobalStyles, {
|
|
175
|
+
styles: {
|
|
176
|
+
':root': rootCss
|
|
177
|
+
}
|
|
178
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_styledEngine.GlobalStyles, {
|
|
179
|
+
styles: styleSheet
|
|
180
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ThemeProvider.default, {
|
|
181
|
+
theme: mergedTheme,
|
|
182
|
+
children: children
|
|
183
|
+
})]
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
process.env.NODE_ENV !== "production" ? CssVarsProvider.propTypes = {
|
|
188
|
+
/**
|
|
189
|
+
* The body attribute name to attach colorScheme.
|
|
190
|
+
*/
|
|
191
|
+
attribute: _propTypes.default.string,
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Your component tree.
|
|
195
|
+
*/
|
|
196
|
+
children: _propTypes.default.node,
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* The initial color scheme used.
|
|
200
|
+
*/
|
|
201
|
+
defaultColorScheme: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.object]),
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* The initial mode used.
|
|
205
|
+
*/
|
|
206
|
+
defaultMode: _propTypes.default.string,
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* The key in the local storage used to store current color scheme.
|
|
210
|
+
*/
|
|
211
|
+
modeStorageKey: _propTypes.default.string,
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* css variable prefix
|
|
215
|
+
*/
|
|
216
|
+
prefix: _propTypes.default.string,
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* The calculated theme object that will be passed through context.
|
|
220
|
+
*/
|
|
221
|
+
theme: _propTypes.default.object
|
|
222
|
+
} : void 0;
|
|
223
|
+
return {
|
|
224
|
+
CssVarsProvider,
|
|
225
|
+
useColorScheme,
|
|
226
|
+
getInitColorSchemeScript: _getInitColorSchemeScript.default
|
|
227
|
+
};
|
|
228
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,68 @@
|
|
|
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, scope: Record<string, string | number>) => void) => 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
|
+
* This function also mutate the string value of theme input by replacing `basePrefix` (if existed) with `prefix`
|
|
47
|
+
*
|
|
48
|
+
* @returns {{ css: Object, vars: Object }} `css` is the stylesheet, `vars` is an object to get css variable (same structure as theme)
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* const { css, vars } = parser({
|
|
52
|
+
* fontSize: 12,
|
|
53
|
+
* lineHeight: 1.2,
|
|
54
|
+
* palette: { primary: { 500: '#000000' } }
|
|
55
|
+
* })
|
|
56
|
+
*
|
|
57
|
+
* console.log(css) // { '--fontSize': '12px', '--lineHeight': 1.2, '--palette-primary-500': '#000000' }
|
|
58
|
+
* console.log(vars) // { fontSize: '--fontSize', lineHeight: '--lineHeight', palette: { primary: { 500: 'var(--palette-primary-500)' } } }
|
|
59
|
+
*/
|
|
60
|
+
export default function cssVarsParser(theme: Record<string, any>, options?: {
|
|
61
|
+
prefix?: string;
|
|
62
|
+
basePrefix?: string;
|
|
63
|
+
shouldSkipGeneratingVar?: (objectPathKeys: Array<string>, value: string | number) => boolean;
|
|
64
|
+
}): {
|
|
65
|
+
css: NestedRecord<string>;
|
|
66
|
+
vars: NestedRecord<string>;
|
|
67
|
+
};
|
|
68
|
+
export {};
|