@mui/system 5.0.3 → 5.1.0
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 +274 -0
- package/borders.js +1 -1
- package/breakpoints.js +45 -11
- package/colorManipulator.js +8 -8
- package/createBox.d.ts +5 -1
- package/createBox.js +5 -3
- package/createStyled.d.ts +16 -190
- package/createStyled.js +6 -2
- package/createTheme/createBreakpoints.d.ts +53 -6
- package/createTheme/createBreakpoints.js +3 -3
- 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/display.js +1 -1
- 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/flexbox.js +1 -1
- package/getThemeValue.js +1 -1
- package/grid.js +1 -1
- package/index.d.ts +6 -0
- package/index.js +77 -68
- 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 -8
- package/palette.js +1 -1
- package/positions.js +1 -1
- package/sizing.js +1 -1
- package/spacing.js +3 -3
- package/style.d.ts +2 -2
- package/style.js +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/typography.js +1 -1
- package/useTheme.js +1 -1
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
|
@@ -5,8 +5,8 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.shouldForwardProp = shouldForwardProp;
|
|
9
8
|
exports.default = createStyled;
|
|
9
|
+
exports.shouldForwardProp = shouldForwardProp;
|
|
10
10
|
exports.systemDefaultTheme = void 0;
|
|
11
11
|
|
|
12
12
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
@@ -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,
|
|
@@ -8,20 +8,67 @@ export type Breakpoint = OverridableStringUnion<
|
|
|
8
8
|
>;
|
|
9
9
|
export const keys: Breakpoint[];
|
|
10
10
|
|
|
11
|
+
// Keep in sync with docs/src/pages/customization/breakpoints/breakpoints.md
|
|
12
|
+
// #default-branch-switch
|
|
11
13
|
export interface Breakpoints {
|
|
12
14
|
keys: Breakpoint[];
|
|
15
|
+
/**
|
|
16
|
+
* Each breakpoint (a key) matches with a fixed screen width (a value).
|
|
17
|
+
* @default {
|
|
18
|
+
* // extra-small
|
|
19
|
+
* xs: 0,
|
|
20
|
+
* // small
|
|
21
|
+
* sm: 600,
|
|
22
|
+
* // medium
|
|
23
|
+
* md: 900,
|
|
24
|
+
* // large
|
|
25
|
+
* lg: 1200,
|
|
26
|
+
* // extra-large
|
|
27
|
+
* xl: 1536,
|
|
28
|
+
* }
|
|
29
|
+
*/
|
|
13
30
|
values: { [key in Breakpoint]: number };
|
|
31
|
+
/**
|
|
32
|
+
* @param key - A breakpoint key (`xs`, `sm`, etc.) or a screen width number in px.
|
|
33
|
+
* @returns A media query string ready to be used with most styling solutions, which matches screen widths greater than the screen size given by the breakpoint key (inclusive).
|
|
34
|
+
* @see [API documentation](https://mui.com/customization/breakpoints/#theme-breakpoints-up-key-media-query)
|
|
35
|
+
*/
|
|
14
36
|
up: (key: Breakpoint | number) => string;
|
|
37
|
+
/**
|
|
38
|
+
* @param key - A breakpoint key (`xs`, `sm`, etc.) or a screen width number in px.
|
|
39
|
+
* @returns A media query string ready to be used with most styling solutions, which matches screen widths less than the screen size given by the breakpoint key (exclusive).
|
|
40
|
+
* @see [API documentation](https://mui.com/customization/breakpoints/#theme-breakpoints-down-key-media-query)
|
|
41
|
+
*/
|
|
15
42
|
down: (key: Breakpoint | number) => string;
|
|
43
|
+
/**
|
|
44
|
+
* @param start - A breakpoint key (`xs`, `sm`, etc.) or a screen width number in px.
|
|
45
|
+
* @param end - A breakpoint key (`xs`, `sm`, etc.) or a screen width number in px.
|
|
46
|
+
* @returns A media query string ready to be used with most styling solutions, which matches screen widths greater than
|
|
47
|
+
* the screen size given by the breakpoint key in the first argument (inclusive) and less than the screen size given by the breakpoint key in the second argument (exclusive).
|
|
48
|
+
* @see [API documentation](https://mui.com/customization/breakpoints/#theme-breakpoints-between-start-end-media-query)
|
|
49
|
+
*/
|
|
16
50
|
between: (start: Breakpoint | number, end: Breakpoint | number) => string;
|
|
51
|
+
/**
|
|
52
|
+
* @param key - A breakpoint key (`xs`, `sm`, etc.) or a screen width number in px.
|
|
53
|
+
* @returns A media query string ready to be used with most styling solutions, which matches screen widths starting from
|
|
54
|
+
* the screen size given by the breakpoint key (inclusive) and stopping at the screen size given by the next breakpoint key (exclusive).
|
|
55
|
+
* @see [API documentation](https://mui.com/customization/breakpoints/#theme-breakpoints-only-key-media-query)
|
|
56
|
+
*/
|
|
17
57
|
only: (key: Breakpoint) => string;
|
|
18
58
|
}
|
|
19
59
|
|
|
20
|
-
export
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
60
|
+
export interface BreakpointsOptions extends Partial<Breakpoints> {
|
|
61
|
+
/**
|
|
62
|
+
* The increment divided by 100 used to implement exclusive breakpoints.
|
|
63
|
+
* For example, `step: 5` means that `down(500)` will result in `'(max-width: 499.95px)'`.
|
|
64
|
+
* @default 5
|
|
65
|
+
*/
|
|
66
|
+
step?: number | undefined;
|
|
67
|
+
/**
|
|
68
|
+
* The unit used for the breakpoint's values.
|
|
69
|
+
* @default 'px'
|
|
70
|
+
*/
|
|
71
|
+
unit?: string | undefined;
|
|
72
|
+
}
|
|
26
73
|
|
|
27
74
|
export default function createBreakpoints(options: BreakpointsOptions): Breakpoints;
|
|
@@ -5,8 +5,8 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.default = createBreakpoints;
|
|
9
8
|
exports.breakpointKeys = void 0;
|
|
9
|
+
exports.default = createBreakpoints;
|
|
10
10
|
|
|
11
11
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
12
12
|
|
|
@@ -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 {};
|