@mui/system 7.0.1 → 7.0.2
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 +60 -0
- package/cssVars/cssVarsParser.d.ts +1 -1
- package/esm/cssVars/cssVarsParser.d.ts +1 -1
- package/esm/index.js +1 -1
- package/esm/memoTheme.d.ts +1 -1
- package/esm/useThemeProps/getThemeProps.d.ts +0 -5
- package/esm/version/index.js +2 -2
- package/index.js +1 -1
- package/memoTheme.d.ts +1 -1
- package/modern/cssVars/cssVarsParser.d.ts +1 -1
- package/modern/memoTheme.d.ts +1 -1
- package/modern/useThemeProps/getThemeProps.d.ts +0 -5
- package/package.json +6 -14
- package/useThemeProps/getThemeProps.d.ts +0 -5
- package/version/index.js +2 -2
- package/modern/Box/Box.js +0 -30
- package/modern/Box/boxClasses.js +0 -3
- package/modern/Box/index.js +0 -3
- package/modern/Container/Container.js +0 -61
- package/modern/Container/ContainerProps.js +0 -1
- package/modern/Container/containerClasses.js +0 -7
- package/modern/Container/createContainer.js +0 -149
- package/modern/Container/index.js +0 -3
- package/modern/DefaultPropsProvider/DefaultPropsProvider.js +0 -64
- package/modern/DefaultPropsProvider/index.js +0 -1
- package/modern/GlobalStyles/GlobalStyles.js +0 -37
- package/modern/GlobalStyles/index.js +0 -2
- package/modern/Grid/Grid.js +0 -106
- package/modern/Grid/GridProps.js +0 -1
- package/modern/Grid/createGrid.js +0 -155
- package/modern/Grid/deleteLegacyGridProps.js +0 -41
- package/modern/Grid/gridClasses.js +0 -19
- package/modern/Grid/gridGenerator.js +0 -193
- package/modern/Grid/index.js +0 -7
- package/modern/Grid/traverseBreakpoints.js +0 -42
- package/modern/InitColorSchemeScript/InitColorSchemeScript.js +0 -78
- package/modern/InitColorSchemeScript/index.js +0 -1
- package/modern/RtlProvider/index.js +0 -24
- package/modern/Stack/Stack.js +0 -62
- package/modern/Stack/StackProps.js +0 -1
- package/modern/Stack/createStack.js +0 -173
- package/modern/Stack/index.js +0 -5
- package/modern/Stack/stackClasses.js +0 -7
- package/modern/ThemeProvider/ThemeProvider.js +0 -97
- package/modern/ThemeProvider/index.js +0 -1
- package/modern/borders/borders.js +0 -49
- package/modern/borders/index.js +0 -2
- package/modern/breakpoints/breakpoints.js +0 -171
- package/modern/breakpoints/index.js +0 -2
- package/modern/colorManipulator/colorManipulator.js +0 -349
- package/modern/colorManipulator/index.js +0 -1
- package/modern/compose/compose.js +0 -24
- package/modern/compose/index.js +0 -1
- package/modern/createBox/createBox.js +0 -35
- package/modern/createBox/index.js +0 -1
- package/modern/createBreakpoints/createBreakpoints.js +0 -81
- package/modern/createBreakpoints/index.js +0 -3
- package/modern/createStyled/createStyled.js +0 -276
- package/modern/createStyled/index.js +0 -2
- package/modern/createTheme/applyStyles.js +0 -87
- package/modern/createTheme/createSpacing.js +0 -31
- package/modern/createTheme/createTheme.js +0 -49
- package/modern/createTheme/index.js +0 -3
- package/modern/createTheme/shape.js +0 -4
- package/modern/cssContainerQueries/cssContainerQueries.js +0 -69
- package/modern/cssContainerQueries/index.js +0 -2
- package/modern/cssGrid/cssGrid.js +0 -85
- package/modern/cssGrid/index.js +0 -2
- package/modern/cssVars/createCssVarsProvider.js +0 -338
- package/modern/cssVars/createCssVarsTheme.js +0 -21
- package/modern/cssVars/createGetCssVar.js +0 -22
- package/modern/cssVars/cssVarsParser.js +0 -129
- package/modern/cssVars/getColorSchemeSelector.js +0 -26
- package/modern/cssVars/index.js +0 -5
- package/modern/cssVars/localStorageManager.js +0 -51
- package/modern/cssVars/prepareCssVars.js +0 -153
- package/modern/cssVars/prepareTypographyVars.js +0 -11
- package/modern/cssVars/useCurrentColorScheme.js +0 -228
- package/modern/display/display.js +0 -27
- package/modern/display/index.js +0 -2
- package/modern/flexbox/flexbox.js +0 -43
- package/modern/flexbox/index.js +0 -2
- package/modern/getThemeValue/getThemeValue.js +0 -51
- package/modern/getThemeValue/index.js +0 -2
- package/modern/index.js +0 -75
- package/modern/memoTheme.js +0 -28
- package/modern/memoize/index.js +0 -1
- package/modern/memoize/memoize.js +0 -9
- package/modern/merge/index.js +0 -1
- package/modern/merge/merge.js +0 -10
- package/modern/package.json +0 -1
- package/modern/palette/index.js +0 -2
- package/modern/palette/palette.js +0 -26
- package/modern/positions/index.js +0 -2
- package/modern/positions/positions.js +0 -22
- package/modern/preprocessStyles.js +0 -25
- package/modern/propsToClassKey/index.js +0 -1
- package/modern/propsToClassKey/propsToClassKey.js +0 -25
- package/modern/responsivePropType/index.js +0 -1
- package/modern/responsivePropType/responsivePropType.js +0 -3
- package/modern/shadows/index.js +0 -1
- package/modern/shadows/shadows.js +0 -6
- package/modern/sizing/index.js +0 -2
- package/modern/sizing/sizing.js +0 -64
- package/modern/spacing/index.js +0 -2
- package/modern/spacing/spacing.js +0 -157
- package/modern/style/index.js +0 -2
- package/modern/style/style.js +0 -75
- package/modern/styleFunctionSx/AliasesCSSProperties.js +0 -1
- package/modern/styleFunctionSx/OverwriteCSSProperties.js +0 -1
- package/modern/styleFunctionSx/StandardCssProperties.js +0 -1
- package/modern/styleFunctionSx/defaultSxConfig.js +0 -294
- package/modern/styleFunctionSx/extendSxProp.js +0 -51
- package/modern/styleFunctionSx/index.js +0 -4
- package/modern/styleFunctionSx/styleFunctionSx.js +0 -127
- package/modern/styled/index.js +0 -1
- package/modern/styled/styled.js +0 -3
- package/modern/typography/index.js +0 -2
- package/modern/typography/typography.js +0 -37
- package/modern/useMediaQuery/index.js +0 -2
- package/modern/useMediaQuery/useMediaQuery.js +0 -118
- package/modern/useTheme/index.js +0 -2
- package/modern/useTheme/useTheme.js +0 -9
- package/modern/useThemeProps/getThemeProps.js +0 -12
- package/modern/useThemeProps/index.js +0 -2
- package/modern/useThemeProps/useThemeProps.js +0 -20
- package/modern/useThemeWithoutDefault/index.js +0 -1
- package/modern/useThemeWithoutDefault/useThemeWithoutDefault.js +0 -12
- package/modern/version/index.js +0 -6
- package/tsconfig.build.tsbuildinfo +0 -1
|
@@ -1,276 +0,0 @@
|
|
|
1
|
-
import styledEngineStyled, { internal_mutateStyles as mutateStyles } from '@mui/styled-engine';
|
|
2
|
-
import { isPlainObject } from '@mui/utils/deepmerge';
|
|
3
|
-
import capitalize from '@mui/utils/capitalize';
|
|
4
|
-
import getDisplayName from '@mui/utils/getDisplayName';
|
|
5
|
-
import createTheme from "../createTheme/index.js";
|
|
6
|
-
import styleFunctionSx from "../styleFunctionSx/index.js";
|
|
7
|
-
import preprocessStyles from "../preprocessStyles.js";
|
|
8
|
-
|
|
9
|
-
/* eslint-disable no-underscore-dangle */
|
|
10
|
-
/* eslint-disable no-labels */
|
|
11
|
-
/* eslint-disable no-lone-blocks */
|
|
12
|
-
|
|
13
|
-
export const systemDefaultTheme = createTheme();
|
|
14
|
-
|
|
15
|
-
// Update /system/styled/#api in case if this changes
|
|
16
|
-
export function shouldForwardProp(prop) {
|
|
17
|
-
return prop !== 'ownerState' && prop !== 'theme' && prop !== 'sx' && prop !== 'as';
|
|
18
|
-
}
|
|
19
|
-
function defaultOverridesResolver(slot) {
|
|
20
|
-
if (!slot) {
|
|
21
|
-
return null;
|
|
22
|
-
}
|
|
23
|
-
return (_props, styles) => styles[slot];
|
|
24
|
-
}
|
|
25
|
-
function attachTheme(props, themeId, defaultTheme) {
|
|
26
|
-
props.theme = isObjectEmpty(props.theme) ? defaultTheme : props.theme[themeId] || props.theme;
|
|
27
|
-
}
|
|
28
|
-
function processStyle(props, style) {
|
|
29
|
-
/*
|
|
30
|
-
* Style types:
|
|
31
|
-
* - null/undefined
|
|
32
|
-
* - string
|
|
33
|
-
* - CSS style object: { [cssKey]: [cssValue], variants }
|
|
34
|
-
* - Processed style object: { style, variants, isProcessed: true }
|
|
35
|
-
* - Array of any of the above
|
|
36
|
-
*/
|
|
37
|
-
|
|
38
|
-
const resolvedStyle = typeof style === 'function' ? style(props) : style;
|
|
39
|
-
if (Array.isArray(resolvedStyle)) {
|
|
40
|
-
return resolvedStyle.flatMap(subStyle => processStyle(props, subStyle));
|
|
41
|
-
}
|
|
42
|
-
if (Array.isArray(resolvedStyle?.variants)) {
|
|
43
|
-
let rootStyle;
|
|
44
|
-
if (resolvedStyle.isProcessed) {
|
|
45
|
-
rootStyle = resolvedStyle.style;
|
|
46
|
-
} else {
|
|
47
|
-
const {
|
|
48
|
-
variants,
|
|
49
|
-
...otherStyles
|
|
50
|
-
} = resolvedStyle;
|
|
51
|
-
rootStyle = otherStyles;
|
|
52
|
-
}
|
|
53
|
-
return processStyleVariants(props, resolvedStyle.variants, [rootStyle]);
|
|
54
|
-
}
|
|
55
|
-
if (resolvedStyle?.isProcessed) {
|
|
56
|
-
return resolvedStyle.style;
|
|
57
|
-
}
|
|
58
|
-
return resolvedStyle;
|
|
59
|
-
}
|
|
60
|
-
function processStyleVariants(props, variants, results = []) {
|
|
61
|
-
let mergedState; // We might not need it, initialized lazily
|
|
62
|
-
|
|
63
|
-
variantLoop: for (let i = 0; i < variants.length; i += 1) {
|
|
64
|
-
const variant = variants[i];
|
|
65
|
-
if (typeof variant.props === 'function') {
|
|
66
|
-
mergedState ?? (mergedState = {
|
|
67
|
-
...props,
|
|
68
|
-
...props.ownerState,
|
|
69
|
-
ownerState: props.ownerState
|
|
70
|
-
});
|
|
71
|
-
if (!variant.props(mergedState)) {
|
|
72
|
-
continue;
|
|
73
|
-
}
|
|
74
|
-
} else {
|
|
75
|
-
for (const key in variant.props) {
|
|
76
|
-
if (props[key] !== variant.props[key] && props.ownerState?.[key] !== variant.props[key]) {
|
|
77
|
-
continue variantLoop;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
if (typeof variant.style === 'function') {
|
|
82
|
-
mergedState ?? (mergedState = {
|
|
83
|
-
...props,
|
|
84
|
-
...props.ownerState,
|
|
85
|
-
ownerState: props.ownerState
|
|
86
|
-
});
|
|
87
|
-
results.push(variant.style(mergedState));
|
|
88
|
-
} else {
|
|
89
|
-
results.push(variant.style);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
return results;
|
|
93
|
-
}
|
|
94
|
-
export default function createStyled(input = {}) {
|
|
95
|
-
const {
|
|
96
|
-
themeId,
|
|
97
|
-
defaultTheme = systemDefaultTheme,
|
|
98
|
-
rootShouldForwardProp = shouldForwardProp,
|
|
99
|
-
slotShouldForwardProp = shouldForwardProp
|
|
100
|
-
} = input;
|
|
101
|
-
function styleAttachTheme(props) {
|
|
102
|
-
attachTheme(props, themeId, defaultTheme);
|
|
103
|
-
}
|
|
104
|
-
const styled = (tag, inputOptions = {}) => {
|
|
105
|
-
// If `tag` is already a styled component, filter out the `sx` style function
|
|
106
|
-
// to prevent unnecessary styles generated by the composite components.
|
|
107
|
-
mutateStyles(tag, styles => styles.filter(style => style !== styleFunctionSx));
|
|
108
|
-
const {
|
|
109
|
-
name: componentName,
|
|
110
|
-
slot: componentSlot,
|
|
111
|
-
skipVariantsResolver: inputSkipVariantsResolver,
|
|
112
|
-
skipSx: inputSkipSx,
|
|
113
|
-
// TODO v6: remove `lowercaseFirstLetter()` in the next major release
|
|
114
|
-
// For more details: https://github.com/mui/material-ui/pull/37908
|
|
115
|
-
overridesResolver = defaultOverridesResolver(lowercaseFirstLetter(componentSlot)),
|
|
116
|
-
...options
|
|
117
|
-
} = inputOptions;
|
|
118
|
-
|
|
119
|
-
// if skipVariantsResolver option is defined, take the value, otherwise, true for root and false for other slots.
|
|
120
|
-
const skipVariantsResolver = inputSkipVariantsResolver !== undefined ? inputSkipVariantsResolver :
|
|
121
|
-
// TODO v6: remove `Root` in the next major release
|
|
122
|
-
// For more details: https://github.com/mui/material-ui/pull/37908
|
|
123
|
-
componentSlot && componentSlot !== 'Root' && componentSlot !== 'root' || false;
|
|
124
|
-
const skipSx = inputSkipSx || false;
|
|
125
|
-
let shouldForwardPropOption = shouldForwardProp;
|
|
126
|
-
|
|
127
|
-
// TODO v6: remove `Root` in the next major release
|
|
128
|
-
// For more details: https://github.com/mui/material-ui/pull/37908
|
|
129
|
-
if (componentSlot === 'Root' || componentSlot === 'root') {
|
|
130
|
-
shouldForwardPropOption = rootShouldForwardProp;
|
|
131
|
-
} else if (componentSlot) {
|
|
132
|
-
// any other slot specified
|
|
133
|
-
shouldForwardPropOption = slotShouldForwardProp;
|
|
134
|
-
} else if (isStringTag(tag)) {
|
|
135
|
-
// for string (html) tag, preserve the behavior in emotion & styled-components.
|
|
136
|
-
shouldForwardPropOption = undefined;
|
|
137
|
-
}
|
|
138
|
-
const defaultStyledResolver = styledEngineStyled(tag, {
|
|
139
|
-
shouldForwardProp: shouldForwardPropOption,
|
|
140
|
-
label: generateStyledLabel(componentName, componentSlot),
|
|
141
|
-
...options
|
|
142
|
-
});
|
|
143
|
-
const transformStyle = style => {
|
|
144
|
-
// On the server Emotion doesn't use React.forwardRef for creating components, so the created
|
|
145
|
-
// component stays as a function. This condition makes sure that we do not interpolate functions
|
|
146
|
-
// which are basically components used as a selectors.
|
|
147
|
-
if (typeof style === 'function' && style.__emotion_real !== style) {
|
|
148
|
-
return function styleFunctionProcessor(props) {
|
|
149
|
-
return processStyle(props, style);
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
if (isPlainObject(style)) {
|
|
153
|
-
const serialized = preprocessStyles(style);
|
|
154
|
-
if (!serialized.variants) {
|
|
155
|
-
return serialized.style;
|
|
156
|
-
}
|
|
157
|
-
return function styleObjectProcessor(props) {
|
|
158
|
-
return processStyle(props, serialized);
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
return style;
|
|
162
|
-
};
|
|
163
|
-
const muiStyledResolver = (...expressionsInput) => {
|
|
164
|
-
const expressionsHead = [];
|
|
165
|
-
const expressionsBody = expressionsInput.map(transformStyle);
|
|
166
|
-
const expressionsTail = [];
|
|
167
|
-
|
|
168
|
-
// Preprocess `props` to set the scoped theme value.
|
|
169
|
-
// This must run before any other expression.
|
|
170
|
-
expressionsHead.push(styleAttachTheme);
|
|
171
|
-
if (componentName && overridesResolver) {
|
|
172
|
-
expressionsTail.push(function styleThemeOverrides(props) {
|
|
173
|
-
const theme = props.theme;
|
|
174
|
-
const styleOverrides = theme.components?.[componentName]?.styleOverrides;
|
|
175
|
-
if (!styleOverrides) {
|
|
176
|
-
return null;
|
|
177
|
-
}
|
|
178
|
-
const resolvedStyleOverrides = {};
|
|
179
|
-
|
|
180
|
-
// TODO: v7 remove iteration and use `resolveStyleArg(styleOverrides[slot])` directly
|
|
181
|
-
// eslint-disable-next-line guard-for-in
|
|
182
|
-
for (const slotKey in styleOverrides) {
|
|
183
|
-
resolvedStyleOverrides[slotKey] = processStyle(props, styleOverrides[slotKey]);
|
|
184
|
-
}
|
|
185
|
-
return overridesResolver(props, resolvedStyleOverrides);
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
if (componentName && !skipVariantsResolver) {
|
|
189
|
-
expressionsTail.push(function styleThemeVariants(props) {
|
|
190
|
-
const theme = props.theme;
|
|
191
|
-
const themeVariants = theme?.components?.[componentName]?.variants;
|
|
192
|
-
if (!themeVariants) {
|
|
193
|
-
return null;
|
|
194
|
-
}
|
|
195
|
-
return processStyleVariants(props, themeVariants);
|
|
196
|
-
});
|
|
197
|
-
}
|
|
198
|
-
if (!skipSx) {
|
|
199
|
-
expressionsTail.push(styleFunctionSx);
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
// This function can be called as a tagged template, so the first argument would contain
|
|
203
|
-
// CSS `string[]` values.
|
|
204
|
-
if (Array.isArray(expressionsBody[0])) {
|
|
205
|
-
const inputStrings = expressionsBody.shift();
|
|
206
|
-
|
|
207
|
-
// We need to add placeholders in the tagged template for the custom functions we have
|
|
208
|
-
// possibly added (attachTheme, overrides, variants, and sx).
|
|
209
|
-
const placeholdersHead = new Array(expressionsHead.length).fill('');
|
|
210
|
-
const placeholdersTail = new Array(expressionsTail.length).fill('');
|
|
211
|
-
let outputStrings;
|
|
212
|
-
// prettier-ignore
|
|
213
|
-
{
|
|
214
|
-
outputStrings = [...placeholdersHead, ...inputStrings, ...placeholdersTail];
|
|
215
|
-
outputStrings.raw = [...placeholdersHead, ...inputStrings.raw, ...placeholdersTail];
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
// The only case where we put something before `attachTheme`
|
|
219
|
-
expressionsHead.unshift(outputStrings);
|
|
220
|
-
}
|
|
221
|
-
const expressions = [...expressionsHead, ...expressionsBody, ...expressionsTail];
|
|
222
|
-
const Component = defaultStyledResolver(...expressions);
|
|
223
|
-
if (tag.muiName) {
|
|
224
|
-
Component.muiName = tag.muiName;
|
|
225
|
-
}
|
|
226
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
227
|
-
Component.displayName = generateDisplayName(componentName, componentSlot, tag);
|
|
228
|
-
}
|
|
229
|
-
return Component;
|
|
230
|
-
};
|
|
231
|
-
if (defaultStyledResolver.withConfig) {
|
|
232
|
-
muiStyledResolver.withConfig = defaultStyledResolver.withConfig;
|
|
233
|
-
}
|
|
234
|
-
return muiStyledResolver;
|
|
235
|
-
};
|
|
236
|
-
return styled;
|
|
237
|
-
}
|
|
238
|
-
function generateDisplayName(componentName, componentSlot, tag) {
|
|
239
|
-
if (componentName) {
|
|
240
|
-
return `${componentName}${capitalize(componentSlot || '')}`;
|
|
241
|
-
}
|
|
242
|
-
return `Styled(${getDisplayName(tag)})`;
|
|
243
|
-
}
|
|
244
|
-
function generateStyledLabel(componentName, componentSlot) {
|
|
245
|
-
let label;
|
|
246
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
247
|
-
if (componentName) {
|
|
248
|
-
// TODO v6: remove `lowercaseFirstLetter()` in the next major release
|
|
249
|
-
// For more details: https://github.com/mui/material-ui/pull/37908
|
|
250
|
-
label = `${componentName}-${lowercaseFirstLetter(componentSlot || 'Root')}`;
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
return label;
|
|
254
|
-
}
|
|
255
|
-
function isObjectEmpty(object) {
|
|
256
|
-
// eslint-disable-next-line
|
|
257
|
-
for (const _ in object) {
|
|
258
|
-
return false;
|
|
259
|
-
}
|
|
260
|
-
return true;
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
// https://github.com/emotion-js/emotion/blob/26ded6109fcd8ca9875cc2ce4564fee678a3f3c5/packages/styled/src/utils.js#L40
|
|
264
|
-
function isStringTag(tag) {
|
|
265
|
-
return typeof tag === 'string' &&
|
|
266
|
-
// 96 is one less than the char code
|
|
267
|
-
// for "a" so this is checking that
|
|
268
|
-
// it's a lowercase character
|
|
269
|
-
tag.charCodeAt(0) > 96;
|
|
270
|
-
}
|
|
271
|
-
function lowercaseFirstLetter(string) {
|
|
272
|
-
if (!string) {
|
|
273
|
-
return string;
|
|
274
|
-
}
|
|
275
|
-
return string.charAt(0).toLowerCase() + string.slice(1);
|
|
276
|
-
}
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A universal utility to style components with multiple color modes. Always use it from the theme object.
|
|
3
|
-
* It works with:
|
|
4
|
-
* - [Basic theme](https://mui.com/material-ui/customization/dark-mode/)
|
|
5
|
-
* - [CSS theme variables](https://mui.com/material-ui/customization/css-theme-variables/overview/)
|
|
6
|
-
* - Zero-runtime engine
|
|
7
|
-
*
|
|
8
|
-
* Tips: Use an array over object spread and place `theme.applyStyles()` last.
|
|
9
|
-
*
|
|
10
|
-
* With the styled function:
|
|
11
|
-
* ✅ [{ background: '#e5e5e5' }, theme.applyStyles('dark', { background: '#1c1c1c' })]
|
|
12
|
-
* 🚫 { background: '#e5e5e5', ...theme.applyStyles('dark', { background: '#1c1c1c' })}
|
|
13
|
-
*
|
|
14
|
-
* With the sx prop:
|
|
15
|
-
* ✅ [{ background: '#e5e5e5' }, theme => theme.applyStyles('dark', { background: '#1c1c1c' })]
|
|
16
|
-
* 🚫 { background: '#e5e5e5', ...theme => theme.applyStyles('dark', { background: '#1c1c1c' })}
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* 1. using with `styled`:
|
|
20
|
-
* ```jsx
|
|
21
|
-
* const Component = styled('div')(({ theme }) => [
|
|
22
|
-
* { background: '#e5e5e5' },
|
|
23
|
-
* theme.applyStyles('dark', {
|
|
24
|
-
* background: '#1c1c1c',
|
|
25
|
-
* color: '#fff',
|
|
26
|
-
* }),
|
|
27
|
-
* ]);
|
|
28
|
-
* ```
|
|
29
|
-
*
|
|
30
|
-
* @example
|
|
31
|
-
* 2. using with `sx` prop:
|
|
32
|
-
* ```jsx
|
|
33
|
-
* <Box sx={[
|
|
34
|
-
* { background: '#e5e5e5' },
|
|
35
|
-
* theme => theme.applyStyles('dark', {
|
|
36
|
-
* background: '#1c1c1c',
|
|
37
|
-
* color: '#fff',
|
|
38
|
-
* }),
|
|
39
|
-
* ]}
|
|
40
|
-
* />
|
|
41
|
-
* ```
|
|
42
|
-
*
|
|
43
|
-
* @example
|
|
44
|
-
* 3. theming a component:
|
|
45
|
-
* ```jsx
|
|
46
|
-
* extendTheme({
|
|
47
|
-
* components: {
|
|
48
|
-
* MuiButton: {
|
|
49
|
-
* styleOverrides: {
|
|
50
|
-
* root: ({ theme }) => [
|
|
51
|
-
* { background: '#e5e5e5' },
|
|
52
|
-
* theme.applyStyles('dark', {
|
|
53
|
-
* background: '#1c1c1c',
|
|
54
|
-
* color: '#fff',
|
|
55
|
-
* }),
|
|
56
|
-
* ],
|
|
57
|
-
* },
|
|
58
|
-
* }
|
|
59
|
-
* }
|
|
60
|
-
* })
|
|
61
|
-
*```
|
|
62
|
-
*/
|
|
63
|
-
export default function applyStyles(key, styles) {
|
|
64
|
-
// @ts-expect-error this is 'any' type
|
|
65
|
-
const theme = this;
|
|
66
|
-
if (theme.vars) {
|
|
67
|
-
if (!theme.colorSchemes?.[key] || typeof theme.getColorSchemeSelector !== 'function') {
|
|
68
|
-
return {};
|
|
69
|
-
}
|
|
70
|
-
// If CssVarsProvider is used as a provider, returns '*:where({selector}) &'
|
|
71
|
-
let selector = theme.getColorSchemeSelector(key);
|
|
72
|
-
if (selector === '&') {
|
|
73
|
-
return styles;
|
|
74
|
-
}
|
|
75
|
-
if (selector.includes('data-') || selector.includes('.')) {
|
|
76
|
-
// '*' is required as a workaround for Emotion issue (https://github.com/emotion-js/emotion/issues/2836)
|
|
77
|
-
selector = `*:where(${selector.replace(/\s*&$/, '')}) &`;
|
|
78
|
-
}
|
|
79
|
-
return {
|
|
80
|
-
[selector]: styles
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
if (theme.palette.mode === key) {
|
|
84
|
-
return styles;
|
|
85
|
-
}
|
|
86
|
-
return {};
|
|
87
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { createUnarySpacing } from "../spacing/index.js";
|
|
2
|
-
|
|
3
|
-
// The different signatures imply different meaning for their arguments that can't be expressed structurally.
|
|
4
|
-
// We express the difference with variable names.
|
|
5
|
-
|
|
6
|
-
export default function createSpacing(spacingInput = 8,
|
|
7
|
-
// Material Design layouts are visually balanced. Most measurements align to an 8dp grid, which aligns both spacing and the overall layout.
|
|
8
|
-
// Smaller components, such as icons, can align to a 4dp grid.
|
|
9
|
-
// https://m2.material.io/design/layout/understanding-layout.html
|
|
10
|
-
transform = createUnarySpacing({
|
|
11
|
-
spacing: spacingInput
|
|
12
|
-
})) {
|
|
13
|
-
// Already transformed.
|
|
14
|
-
if (spacingInput.mui) {
|
|
15
|
-
return spacingInput;
|
|
16
|
-
}
|
|
17
|
-
const spacing = (...argsInput) => {
|
|
18
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
19
|
-
if (!(argsInput.length <= 4)) {
|
|
20
|
-
console.error(`MUI: Too many arguments provided, expected between 0 and 4, got ${argsInput.length}`);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
const args = argsInput.length === 0 ? [1] : argsInput;
|
|
24
|
-
return args.map(argument => {
|
|
25
|
-
const output = transform(argument);
|
|
26
|
-
return typeof output === 'number' ? `${output}px` : output;
|
|
27
|
-
}).join(' ');
|
|
28
|
-
};
|
|
29
|
-
spacing.mui = true;
|
|
30
|
-
return spacing;
|
|
31
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import deepmerge from '@mui/utils/deepmerge';
|
|
2
|
-
import createBreakpoints from "../createBreakpoints/createBreakpoints.js";
|
|
3
|
-
import cssContainerQueries from "../cssContainerQueries/index.js";
|
|
4
|
-
import shape from "./shape.js";
|
|
5
|
-
import createSpacing from "./createSpacing.js";
|
|
6
|
-
import styleFunctionSx from "../styleFunctionSx/styleFunctionSx.js";
|
|
7
|
-
import defaultSxConfig from "../styleFunctionSx/defaultSxConfig.js";
|
|
8
|
-
import applyStyles from "./applyStyles.js";
|
|
9
|
-
function createTheme(options = {}, ...args) {
|
|
10
|
-
const {
|
|
11
|
-
breakpoints: breakpointsInput = {},
|
|
12
|
-
palette: paletteInput = {},
|
|
13
|
-
spacing: spacingInput,
|
|
14
|
-
shape: shapeInput = {},
|
|
15
|
-
...other
|
|
16
|
-
} = options;
|
|
17
|
-
const breakpoints = createBreakpoints(breakpointsInput);
|
|
18
|
-
const spacing = createSpacing(spacingInput);
|
|
19
|
-
let muiTheme = deepmerge({
|
|
20
|
-
breakpoints,
|
|
21
|
-
direction: 'ltr',
|
|
22
|
-
components: {},
|
|
23
|
-
// Inject component definitions.
|
|
24
|
-
palette: {
|
|
25
|
-
mode: 'light',
|
|
26
|
-
...paletteInput
|
|
27
|
-
},
|
|
28
|
-
spacing,
|
|
29
|
-
shape: {
|
|
30
|
-
...shape,
|
|
31
|
-
...shapeInput
|
|
32
|
-
}
|
|
33
|
-
}, other);
|
|
34
|
-
muiTheme = cssContainerQueries(muiTheme);
|
|
35
|
-
muiTheme.applyStyles = applyStyles;
|
|
36
|
-
muiTheme = args.reduce((acc, argument) => deepmerge(acc, argument), muiTheme);
|
|
37
|
-
muiTheme.unstable_sxConfig = {
|
|
38
|
-
...defaultSxConfig,
|
|
39
|
-
...other?.unstable_sxConfig
|
|
40
|
-
};
|
|
41
|
-
muiTheme.unstable_sx = function sx(props) {
|
|
42
|
-
return styleFunctionSx({
|
|
43
|
-
sx: props,
|
|
44
|
-
theme: this
|
|
45
|
-
});
|
|
46
|
-
};
|
|
47
|
-
return muiTheme;
|
|
48
|
-
}
|
|
49
|
-
export default createTheme;
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import _formatErrorMessage from "@mui/utils/formatMuiErrorMessage";
|
|
2
|
-
/**
|
|
3
|
-
* For using in `sx` prop to sort the breakpoint from low to high.
|
|
4
|
-
* Note: this function does not work and will not support multiple units.
|
|
5
|
-
* e.g. input: { '@container (min-width:300px)': '1rem', '@container (min-width:40rem)': '2rem' }
|
|
6
|
-
* output: { '@container (min-width:40rem)': '2rem', '@container (min-width:300px)': '1rem' } // since 40 < 300 eventhough 40rem > 300px
|
|
7
|
-
*/
|
|
8
|
-
export function sortContainerQueries(theme, css) {
|
|
9
|
-
if (!theme.containerQueries) {
|
|
10
|
-
return css;
|
|
11
|
-
}
|
|
12
|
-
const sorted = Object.keys(css).filter(key => key.startsWith('@container')).sort((a, b) => {
|
|
13
|
-
const regex = /min-width:\s*([0-9.]+)/;
|
|
14
|
-
return +(a.match(regex)?.[1] || 0) - +(b.match(regex)?.[1] || 0);
|
|
15
|
-
});
|
|
16
|
-
if (!sorted.length) {
|
|
17
|
-
return css;
|
|
18
|
-
}
|
|
19
|
-
return sorted.reduce((acc, key) => {
|
|
20
|
-
const value = css[key];
|
|
21
|
-
delete acc[key];
|
|
22
|
-
acc[key] = value;
|
|
23
|
-
return acc;
|
|
24
|
-
}, {
|
|
25
|
-
...css
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
export function isCqShorthand(breakpointKeys, value) {
|
|
29
|
-
return value === '@' || value.startsWith('@') && (breakpointKeys.some(key => value.startsWith(`@${key}`)) || !!value.match(/^@\d/));
|
|
30
|
-
}
|
|
31
|
-
export function getContainerQuery(theme, shorthand) {
|
|
32
|
-
const matches = shorthand.match(/^@([^/]+)?\/?(.+)?$/);
|
|
33
|
-
if (!matches) {
|
|
34
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
35
|
-
throw new Error(process.env.NODE_ENV !== "production" ? `MUI: The provided shorthand ${`(${shorthand})`} is invalid. The format should be \`@<breakpoint | number>\` or \`@<breakpoint | number>/<container>\`.\n` + 'For example, `@sm` or `@600` or `@40rem/sidebar`.' : _formatErrorMessage(18, `(${shorthand})`));
|
|
36
|
-
}
|
|
37
|
-
return null;
|
|
38
|
-
}
|
|
39
|
-
const [, containerQuery, containerName] = matches;
|
|
40
|
-
const value = Number.isNaN(+containerQuery) ? containerQuery || 0 : +containerQuery;
|
|
41
|
-
return theme.containerQueries(containerName).up(value);
|
|
42
|
-
}
|
|
43
|
-
export default function cssContainerQueries(themeInput) {
|
|
44
|
-
const toContainerQuery = (mediaQuery, name) => mediaQuery.replace('@media', name ? `@container ${name}` : '@container');
|
|
45
|
-
function attachCq(node, name) {
|
|
46
|
-
node.up = (...args) => toContainerQuery(themeInput.breakpoints.up(...args), name);
|
|
47
|
-
node.down = (...args) => toContainerQuery(themeInput.breakpoints.down(...args), name);
|
|
48
|
-
node.between = (...args) => toContainerQuery(themeInput.breakpoints.between(...args), name);
|
|
49
|
-
node.only = (...args) => toContainerQuery(themeInput.breakpoints.only(...args), name);
|
|
50
|
-
node.not = (...args) => {
|
|
51
|
-
const result = toContainerQuery(themeInput.breakpoints.not(...args), name);
|
|
52
|
-
if (result.includes('not all and')) {
|
|
53
|
-
// `@container` does not work with `not all and`, so need to invert the logic
|
|
54
|
-
return result.replace('not all and ', '').replace('min-width:', 'width<').replace('max-width:', 'width>').replace('and', 'or');
|
|
55
|
-
}
|
|
56
|
-
return result;
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
const node = {};
|
|
60
|
-
const containerQueries = name => {
|
|
61
|
-
attachCq(node, name);
|
|
62
|
-
return node;
|
|
63
|
-
};
|
|
64
|
-
attachCq(containerQueries);
|
|
65
|
-
return {
|
|
66
|
-
...themeInput,
|
|
67
|
-
containerQueries
|
|
68
|
-
};
|
|
69
|
-
}
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import style from "../style/index.js";
|
|
2
|
-
import compose from "../compose/index.js";
|
|
3
|
-
import { createUnaryUnit, getValue } from "../spacing/index.js";
|
|
4
|
-
import { handleBreakpoints } from "../breakpoints/index.js";
|
|
5
|
-
import responsivePropType from "../responsivePropType/index.js";
|
|
6
|
-
|
|
7
|
-
// false positive
|
|
8
|
-
// eslint-disable-next-line react/function-component-definition
|
|
9
|
-
export const gap = props => {
|
|
10
|
-
if (props.gap !== undefined && props.gap !== null) {
|
|
11
|
-
const transformer = createUnaryUnit(props.theme, 'spacing', 8, 'gap');
|
|
12
|
-
const styleFromPropValue = propValue => ({
|
|
13
|
-
gap: getValue(transformer, propValue)
|
|
14
|
-
});
|
|
15
|
-
return handleBreakpoints(props, props.gap, styleFromPropValue);
|
|
16
|
-
}
|
|
17
|
-
return null;
|
|
18
|
-
};
|
|
19
|
-
gap.propTypes = process.env.NODE_ENV !== 'production' ? {
|
|
20
|
-
gap: responsivePropType
|
|
21
|
-
} : {};
|
|
22
|
-
gap.filterProps = ['gap'];
|
|
23
|
-
|
|
24
|
-
// false positive
|
|
25
|
-
// eslint-disable-next-line react/function-component-definition
|
|
26
|
-
export const columnGap = props => {
|
|
27
|
-
if (props.columnGap !== undefined && props.columnGap !== null) {
|
|
28
|
-
const transformer = createUnaryUnit(props.theme, 'spacing', 8, 'columnGap');
|
|
29
|
-
const styleFromPropValue = propValue => ({
|
|
30
|
-
columnGap: getValue(transformer, propValue)
|
|
31
|
-
});
|
|
32
|
-
return handleBreakpoints(props, props.columnGap, styleFromPropValue);
|
|
33
|
-
}
|
|
34
|
-
return null;
|
|
35
|
-
};
|
|
36
|
-
columnGap.propTypes = process.env.NODE_ENV !== 'production' ? {
|
|
37
|
-
columnGap: responsivePropType
|
|
38
|
-
} : {};
|
|
39
|
-
columnGap.filterProps = ['columnGap'];
|
|
40
|
-
|
|
41
|
-
// false positive
|
|
42
|
-
// eslint-disable-next-line react/function-component-definition
|
|
43
|
-
export const rowGap = props => {
|
|
44
|
-
if (props.rowGap !== undefined && props.rowGap !== null) {
|
|
45
|
-
const transformer = createUnaryUnit(props.theme, 'spacing', 8, 'rowGap');
|
|
46
|
-
const styleFromPropValue = propValue => ({
|
|
47
|
-
rowGap: getValue(transformer, propValue)
|
|
48
|
-
});
|
|
49
|
-
return handleBreakpoints(props, props.rowGap, styleFromPropValue);
|
|
50
|
-
}
|
|
51
|
-
return null;
|
|
52
|
-
};
|
|
53
|
-
rowGap.propTypes = process.env.NODE_ENV !== 'production' ? {
|
|
54
|
-
rowGap: responsivePropType
|
|
55
|
-
} : {};
|
|
56
|
-
rowGap.filterProps = ['rowGap'];
|
|
57
|
-
export const gridColumn = style({
|
|
58
|
-
prop: 'gridColumn'
|
|
59
|
-
});
|
|
60
|
-
export const gridRow = style({
|
|
61
|
-
prop: 'gridRow'
|
|
62
|
-
});
|
|
63
|
-
export const gridAutoFlow = style({
|
|
64
|
-
prop: 'gridAutoFlow'
|
|
65
|
-
});
|
|
66
|
-
export const gridAutoColumns = style({
|
|
67
|
-
prop: 'gridAutoColumns'
|
|
68
|
-
});
|
|
69
|
-
export const gridAutoRows = style({
|
|
70
|
-
prop: 'gridAutoRows'
|
|
71
|
-
});
|
|
72
|
-
export const gridTemplateColumns = style({
|
|
73
|
-
prop: 'gridTemplateColumns'
|
|
74
|
-
});
|
|
75
|
-
export const gridTemplateRows = style({
|
|
76
|
-
prop: 'gridTemplateRows'
|
|
77
|
-
});
|
|
78
|
-
export const gridTemplateAreas = style({
|
|
79
|
-
prop: 'gridTemplateAreas'
|
|
80
|
-
});
|
|
81
|
-
export const gridArea = style({
|
|
82
|
-
prop: 'gridArea'
|
|
83
|
-
});
|
|
84
|
-
const grid = compose(gap, columnGap, rowGap, gridColumn, gridRow, gridAutoFlow, gridAutoColumns, gridAutoRows, gridTemplateColumns, gridTemplateRows, gridTemplateAreas, gridArea);
|
|
85
|
-
export default grid;
|
package/modern/cssGrid/index.js
DELETED