@mui/system 5.8.5 → 5.9.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 +190 -0
- package/Unstable_Grid/Grid.d.ts +12 -0
- package/Unstable_Grid/Grid.js +190 -0
- package/Unstable_Grid/GridProps.d.ts +158 -0
- package/Unstable_Grid/GridProps.js +5 -0
- package/Unstable_Grid/createGrid.d.ts +11 -0
- package/Unstable_Grid/createGrid.js +174 -0
- package/Unstable_Grid/gridClasses.d.ts +20 -0
- package/Unstable_Grid/gridClasses.js +25 -0
- package/Unstable_Grid/gridGenerator.d.ts +26 -0
- package/Unstable_Grid/gridGenerator.js +269 -0
- package/Unstable_Grid/index.d.ts +5 -0
- package/Unstable_Grid/index.js +65 -0
- package/Unstable_Grid/package.json +6 -0
- package/{grid.js → cssGrid.js} +0 -0
- package/cssVars/createCssVarsProvider.d.ts +13 -18
- package/cssVars/createCssVarsProvider.js +13 -17
- package/cssVars/createGetCssVar.d.ts +1 -1
- package/cssVars/createGetCssVar.js +2 -2
- package/cssVars/cssVarsParser.d.ts +4 -9
- package/cssVars/cssVarsParser.js +4 -19
- package/cssVars/getInitColorSchemeScript.d.ts +5 -0
- package/cssVars/getInitColorSchemeScript.js +7 -0
- package/cssVars/index.d.ts +2 -1
- package/cssVars/index.js +9 -1
- package/cssVars/useCurrentColorScheme.js +1 -1
- package/esm/Unstable_Grid/Grid.js +179 -0
- package/esm/Unstable_Grid/GridProps.js +1 -0
- package/esm/Unstable_Grid/createGrid.js +152 -0
- package/esm/Unstable_Grid/gridClasses.js +14 -0
- package/esm/Unstable_Grid/gridGenerator.js +230 -0
- package/esm/Unstable_Grid/index.js +5 -0
- package/esm/{grid.js → cssGrid.js} +0 -0
- package/esm/cssVars/createCssVarsProvider.js +13 -16
- package/esm/cssVars/createGetCssVar.js +2 -2
- package/esm/cssVars/cssVarsParser.js +4 -19
- package/esm/cssVars/getInitColorSchemeScript.js +7 -0
- package/esm/cssVars/index.js +2 -1
- package/esm/cssVars/useCurrentColorScheme.js +1 -1
- package/esm/getThemeValue.js +1 -1
- package/esm/index.js +9 -3
- package/getThemeValue.js +3 -3
- package/index.d.ts +3 -0
- package/index.js +30 -7
- package/legacy/Unstable_Grid/Grid.js +179 -0
- package/legacy/Unstable_Grid/GridProps.js +1 -0
- package/legacy/Unstable_Grid/createGrid.js +166 -0
- package/legacy/Unstable_Grid/gridClasses.js +27 -0
- package/legacy/Unstable_Grid/gridGenerator.js +239 -0
- package/legacy/Unstable_Grid/index.js +5 -0
- package/legacy/{grid.js → cssGrid.js} +0 -0
- package/legacy/cssVars/createCssVarsProvider.js +13 -17
- package/legacy/cssVars/createGetCssVar.js +3 -3
- package/legacy/cssVars/cssVarsParser.js +4 -20
- package/legacy/cssVars/getInitColorSchemeScript.js +3 -1
- package/legacy/cssVars/index.js +2 -1
- package/legacy/cssVars/useCurrentColorScheme.js +1 -1
- package/legacy/getThemeValue.js +1 -1
- package/legacy/index.js +10 -4
- package/modern/Unstable_Grid/Grid.js +179 -0
- package/modern/Unstable_Grid/GridProps.js +1 -0
- package/modern/Unstable_Grid/createGrid.js +150 -0
- package/modern/Unstable_Grid/gridClasses.js +14 -0
- package/modern/Unstable_Grid/gridGenerator.js +226 -0
- package/modern/Unstable_Grid/index.js +5 -0
- package/modern/{grid.js → cssGrid.js} +0 -0
- package/modern/cssVars/createCssVarsProvider.js +13 -16
- package/modern/cssVars/createGetCssVar.js +2 -2
- package/modern/cssVars/cssVarsParser.js +4 -19
- package/modern/cssVars/getInitColorSchemeScript.js +7 -0
- package/modern/cssVars/index.js +2 -1
- package/modern/cssVars/useCurrentColorScheme.js +1 -1
- package/modern/getThemeValue.js +1 -1
- package/modern/index.js +10 -4
- package/package.json +5 -5
|
@@ -28,11 +28,9 @@ var _getInitColorSchemeScript = _interopRequireWildcard(require("./getInitColorS
|
|
|
28
28
|
|
|
29
29
|
var _useCurrentColorScheme = _interopRequireDefault(require("./useCurrentColorScheme"));
|
|
30
30
|
|
|
31
|
-
var _createGetCssVar = _interopRequireDefault(require("./createGetCssVar"));
|
|
32
|
-
|
|
33
31
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
34
32
|
|
|
35
|
-
const _excluded = ["colorSchemes", "components"];
|
|
33
|
+
const _excluded = ["colorSchemes", "components", "cssVarPrefix"];
|
|
36
34
|
|
|
37
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); }
|
|
38
36
|
|
|
@@ -51,8 +49,7 @@ function createCssVarsProvider(options) {
|
|
|
51
49
|
defaultColorScheme: designSystemColorScheme,
|
|
52
50
|
disableTransitionOnChange: designSystemTransitionOnChange = false,
|
|
53
51
|
enableColorScheme: designSystemEnableColorScheme = true,
|
|
54
|
-
|
|
55
|
-
shouldSkipGeneratingVar,
|
|
52
|
+
shouldSkipGeneratingVar: designSystemShouldSkipGeneratingVar,
|
|
56
53
|
resolveTheme
|
|
57
54
|
} = options;
|
|
58
55
|
|
|
@@ -75,7 +72,6 @@ function createCssVarsProvider(options) {
|
|
|
75
72
|
function CssVarsProvider({
|
|
76
73
|
children,
|
|
77
74
|
theme: themeProp = defaultTheme,
|
|
78
|
-
prefix = designSystemPrefix,
|
|
79
75
|
modeStorageKey = defaultModeStorageKey,
|
|
80
76
|
colorSchemeStorageKey = defaultColorSchemeStorageKey,
|
|
81
77
|
attribute = defaultAttribute,
|
|
@@ -86,12 +82,14 @@ function createCssVarsProvider(options) {
|
|
|
86
82
|
storageWindow = typeof window === 'undefined' ? undefined : window,
|
|
87
83
|
documentNode = typeof document === 'undefined' ? undefined : document,
|
|
88
84
|
colorSchemeNode = typeof document === 'undefined' ? undefined : document.documentElement,
|
|
89
|
-
colorSchemeSelector = ':root'
|
|
85
|
+
colorSchemeSelector = ':root',
|
|
86
|
+
shouldSkipGeneratingVar = designSystemShouldSkipGeneratingVar
|
|
90
87
|
}) {
|
|
91
88
|
const hasMounted = React.useRef(false);
|
|
92
89
|
const {
|
|
93
90
|
colorSchemes = {},
|
|
94
|
-
components = {}
|
|
91
|
+
components = {},
|
|
92
|
+
cssVarPrefix
|
|
95
93
|
} = themeProp,
|
|
96
94
|
restThemeProp = (0, _objectWithoutPropertiesLoose2.default)(themeProp, _excluded);
|
|
97
95
|
const allColorSchemes = Object.keys(colorSchemes);
|
|
@@ -135,16 +133,14 @@ function createCssVarsProvider(options) {
|
|
|
135
133
|
vars: rootVars,
|
|
136
134
|
parsedTheme
|
|
137
135
|
} = (0, _cssVarsParser.default)(theme, {
|
|
138
|
-
prefix,
|
|
139
|
-
basePrefix: designSystemPrefix,
|
|
136
|
+
prefix: cssVarPrefix,
|
|
140
137
|
shouldSkipGeneratingVar
|
|
141
138
|
});
|
|
142
139
|
theme = (0, _extends2.default)({}, parsedTheme, {
|
|
143
140
|
components,
|
|
144
141
|
colorSchemes,
|
|
145
|
-
|
|
142
|
+
cssVarPrefix,
|
|
146
143
|
vars: rootVars,
|
|
147
|
-
getCssVar: (0, _createGetCssVar.default)(prefix),
|
|
148
144
|
getColorSchemeSelector: targetColorScheme => `[${attribute}="${targetColorScheme}"] &`
|
|
149
145
|
});
|
|
150
146
|
const defaultColorSchemeStyleSheet = {};
|
|
@@ -155,8 +151,7 @@ function createCssVarsProvider(options) {
|
|
|
155
151
|
vars,
|
|
156
152
|
parsedTheme: parsedScheme
|
|
157
153
|
} = (0, _cssVarsParser.default)(scheme, {
|
|
158
|
-
prefix,
|
|
159
|
-
basePrefix: designSystemPrefix,
|
|
154
|
+
prefix: cssVarPrefix,
|
|
160
155
|
shouldSkipGeneratingVar
|
|
161
156
|
});
|
|
162
157
|
theme.vars = (0, _utils.deepmerge)(theme.vars, vars);
|
|
@@ -320,9 +315,9 @@ function createCssVarsProvider(options) {
|
|
|
320
315
|
modeStorageKey: _propTypes.default.string,
|
|
321
316
|
|
|
322
317
|
/**
|
|
323
|
-
* CSS
|
|
318
|
+
* A function to determine if the key, value should be attached as CSS Variable
|
|
324
319
|
*/
|
|
325
|
-
|
|
320
|
+
shouldSkipGeneratingVar: _propTypes.default.func,
|
|
326
321
|
|
|
327
322
|
/**
|
|
328
323
|
* The window that attaches the 'storage' event listener
|
|
@@ -339,7 +334,8 @@ function createCssVarsProvider(options) {
|
|
|
339
334
|
const getInitColorSchemeScript = params => (0, _getInitColorSchemeScript.default)((0, _extends2.default)({
|
|
340
335
|
attribute: defaultAttribute,
|
|
341
336
|
colorSchemeStorageKey: defaultColorSchemeStorageKey,
|
|
342
|
-
modeStorageKey: defaultModeStorageKey
|
|
337
|
+
modeStorageKey: defaultModeStorageKey,
|
|
338
|
+
enableColorScheme: designSystemEnableColorScheme
|
|
343
339
|
}, params));
|
|
344
340
|
|
|
345
341
|
return {
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
* The benefit of this function is to help developers get CSS var from theme without specifying the whole variable
|
|
3
3
|
* and they does not need to remember the prefix (defined once).
|
|
4
4
|
*/
|
|
5
|
-
export default function createGetCssVar<T extends string = string>(prefix?: string): <AdditionalVars extends string = never>(field: T | AdditionalVars, ...
|
|
5
|
+
export default function createGetCssVar<T extends string = string>(prefix?: string): <AdditionalVars extends string = never>(field: T | AdditionalVars, ...fallbacks: (T | AdditionalVars)[]) => string;
|
|
@@ -25,8 +25,8 @@ function createGetCssVar(prefix = '') {
|
|
|
25
25
|
} // AdditionalVars makes `getCssVar` less strict, so it can be use like this `getCssVar('non-mui-variable')` without type error.
|
|
26
26
|
|
|
27
27
|
|
|
28
|
-
const getCssVar = (field, ...
|
|
29
|
-
return `var(--${prefix ? `${prefix}-` : ''}${field}${appendVar(...
|
|
28
|
+
const getCssVar = (field, ...fallbacks) => {
|
|
29
|
+
return `var(--${prefix ? `${prefix}-` : ''}${field}${appendVar(...fallbacks)})`;
|
|
30
30
|
};
|
|
31
31
|
|
|
32
32
|
return getCssVar;
|
|
@@ -37,13 +37,9 @@ export declare const walkObjectDeep: <Value, T = Record<string, any>>(obj: T, ca
|
|
|
37
37
|
* @param {Object} theme
|
|
38
38
|
* @param {{
|
|
39
39
|
* prefix?: string,
|
|
40
|
-
* basePrefix?: string,
|
|
41
40
|
* shouldSkipGeneratingVar?: (objectPathKeys: Array<string>, value: string | number) => boolean
|
|
42
41
|
* }} options.
|
|
43
|
-
* `
|
|
44
|
-
* `prefix`: defined by application
|
|
45
|
-
*
|
|
46
|
-
* the CSS variable value will be adjusted based on the provided `basePrefix` & `prefix` which can be found in `parsedTheme`.
|
|
42
|
+
* `prefix`: The prefix of the generated CSS variables. This function does not change the value.
|
|
47
43
|
*
|
|
48
44
|
* @returns {{ css: Object, vars: Object, parsedTheme: typeof theme }} `css` is the stylesheet, `vars` is an object to get css variable (same structure as theme), and `parsedTheme` is the cloned version of theme.
|
|
49
45
|
*
|
|
@@ -54,13 +50,12 @@ export declare const walkObjectDeep: <Value, T = Record<string, any>>(obj: T, ca
|
|
|
54
50
|
* palette: { primary: { 500: 'var(--color)' } }
|
|
55
51
|
* }, { prefix: 'foo' })
|
|
56
52
|
*
|
|
57
|
-
* console.log(css) // { '--foo-fontSize': '12px', '--foo-lineHeight': 1.2, '--foo-palette-primary-500': 'var(--
|
|
58
|
-
* console.log(vars) // { fontSize: '--foo-fontSize', lineHeight: '--foo-lineHeight', palette: { primary: { 500: 'var(--foo-palette-primary-500)' } } }
|
|
59
|
-
* console.log(parsedTheme) // { fontSize: 12, lineHeight: 1.2, palette: { primary: { 500: 'var(--
|
|
53
|
+
* console.log(css) // { '--foo-fontSize': '12px', '--foo-lineHeight': 1.2, '--foo-palette-primary-500': 'var(--color)' }
|
|
54
|
+
* console.log(vars) // { fontSize: 'var(--foo-fontSize)', lineHeight: 'var(--foo-lineHeight)', palette: { primary: { 500: 'var(--foo-palette-primary-500)' } } }
|
|
55
|
+
* console.log(parsedTheme) // { fontSize: 12, lineHeight: 1.2, palette: { primary: { 500: 'var(--color)' } } }
|
|
60
56
|
*/
|
|
61
57
|
export default function cssVarsParser<T extends Record<string, any>>(theme: T, options?: {
|
|
62
58
|
prefix?: string;
|
|
63
|
-
basePrefix?: string;
|
|
64
59
|
shouldSkipGeneratingVar?: (objectPathKeys: Array<string>, value: string | number) => boolean;
|
|
65
60
|
}): {
|
|
66
61
|
css: NestedRecord<string>;
|
package/cssVars/cssVarsParser.js
CHANGED
|
@@ -102,13 +102,9 @@ const getCssValue = (keys, value) => {
|
|
|
102
102
|
* @param {Object} theme
|
|
103
103
|
* @param {{
|
|
104
104
|
* prefix?: string,
|
|
105
|
-
* basePrefix?: string,
|
|
106
105
|
* shouldSkipGeneratingVar?: (objectPathKeys: Array<string>, value: string | number) => boolean
|
|
107
106
|
* }} options.
|
|
108
|
-
* `
|
|
109
|
-
* `prefix`: defined by application
|
|
110
|
-
*
|
|
111
|
-
* the CSS variable value will be adjusted based on the provided `basePrefix` & `prefix` which can be found in `parsedTheme`.
|
|
107
|
+
* `prefix`: The prefix of the generated CSS variables. This function does not change the value.
|
|
112
108
|
*
|
|
113
109
|
* @returns {{ css: Object, vars: Object, parsedTheme: typeof theme }} `css` is the stylesheet, `vars` is an object to get css variable (same structure as theme), and `parsedTheme` is the cloned version of theme.
|
|
114
110
|
*
|
|
@@ -119,16 +115,15 @@ const getCssValue = (keys, value) => {
|
|
|
119
115
|
* palette: { primary: { 500: 'var(--color)' } }
|
|
120
116
|
* }, { prefix: 'foo' })
|
|
121
117
|
*
|
|
122
|
-
* console.log(css) // { '--foo-fontSize': '12px', '--foo-lineHeight': 1.2, '--foo-palette-primary-500': 'var(--
|
|
123
|
-
* console.log(vars) // { fontSize: '--foo-fontSize', lineHeight: '--foo-lineHeight', palette: { primary: { 500: 'var(--foo-palette-primary-500)' } } }
|
|
124
|
-
* console.log(parsedTheme) // { fontSize: 12, lineHeight: 1.2, palette: { primary: { 500: 'var(--
|
|
118
|
+
* console.log(css) // { '--foo-fontSize': '12px', '--foo-lineHeight': 1.2, '--foo-palette-primary-500': 'var(--color)' }
|
|
119
|
+
* console.log(vars) // { fontSize: 'var(--foo-fontSize)', lineHeight: 'var(--foo-lineHeight)', palette: { primary: { 500: 'var(--foo-palette-primary-500)' } } }
|
|
120
|
+
* console.log(parsedTheme) // { fontSize: 12, lineHeight: 1.2, palette: { primary: { 500: 'var(--color)' } } }
|
|
125
121
|
*/
|
|
126
122
|
|
|
127
123
|
|
|
128
124
|
function cssVarsParser(theme, options) {
|
|
129
125
|
const {
|
|
130
126
|
prefix,
|
|
131
|
-
basePrefix = '',
|
|
132
127
|
shouldSkipGeneratingVar
|
|
133
128
|
} = options || {};
|
|
134
129
|
const css = {};
|
|
@@ -136,16 +131,6 @@ function cssVarsParser(theme, options) {
|
|
|
136
131
|
const parsedTheme = {};
|
|
137
132
|
walkObjectDeep(theme, (keys, value, arrayKeys) => {
|
|
138
133
|
if (typeof value === 'string' || typeof value === 'number') {
|
|
139
|
-
if (typeof value === 'string' && value.match(/var\(\s*--/)) {
|
|
140
|
-
// for CSS variable, apply prefix or remove basePrefix from the variable
|
|
141
|
-
if (!basePrefix && prefix) {
|
|
142
|
-
value = value.replace(/var\(\s*--/g, `var(--${prefix}-`);
|
|
143
|
-
} else {
|
|
144
|
-
value = prefix ? value.replace(new RegExp(`var\\(\\s*--${basePrefix}`, 'g'), `var(--${prefix}`) // removing spaces
|
|
145
|
-
: value.replace(new RegExp(`var\\(\\s*--${basePrefix}-`, 'g'), 'var(--');
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
134
|
if (!shouldSkipGeneratingVar || shouldSkipGeneratingVar && !shouldSkipGeneratingVar(keys, value)) {
|
|
150
135
|
// only create css & var if `shouldSkipGeneratingVar` return false
|
|
151
136
|
const cssVar = `--${prefix ? `${prefix}-` : ''}${keys.join('-')}`;
|
|
@@ -3,6 +3,11 @@ export declare const DEFAULT_MODE_STORAGE_KEY = "mode";
|
|
|
3
3
|
export declare const DEFAULT_COLOR_SCHEME_STORAGE_KEY = "color-scheme";
|
|
4
4
|
export declare const DEFAULT_ATTRIBUTE = "data-color-scheme";
|
|
5
5
|
export interface GetInitColorSchemeScriptOptions {
|
|
6
|
+
/**
|
|
7
|
+
* Indicate to the browser which color scheme is used (light or dark) for rendering built-in UI
|
|
8
|
+
* @default true
|
|
9
|
+
*/
|
|
10
|
+
enableColorScheme?: boolean;
|
|
6
11
|
/**
|
|
7
12
|
* If `true`, the initial color scheme is set to the user's prefers-color-scheme mode
|
|
8
13
|
* @default false
|
|
@@ -23,6 +23,7 @@ exports.DEFAULT_ATTRIBUTE = DEFAULT_ATTRIBUTE;
|
|
|
23
23
|
|
|
24
24
|
function getInitColorSchemeScript(options) {
|
|
25
25
|
const {
|
|
26
|
+
enableColorScheme = true,
|
|
26
27
|
enableSystem = false,
|
|
27
28
|
defaultLightColorScheme = 'light',
|
|
28
29
|
defaultDarkColorScheme = 'dark',
|
|
@@ -36,13 +37,16 @@ function getInitColorSchemeScript(options) {
|
|
|
36
37
|
dangerouslySetInnerHTML: {
|
|
37
38
|
__html: `(function() { try {
|
|
38
39
|
var mode = localStorage.getItem('${modeStorageKey}');
|
|
40
|
+
var cssColorScheme = mode;
|
|
39
41
|
var colorScheme = '';
|
|
40
42
|
if (mode === 'system' || (!mode && !!${enableSystem})) {
|
|
41
43
|
// handle system mode
|
|
42
44
|
var mql = window.matchMedia('(prefers-color-scheme: dark)');
|
|
43
45
|
if (mql.matches) {
|
|
46
|
+
cssColorScheme = 'dark';
|
|
44
47
|
colorScheme = localStorage.getItem('${colorSchemeStorageKey}-dark') || '${defaultDarkColorScheme}';
|
|
45
48
|
} else {
|
|
49
|
+
cssColorScheme = 'light';
|
|
46
50
|
colorScheme = localStorage.getItem('${colorSchemeStorageKey}-light') || '${defaultLightColorScheme}';
|
|
47
51
|
}
|
|
48
52
|
}
|
|
@@ -55,6 +59,9 @@ function getInitColorSchemeScript(options) {
|
|
|
55
59
|
if (colorScheme) {
|
|
56
60
|
${colorSchemeNode}.setAttribute('${attribute}', colorScheme);
|
|
57
61
|
}
|
|
62
|
+
if (${enableColorScheme} && !!cssColorScheme) {
|
|
63
|
+
${colorSchemeNode}.style.setProperty('color-scheme', cssColorScheme);
|
|
64
|
+
}
|
|
58
65
|
} catch (e) {} })();`
|
|
59
66
|
}
|
|
60
67
|
});
|
package/cssVars/index.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
export { default } from './createCssVarsProvider';
|
|
2
|
-
export type { CreateCssVarsProviderResult } from './createCssVarsProvider';
|
|
2
|
+
export type { CreateCssVarsProviderResult, CssVarsProviderConfig, ColorSchemeContextValue, } from './createCssVarsProvider';
|
|
3
|
+
export { default as getInitColorSchemeScript } from './getInitColorSchemeScript';
|
package/cssVars/index.js
CHANGED
|
@@ -11,5 +11,13 @@ Object.defineProperty(exports, "default", {
|
|
|
11
11
|
return _createCssVarsProvider.default;
|
|
12
12
|
}
|
|
13
13
|
});
|
|
14
|
+
Object.defineProperty(exports, "getInitColorSchemeScript", {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: function () {
|
|
17
|
+
return _getInitColorSchemeScript.default;
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
var _createCssVarsProvider = _interopRequireDefault(require("./createCssVarsProvider"));
|
|
14
22
|
|
|
15
|
-
var
|
|
23
|
+
var _getInitColorSchemeScript = _interopRequireDefault(require("./getInitColorSchemeScript"));
|
|
@@ -171,7 +171,7 @@ function useCurrentColorScheme(options) {
|
|
|
171
171
|
const handleMediaQuery = React.useCallback(e => {
|
|
172
172
|
if (state.mode === 'system') {
|
|
173
173
|
setState(currentState => (0, _extends2.default)({}, currentState, {
|
|
174
|
-
systemMode: e.matches ? 'dark' : 'light'
|
|
174
|
+
systemMode: e != null && e.matches ? 'dark' : 'light'
|
|
175
175
|
}));
|
|
176
176
|
}
|
|
177
177
|
}, [state.mode]); // Ref hack to avoid adding handleMediaQuery as a dep
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import PropTypes from 'prop-types';
|
|
2
|
+
import createGrid from './createGrid';
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* Demos:
|
|
6
|
+
*
|
|
7
|
+
* - [Grid (Material UI)](https://mui.com/material-ui/react-grid/)
|
|
8
|
+
*
|
|
9
|
+
* API:
|
|
10
|
+
*
|
|
11
|
+
* - [Grid API](https://mui.com/system/api/grid/)
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const Grid = createGrid();
|
|
15
|
+
process.env.NODE_ENV !== "production" ? Grid.propTypes
|
|
16
|
+
/* remove-proptypes */
|
|
17
|
+
= {
|
|
18
|
+
// ----------------------------- Warning --------------------------------
|
|
19
|
+
// | These PropTypes are generated from the TypeScript type definitions |
|
|
20
|
+
// | To update them edit TypeScript types and run "yarn proptypes" |
|
|
21
|
+
// ----------------------------------------------------------------------
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The content of the component.
|
|
25
|
+
*/
|
|
26
|
+
children: PropTypes.node,
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The number of columns.
|
|
30
|
+
* @default 12
|
|
31
|
+
*/
|
|
32
|
+
columns: PropTypes
|
|
33
|
+
/* @typescript-to-proptypes-ignore */
|
|
34
|
+
.oneOfType([PropTypes.arrayOf(PropTypes.number), PropTypes.number, PropTypes.object]),
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Defines the horizontal space between the type `item` components.
|
|
38
|
+
* It overrides the value of the `spacing` prop.
|
|
39
|
+
*/
|
|
40
|
+
columnSpacing: PropTypes
|
|
41
|
+
/* @typescript-to-proptypes-ignore */
|
|
42
|
+
.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.number, PropTypes.string])), PropTypes.number, PropTypes.object, PropTypes.string]),
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* If `true`, the component will have the flex *container* behavior.
|
|
46
|
+
* You should be wrapping *items* with a *container*.
|
|
47
|
+
* @default false
|
|
48
|
+
*/
|
|
49
|
+
container: PropTypes.bool,
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Defines the `flex-direction` style property.
|
|
53
|
+
* It is applied for all screen sizes.
|
|
54
|
+
* @default 'row'
|
|
55
|
+
*/
|
|
56
|
+
direction: PropTypes
|
|
57
|
+
/* @typescript-to-proptypes-ignore */
|
|
58
|
+
.oneOfType([PropTypes.oneOf(['column-reverse', 'column', 'row-reverse', 'row']), PropTypes.arrayOf(PropTypes.oneOf(['column-reverse', 'column', 'row-reverse', 'row'])), PropTypes.object]),
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* If a number, it sets the number of columns the grid item uses.
|
|
62
|
+
* It can't be greater than the total number of columns of the container (12 by default).
|
|
63
|
+
* If 'auto', the grid item's width matches its content.
|
|
64
|
+
* If false, the prop is ignored.
|
|
65
|
+
* If true, the grid item's width grows to use the space available in the grid container.
|
|
66
|
+
* The value is applied for the `lg` breakpoint and wider screens if not overridden.
|
|
67
|
+
* @default false
|
|
68
|
+
*/
|
|
69
|
+
lg: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number, PropTypes.bool]),
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* If a number, it sets the margin-left equals to the number of columns the grid item uses.
|
|
73
|
+
* If 'auto', the grid item push itself to the right-end of the container.
|
|
74
|
+
* The value is applied for the `lg` breakpoint and wider screens if not overridden.
|
|
75
|
+
*/
|
|
76
|
+
lgOffset: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number]),
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* If a number, it sets the number of columns the grid item uses.
|
|
80
|
+
* It can't be greater than the total number of columns of the container (12 by default).
|
|
81
|
+
* If 'auto', the grid item's width matches its content.
|
|
82
|
+
* If false, the prop is ignored.
|
|
83
|
+
* If true, the grid item's width grows to use the space available in the grid container.
|
|
84
|
+
* The value is applied for the `md` breakpoint and wider screens if not overridden.
|
|
85
|
+
* @default false
|
|
86
|
+
*/
|
|
87
|
+
md: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number, PropTypes.bool]),
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* If a number, it sets the margin-left equals to the number of columns the grid item uses.
|
|
91
|
+
* If 'auto', the grid item push itself to the right-end of the container.
|
|
92
|
+
* The value is applied for the `md` breakpoint and wider screens if not overridden.
|
|
93
|
+
*/
|
|
94
|
+
mdOffset: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number]),
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Defines the vertical space between the type `item` components.
|
|
98
|
+
* It overrides the value of the `spacing` prop.
|
|
99
|
+
*/
|
|
100
|
+
rowSpacing: PropTypes
|
|
101
|
+
/* @typescript-to-proptypes-ignore */
|
|
102
|
+
.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.number, PropTypes.string])), PropTypes.number, PropTypes.object, PropTypes.string]),
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* If a number, it sets the number of columns the grid item uses.
|
|
106
|
+
* It can't be greater than the total number of columns of the container (12 by default).
|
|
107
|
+
* If 'auto', the grid item's width matches its content.
|
|
108
|
+
* If false, the prop is ignored.
|
|
109
|
+
* If true, the grid item's width grows to use the space available in the grid container.
|
|
110
|
+
* The value is applied for the `sm` breakpoint and wider screens if not overridden.
|
|
111
|
+
* @default false
|
|
112
|
+
*/
|
|
113
|
+
sm: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number, PropTypes.bool]),
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* If a number, it sets the margin-left equals to the number of columns the grid item uses.
|
|
117
|
+
* If 'auto', the grid item push itself to the right-end of the container.
|
|
118
|
+
* The value is applied for the `sm` breakpoint and wider screens if not overridden.
|
|
119
|
+
*/
|
|
120
|
+
smOffset: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number]),
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Defines the space between the type `item` components.
|
|
124
|
+
* It can only be used on a type `container` component.
|
|
125
|
+
* @default 0
|
|
126
|
+
*/
|
|
127
|
+
spacing: PropTypes
|
|
128
|
+
/* @typescript-to-proptypes-ignore */
|
|
129
|
+
.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.number, PropTypes.string])), PropTypes.number, PropTypes.object, PropTypes.string]),
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* @ignore
|
|
133
|
+
*/
|
|
134
|
+
sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Defines the `flex-wrap` style property.
|
|
138
|
+
* It's applied for all screen sizes.
|
|
139
|
+
* @default 'wrap'
|
|
140
|
+
*/
|
|
141
|
+
wrap: PropTypes.oneOf(['nowrap', 'wrap-reverse', 'wrap']),
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* If a number, it sets the number of columns the grid item uses.
|
|
145
|
+
* It can't be greater than the total number of columns of the container (12 by default).
|
|
146
|
+
* If 'auto', the grid item's width matches its content.
|
|
147
|
+
* If false, the prop is ignored.
|
|
148
|
+
* If true, the grid item's width grows to use the space available in the grid container.
|
|
149
|
+
* The value is applied for the `xl` breakpoint and wider screens if not overridden.
|
|
150
|
+
* @default false
|
|
151
|
+
*/
|
|
152
|
+
xl: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number, PropTypes.bool]),
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* If a number, it sets the margin-left equals to the number of columns the grid item uses.
|
|
156
|
+
* If 'auto', the grid item push itself to the right-end of the container.
|
|
157
|
+
* The value is applied for the `xl` breakpoint and wider screens if not overridden.
|
|
158
|
+
*/
|
|
159
|
+
xlOffset: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number]),
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* If a number, it sets the number of columns the grid item uses.
|
|
163
|
+
* It can't be greater than the total number of columns of the container (12 by default).
|
|
164
|
+
* If 'auto', the grid item's width matches its content.
|
|
165
|
+
* If false, the prop is ignored.
|
|
166
|
+
* If true, the grid item's width grows to use the space available in the grid container.
|
|
167
|
+
* The value is applied for all the screen sizes with the lowest priority.
|
|
168
|
+
* @default false
|
|
169
|
+
*/
|
|
170
|
+
xs: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number, PropTypes.bool]),
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* If a number, it sets the margin-left equals to the number of columns the grid item uses.
|
|
174
|
+
* If 'auto', the grid item push itself to the right-end of the container.
|
|
175
|
+
* The value is applied for the `xs` breakpoint and wider screens if not overridden.
|
|
176
|
+
*/
|
|
177
|
+
xsOffset: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number])
|
|
178
|
+
} : void 0;
|
|
179
|
+
export default Grid;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
|
+
const _excluded = ["className", "columns", "container", "component", "direction", "wrap", "spacing", "rowSpacing", "columnSpacing"];
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
import PropTypes from 'prop-types';
|
|
6
|
+
import clsx from 'clsx';
|
|
7
|
+
import { unstable_composeClasses as composeClasses, unstable_generateUtilityClass as generateUtilityClass } from '@mui/utils';
|
|
8
|
+
import systemStyled from '../styled';
|
|
9
|
+
import useThemePropsSystem from '../useThemeProps';
|
|
10
|
+
import useTheme from '../useTheme';
|
|
11
|
+
import { extendSxProp } from '../styleFunctionSx';
|
|
12
|
+
import createTheme from '../createTheme';
|
|
13
|
+
import { generateGridStyles, generateGridSizeStyles, generateGridColumnsStyles, generateGridColumnSpacingStyles, generateGridRowSpacingStyles, generateGridDirectionStyles, generateGridOffsetStyles, generateSizeClassNames, generateSpacingClassNames } from './gridGenerator';
|
|
14
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
15
|
+
const defaultTheme = createTheme(); // widening Theme to any so that the consumer can own the theme structure.
|
|
16
|
+
|
|
17
|
+
const defaultCreateStyledComponent = systemStyled('div', {
|
|
18
|
+
name: 'MuiGrid',
|
|
19
|
+
slot: 'Root',
|
|
20
|
+
overridesResolver: (props, styles) => styles.root
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
function useThemePropsDefault(props) {
|
|
24
|
+
return useThemePropsSystem({
|
|
25
|
+
props,
|
|
26
|
+
name: 'MuiGrid',
|
|
27
|
+
defaultTheme
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export default function createGrid(options = {}) {
|
|
32
|
+
const {
|
|
33
|
+
// This will allow adding custom styled fn (for example for custom sx style function)
|
|
34
|
+
createStyledComponent = defaultCreateStyledComponent,
|
|
35
|
+
useThemeProps = useThemePropsDefault,
|
|
36
|
+
componentName = 'MuiGrid'
|
|
37
|
+
} = options;
|
|
38
|
+
const NestedContext = /*#__PURE__*/React.createContext(false);
|
|
39
|
+
|
|
40
|
+
const useUtilityClasses = (ownerState, theme) => {
|
|
41
|
+
const {
|
|
42
|
+
container,
|
|
43
|
+
direction,
|
|
44
|
+
spacing,
|
|
45
|
+
wrap,
|
|
46
|
+
gridSize
|
|
47
|
+
} = ownerState;
|
|
48
|
+
const slots = {
|
|
49
|
+
root: ['root', container && 'container', direction !== 'row' && `direction-xs-${String(direction)}`, wrap !== 'wrap' && `wrap-xs-${String(wrap)}`, ...generateSizeClassNames(gridSize), ...(container ? generateSpacingClassNames(spacing, theme.breakpoints.keys[0]) : [])]
|
|
50
|
+
};
|
|
51
|
+
return composeClasses(slots, slot => generateUtilityClass(componentName, slot), {});
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const GridRoot = createStyledComponent(generateGridColumnsStyles, generateGridColumnSpacingStyles, generateGridRowSpacingStyles, generateGridSizeStyles, generateGridDirectionStyles, generateGridStyles, generateGridOffsetStyles);
|
|
55
|
+
const Grid = /*#__PURE__*/React.forwardRef(function Grid(inProps, ref) {
|
|
56
|
+
var _inProps$columns, _inProps$spacing, _ref, _inProps$rowSpacing, _ref2, _inProps$columnSpacin;
|
|
57
|
+
|
|
58
|
+
const theme = useTheme();
|
|
59
|
+
const themeProps = useThemeProps(inProps);
|
|
60
|
+
const props = extendSxProp(themeProps); // `color` type conflicts with html color attribute.
|
|
61
|
+
|
|
62
|
+
const nested = React.useContext(NestedContext);
|
|
63
|
+
|
|
64
|
+
const {
|
|
65
|
+
className,
|
|
66
|
+
columns: columnsProp = 12,
|
|
67
|
+
container = false,
|
|
68
|
+
component = 'div',
|
|
69
|
+
direction = 'row',
|
|
70
|
+
wrap = 'wrap',
|
|
71
|
+
spacing: spacingProp = 0,
|
|
72
|
+
rowSpacing: rowSpacingProp = spacingProp,
|
|
73
|
+
columnSpacing: columnSpacingProp = spacingProp
|
|
74
|
+
} = props,
|
|
75
|
+
rest = _objectWithoutPropertiesLoose(props, _excluded); // collect breakpoints related props because they can be custom from the theme.
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
const gridSize = {};
|
|
79
|
+
const gridOffset = {};
|
|
80
|
+
const other = {};
|
|
81
|
+
Object.entries(rest).forEach(([key, val]) => {
|
|
82
|
+
if (theme.breakpoints.values[key] !== undefined) {
|
|
83
|
+
gridSize[key] = val;
|
|
84
|
+
} else if (theme.breakpoints.values[key.replace('Offset', '')] !== undefined) {
|
|
85
|
+
gridOffset[key.replace('Offset', '')] = val;
|
|
86
|
+
} else {
|
|
87
|
+
other[key] = val;
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
const columns = (_inProps$columns = inProps.columns) != null ? _inProps$columns : nested ? undefined : columnsProp;
|
|
91
|
+
const spacing = (_inProps$spacing = inProps.spacing) != null ? _inProps$spacing : nested ? undefined : spacingProp;
|
|
92
|
+
const rowSpacing = (_ref = (_inProps$rowSpacing = inProps.rowSpacing) != null ? _inProps$rowSpacing : inProps.spacing) != null ? _ref : nested ? undefined : rowSpacingProp;
|
|
93
|
+
const columnSpacing = (_ref2 = (_inProps$columnSpacin = inProps.columnSpacing) != null ? _inProps$columnSpacin : inProps.spacing) != null ? _ref2 : nested ? undefined : columnSpacingProp;
|
|
94
|
+
|
|
95
|
+
const ownerState = _extends({}, props, {
|
|
96
|
+
nested,
|
|
97
|
+
columns,
|
|
98
|
+
container,
|
|
99
|
+
direction,
|
|
100
|
+
wrap,
|
|
101
|
+
spacing,
|
|
102
|
+
rowSpacing,
|
|
103
|
+
columnSpacing,
|
|
104
|
+
gridSize,
|
|
105
|
+
gridOffset
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
const classes = useUtilityClasses(ownerState, theme);
|
|
109
|
+
|
|
110
|
+
let result = /*#__PURE__*/_jsx(GridRoot, _extends({
|
|
111
|
+
ref: ref,
|
|
112
|
+
as: component,
|
|
113
|
+
ownerState: ownerState,
|
|
114
|
+
className: clsx(classes.root, className)
|
|
115
|
+
}, other));
|
|
116
|
+
|
|
117
|
+
if (!nested) {
|
|
118
|
+
result = /*#__PURE__*/_jsx(NestedContext.Provider, {
|
|
119
|
+
value: true,
|
|
120
|
+
children: result
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return result;
|
|
125
|
+
});
|
|
126
|
+
process.env.NODE_ENV !== "production" ? Grid.propTypes
|
|
127
|
+
/* remove-proptypes */
|
|
128
|
+
= {
|
|
129
|
+
children: PropTypes.node,
|
|
130
|
+
className: PropTypes.string,
|
|
131
|
+
columns: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.number), PropTypes.number, PropTypes.object]),
|
|
132
|
+
columnSpacing: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.number, PropTypes.string])), PropTypes.number, PropTypes.object, PropTypes.string]),
|
|
133
|
+
component: PropTypes.elementType,
|
|
134
|
+
container: PropTypes.bool,
|
|
135
|
+
direction: PropTypes.oneOfType([PropTypes.oneOf(['column-reverse', 'column', 'row-reverse', 'row']), PropTypes.arrayOf(PropTypes.oneOf(['column-reverse', 'column', 'row-reverse', 'row'])), PropTypes.object]),
|
|
136
|
+
lg: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number, PropTypes.bool]),
|
|
137
|
+
lgOffset: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number]),
|
|
138
|
+
md: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number, PropTypes.bool]),
|
|
139
|
+
mdOffset: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number]),
|
|
140
|
+
rowSpacing: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.number, PropTypes.string])), PropTypes.number, PropTypes.object, PropTypes.string]),
|
|
141
|
+
sm: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number, PropTypes.bool]),
|
|
142
|
+
smOffset: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number]),
|
|
143
|
+
spacing: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.number, PropTypes.string])), PropTypes.number, PropTypes.object, PropTypes.string]),
|
|
144
|
+
sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
|
|
145
|
+
wrap: PropTypes.oneOf(['nowrap', 'wrap-reverse', 'wrap']),
|
|
146
|
+
xl: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number, PropTypes.bool]),
|
|
147
|
+
xlOffset: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number]),
|
|
148
|
+
xs: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number, PropTypes.bool]),
|
|
149
|
+
xsOffset: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number])
|
|
150
|
+
} : void 0;
|
|
151
|
+
return Grid;
|
|
152
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { unstable_generateUtilityClass as generateUtilityClass, unstable_generateUtilityClasses as generateUtilityClasses } from '@mui/utils';
|
|
2
|
+
export function getGridUtilityClass(slot) {
|
|
3
|
+
return generateUtilityClass('MuiGrid', slot);
|
|
4
|
+
}
|
|
5
|
+
const SPACINGS = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
|
6
|
+
const DIRECTIONS = ['column-reverse', 'column', 'row-reverse', 'row'];
|
|
7
|
+
const WRAPS = ['nowrap', 'wrap-reverse', 'wrap'];
|
|
8
|
+
const GRID_SIZES = ['auto', true, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
|
|
9
|
+
const gridClasses = generateUtilityClasses('MuiGrid', ['root', 'container', 'item', // spacings
|
|
10
|
+
...SPACINGS.map(spacing => `spacing-xs-${spacing}`), // direction values
|
|
11
|
+
...DIRECTIONS.map(direction => `direction-xs-${direction}`), // wrap values
|
|
12
|
+
...WRAPS.map(wrap => `wrap-xs-${wrap}`), // grid sizes for all breakpoints
|
|
13
|
+
...GRID_SIZES.map(size => `grid-xs-${size}`), ...GRID_SIZES.map(size => `grid-sm-${size}`), ...GRID_SIZES.map(size => `grid-md-${size}`), ...GRID_SIZES.map(size => `grid-lg-${size}`), ...GRID_SIZES.map(size => `grid-xl-${size}`)]);
|
|
14
|
+
export default gridClasses;
|