@mui/system 5.8.7 → 5.9.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 +200 -4
- package/Unstable_Grid/Grid.d.ts +12 -0
- package/Unstable_Grid/Grid.js +195 -0
- package/Unstable_Grid/GridProps.d.ts +162 -0
- package/Unstable_Grid/GridProps.js +5 -0
- package/Unstable_Grid/createGrid.d.ts +11 -0
- package/Unstable_Grid/createGrid.js +199 -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 +275 -0
- package/Unstable_Grid/index.d.ts +5 -0
- package/Unstable_Grid/index.js +65 -0
- package/Unstable_Grid/package.json +6 -0
- package/breakpoints.js +1 -1
- package/{grid.js → cssGrid.js} +0 -0
- package/cssVars/useCurrentColorScheme.js +1 -1
- package/esm/Unstable_Grid/Grid.js +184 -0
- package/esm/Unstable_Grid/GridProps.js +1 -0
- package/esm/Unstable_Grid/createGrid.js +177 -0
- package/esm/Unstable_Grid/gridClasses.js +14 -0
- package/esm/Unstable_Grid/gridGenerator.js +236 -0
- package/esm/Unstable_Grid/index.js +5 -0
- package/esm/breakpoints.js +1 -1
- package/esm/{grid.js → cssGrid.js} +0 -0
- 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 +184 -0
- package/legacy/Unstable_Grid/GridProps.js +1 -0
- package/legacy/Unstable_Grid/createGrid.js +191 -0
- package/legacy/Unstable_Grid/gridClasses.js +27 -0
- package/legacy/Unstable_Grid/gridGenerator.js +245 -0
- package/legacy/Unstable_Grid/index.js +5 -0
- package/legacy/breakpoints.js +1 -1
- package/legacy/{grid.js → cssGrid.js} +0 -0
- 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 +184 -0
- package/modern/Unstable_Grid/GridProps.js +1 -0
- package/modern/Unstable_Grid/createGrid.js +175 -0
- package/modern/Unstable_Grid/gridClasses.js +14 -0
- package/modern/Unstable_Grid/gridGenerator.js +232 -0
- package/modern/Unstable_Grid/index.js +5 -0
- package/modern/breakpoints.js +1 -1
- package/modern/{grid.js → cssGrid.js} +0 -0
- package/modern/cssVars/useCurrentColorScheme.js +1 -1
- package/modern/getThemeValue.js +1 -1
- package/modern/index.js +10 -4
- package/package.json +5 -5
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
+
import _typeof from "@babel/runtime/helpers/esm/typeof";
|
|
3
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
4
|
+
export var traverseBreakpoints = function traverseBreakpoints(breakpoints, responsize, iterator) {
|
|
5
|
+
var smallestBreakpoint = breakpoints.keys[0]; // the keys is sorted from smallest to largest by `createBreakpoints`.
|
|
6
|
+
|
|
7
|
+
if (Array.isArray(responsize)) {
|
|
8
|
+
responsize.forEach(function (breakpointValue, index) {
|
|
9
|
+
iterator(function (responsizeStyles, style) {
|
|
10
|
+
if (index <= breakpoints.keys.length - 1) {
|
|
11
|
+
if (index === 0) {
|
|
12
|
+
_extends(responsizeStyles, style);
|
|
13
|
+
} else {
|
|
14
|
+
responsizeStyles[breakpoints.up(breakpoints.keys[index])] = style;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}, breakpointValue);
|
|
18
|
+
});
|
|
19
|
+
} else if (responsize && _typeof(responsize) === 'object') {
|
|
20
|
+
// prevent null
|
|
21
|
+
// responsize could be a very big object, pick the smallest responsive values
|
|
22
|
+
var keys = Object.keys(responsize).length > breakpoints.keys.length ? breakpoints.keys : Object.keys(responsize);
|
|
23
|
+
keys.forEach(function (key) {
|
|
24
|
+
if (breakpoints.keys.indexOf(key) !== -1) {
|
|
25
|
+
// @ts-ignore already checked that responsize is an object
|
|
26
|
+
var breakpointValue = responsize[key];
|
|
27
|
+
|
|
28
|
+
if (breakpointValue !== undefined) {
|
|
29
|
+
iterator(function (responsizeStyles, style) {
|
|
30
|
+
if (smallestBreakpoint === key) {
|
|
31
|
+
_extends(responsizeStyles, style);
|
|
32
|
+
} else {
|
|
33
|
+
responsizeStyles[breakpoints.up(key)] = style;
|
|
34
|
+
}
|
|
35
|
+
}, breakpointValue);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
} else if (typeof responsize === 'number' || typeof responsize === 'string') {
|
|
40
|
+
iterator(function (responsizeStyles, style) {
|
|
41
|
+
_extends(responsizeStyles, style);
|
|
42
|
+
}, responsize);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
export var generateGridSizeStyles = function generateGridSizeStyles(_ref) {
|
|
46
|
+
var theme = _ref.theme,
|
|
47
|
+
ownerState = _ref.ownerState;
|
|
48
|
+
var styles = {};
|
|
49
|
+
traverseBreakpoints(theme.breakpoints, ownerState.gridSize, function (appendStyle, value) {
|
|
50
|
+
var style = {};
|
|
51
|
+
|
|
52
|
+
if (value === true) {
|
|
53
|
+
style = {
|
|
54
|
+
flexBasis: 0,
|
|
55
|
+
flexGrow: 1,
|
|
56
|
+
maxWidth: '100%'
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (value === 'auto') {
|
|
61
|
+
style = {
|
|
62
|
+
flexBasis: 'auto',
|
|
63
|
+
flexGrow: 0,
|
|
64
|
+
flexShrink: 0,
|
|
65
|
+
maxWidth: 'none',
|
|
66
|
+
width: 'auto'
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (typeof value === 'number') {
|
|
71
|
+
style = {
|
|
72
|
+
flexGrow: 0,
|
|
73
|
+
flexBasis: 'auto',
|
|
74
|
+
width: "calc(100% * ".concat(value, " / var(--Grid-columns)").concat(ownerState.nested && ownerState.container ? " + var(--Grid-columnSpacing)" : '', ")")
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
appendStyle(styles, style);
|
|
79
|
+
});
|
|
80
|
+
return styles;
|
|
81
|
+
};
|
|
82
|
+
export var generateGridOffsetStyles = function generateGridOffsetStyles(_ref2) {
|
|
83
|
+
var theme = _ref2.theme,
|
|
84
|
+
ownerState = _ref2.ownerState;
|
|
85
|
+
var styles = {};
|
|
86
|
+
traverseBreakpoints(theme.breakpoints, ownerState.gridOffset, function (appendStyle, value) {
|
|
87
|
+
var style = {};
|
|
88
|
+
|
|
89
|
+
if (value === 'auto') {
|
|
90
|
+
style = {
|
|
91
|
+
marginLeft: 'auto'
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (typeof value === 'number') {
|
|
96
|
+
style = {
|
|
97
|
+
marginLeft: value === 0 ? '0px' : "calc(100% * ".concat(value, " / var(--Grid-columns))")
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
appendStyle(styles, style);
|
|
102
|
+
});
|
|
103
|
+
return styles;
|
|
104
|
+
};
|
|
105
|
+
export var generateGridColumnsStyles = function generateGridColumnsStyles(_ref3) {
|
|
106
|
+
var theme = _ref3.theme,
|
|
107
|
+
ownerState = _ref3.ownerState;
|
|
108
|
+
|
|
109
|
+
if (!ownerState.container) {
|
|
110
|
+
return {};
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
var styles = {
|
|
114
|
+
'--Grid-columns': 12
|
|
115
|
+
};
|
|
116
|
+
traverseBreakpoints(theme.breakpoints, ownerState.columns, function (appendStyle, value) {
|
|
117
|
+
appendStyle(styles, {
|
|
118
|
+
'--Grid-columns': value
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
return styles;
|
|
122
|
+
};
|
|
123
|
+
export var generateGridRowSpacingStyles = function generateGridRowSpacingStyles(_ref4) {
|
|
124
|
+
var theme = _ref4.theme,
|
|
125
|
+
ownerState = _ref4.ownerState;
|
|
126
|
+
|
|
127
|
+
if (!ownerState.container) {
|
|
128
|
+
return {};
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
var styles = {};
|
|
132
|
+
traverseBreakpoints(theme.breakpoints, ownerState.rowSpacing, function (appendStyle, value) {
|
|
133
|
+
var _theme$spacing;
|
|
134
|
+
|
|
135
|
+
appendStyle(styles, {
|
|
136
|
+
'--Grid-rowSpacing': typeof value === 'string' ? value : (_theme$spacing = theme.spacing) == null ? void 0 : _theme$spacing.call(theme, value)
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
return styles;
|
|
140
|
+
};
|
|
141
|
+
export var generateGridColumnSpacingStyles = function generateGridColumnSpacingStyles(_ref5) {
|
|
142
|
+
var theme = _ref5.theme,
|
|
143
|
+
ownerState = _ref5.ownerState;
|
|
144
|
+
|
|
145
|
+
if (!ownerState.container) {
|
|
146
|
+
return {};
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
var styles = {};
|
|
150
|
+
traverseBreakpoints(theme.breakpoints, ownerState.columnSpacing, function (appendStyle, value) {
|
|
151
|
+
var _theme$spacing2;
|
|
152
|
+
|
|
153
|
+
appendStyle(styles, {
|
|
154
|
+
'--Grid-columnSpacing': typeof value === 'string' ? value : (_theme$spacing2 = theme.spacing) == null ? void 0 : _theme$spacing2.call(theme, value)
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
return styles;
|
|
158
|
+
};
|
|
159
|
+
export var generateGridDirectionStyles = function generateGridDirectionStyles(_ref6) {
|
|
160
|
+
var theme = _ref6.theme,
|
|
161
|
+
ownerState = _ref6.ownerState;
|
|
162
|
+
|
|
163
|
+
if (!ownerState.container) {
|
|
164
|
+
return {};
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
var styles = {};
|
|
168
|
+
traverseBreakpoints(theme.breakpoints, ownerState.direction, function (appendStyle, value) {
|
|
169
|
+
appendStyle(styles, {
|
|
170
|
+
flexDirection: value
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
return styles;
|
|
174
|
+
};
|
|
175
|
+
export var generateGridStyles = function generateGridStyles(_ref7) {
|
|
176
|
+
var ownerState = _ref7.ownerState;
|
|
177
|
+
return _extends({
|
|
178
|
+
minWidth: 0,
|
|
179
|
+
boxSizing: 'border-box'
|
|
180
|
+
}, ownerState.container ? _extends({
|
|
181
|
+
display: 'flex',
|
|
182
|
+
flexWrap: 'wrap'
|
|
183
|
+
}, ownerState.wrap && ownerState.wrap !== 'wrap' && {
|
|
184
|
+
flexWrap: ownerState.wrap
|
|
185
|
+
}, {
|
|
186
|
+
margin: "calc(var(--Grid-rowSpacing) / -2) calc(var(--Grid-columnSpacing) / -2)"
|
|
187
|
+
}, ownerState.disableEqualOverflow && {
|
|
188
|
+
margin: "calc(var(--Grid-rowSpacing) * -1) 0px 0px calc(var(--Grid-columnSpacing) * -1)"
|
|
189
|
+
}, ownerState.nested ? _extends({
|
|
190
|
+
padding: "calc(var(--Grid-nested-rowSpacing) / 2) calc(var(--Grid-nested-columnSpacing) / 2)"
|
|
191
|
+
}, (ownerState.disableEqualOverflow || ownerState.parentDisableEqualOverflow) && {
|
|
192
|
+
padding: "calc(var(--Grid-nested-rowSpacing)) 0px 0px calc(var(--Grid-nested-columnSpacing))"
|
|
193
|
+
}) : {
|
|
194
|
+
'--Grid-nested-rowSpacing': 'var(--Grid-rowSpacing)',
|
|
195
|
+
'--Grid-nested-columnSpacing': 'var(--Grid-columnSpacing)'
|
|
196
|
+
}) : _extends({
|
|
197
|
+
padding: "calc(var(--Grid-rowSpacing) / 2) calc(var(--Grid-columnSpacing) / 2)"
|
|
198
|
+
}, ownerState.disableEqualOverflow && {
|
|
199
|
+
padding: "calc(var(--Grid-rowSpacing)) 0px 0px calc(var(--Grid-columnSpacing))"
|
|
200
|
+
}));
|
|
201
|
+
};
|
|
202
|
+
export var generateSizeClassNames = function generateSizeClassNames(gridSize) {
|
|
203
|
+
var classNames = [];
|
|
204
|
+
Object.entries(gridSize).forEach(function (_ref8) {
|
|
205
|
+
var _ref9 = _slicedToArray(_ref8, 2),
|
|
206
|
+
key = _ref9[0],
|
|
207
|
+
value = _ref9[1];
|
|
208
|
+
|
|
209
|
+
if (value !== false && value !== undefined) {
|
|
210
|
+
classNames.push("grid-".concat(key, "-").concat(String(value)));
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
return classNames;
|
|
214
|
+
};
|
|
215
|
+
export var generateSpacingClassNames = function generateSpacingClassNames(spacing) {
|
|
216
|
+
var smallestBreakpoint = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'xs';
|
|
217
|
+
|
|
218
|
+
function isValidSpacing(val) {
|
|
219
|
+
if (val === undefined) {
|
|
220
|
+
return false;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
return typeof val === 'string' && !Number.isNaN(Number(val)) || typeof val === 'number' && val > 0;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
if (isValidSpacing(spacing)) {
|
|
227
|
+
return ["spacing-".concat(smallestBreakpoint, "-").concat(String(spacing))];
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
if (_typeof(spacing) === 'object' && !Array.isArray(spacing)) {
|
|
231
|
+
var classNames = [];
|
|
232
|
+
Object.entries(spacing).forEach(function (_ref10) {
|
|
233
|
+
var _ref11 = _slicedToArray(_ref10, 2),
|
|
234
|
+
key = _ref11[0],
|
|
235
|
+
value = _ref11[1];
|
|
236
|
+
|
|
237
|
+
if (isValidSpacing(value)) {
|
|
238
|
+
classNames.push("spacing-".concat(key, "-").concat(String(value)));
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
return classNames;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
return [];
|
|
245
|
+
};
|
package/legacy/breakpoints.js
CHANGED
|
@@ -92,7 +92,7 @@ export function createEmptyBreakpointObject() {
|
|
|
92
92
|
var _breakpointsInput$key;
|
|
93
93
|
|
|
94
94
|
var breakpointsInput = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
95
|
-
var breakpointsInOrder =
|
|
95
|
+
var breakpointsInOrder = (_breakpointsInput$key = breakpointsInput.keys) == null ? void 0 : _breakpointsInput$key.reduce(function (acc, key) {
|
|
96
96
|
var breakpointStyleKey = breakpointsInput.up(key);
|
|
97
97
|
acc[breakpointStyleKey] = {};
|
|
98
98
|
return acc;
|
|
File without changes
|
|
@@ -161,7 +161,7 @@ export default function useCurrentColorScheme(options) {
|
|
|
161
161
|
if (state.mode === 'system') {
|
|
162
162
|
setState(function (currentState) {
|
|
163
163
|
return _extends({}, currentState, {
|
|
164
|
-
systemMode: e.matches ? 'dark' : 'light'
|
|
164
|
+
systemMode: e != null && e.matches ? 'dark' : 'light'
|
|
165
165
|
});
|
|
166
166
|
});
|
|
167
167
|
}
|
package/legacy/getThemeValue.js
CHANGED
|
@@ -2,7 +2,7 @@ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
|
2
2
|
import borders from './borders';
|
|
3
3
|
import display from './display';
|
|
4
4
|
import flexbox from './flexbox';
|
|
5
|
-
import grid from './
|
|
5
|
+
import grid from './cssGrid';
|
|
6
6
|
import positions from './positions';
|
|
7
7
|
import palette from './palette';
|
|
8
8
|
import shadows from './shadows';
|
package/legacy/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** @license MUI v5.
|
|
1
|
+
/** @license MUI v5.9.2
|
|
2
2
|
*
|
|
3
3
|
* This source code is licensed under the MIT license found in the
|
|
4
4
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -12,8 +12,8 @@ export { default as compose } from './compose';
|
|
|
12
12
|
export { default as display } from './display';
|
|
13
13
|
export { default as flexbox } from './flexbox';
|
|
14
14
|
export * from './flexbox';
|
|
15
|
-
export { default as grid } from './
|
|
16
|
-
export * from './
|
|
15
|
+
export { default as grid } from './cssGrid';
|
|
16
|
+
export * from './cssGrid';
|
|
17
17
|
export { default as palette } from './palette';
|
|
18
18
|
export * from './palette';
|
|
19
19
|
export { default as positions } from './positions';
|
|
@@ -45,6 +45,12 @@ export * from './colorManipulator';
|
|
|
45
45
|
export { default as ThemeProvider } from './ThemeProvider';
|
|
46
46
|
export { default as unstable_createCssVarsProvider } from './cssVars/createCssVarsProvider';
|
|
47
47
|
export { default as unstable_createGetCssVar } from './cssVars/createGetCssVar';
|
|
48
|
+
/** ----------------- */
|
|
49
|
+
|
|
50
|
+
/** Layout components */
|
|
51
|
+
|
|
48
52
|
export { default as createContainer } from './Container/createContainer';
|
|
49
53
|
export { default as Container } from './Container';
|
|
50
|
-
export * from './Container';
|
|
54
|
+
export * from './Container';
|
|
55
|
+
export { default as Unstable_Grid } from './Unstable_Grid/Grid';
|
|
56
|
+
export * from './Unstable_Grid';
|
|
@@ -0,0 +1,184 @@
|
|
|
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 `true`, the negative margin and padding are apply only to the top and left sides of the grid.
|
|
62
|
+
*/
|
|
63
|
+
disableEqualOverflow: PropTypes.bool,
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* If a number, it sets the number of columns the grid item uses.
|
|
67
|
+
* It can't be greater than the total number of columns of the container (12 by default).
|
|
68
|
+
* If 'auto', the grid item's width matches its content.
|
|
69
|
+
* If false, the prop is ignored.
|
|
70
|
+
* If true, the grid item's width grows to use the space available in the grid container.
|
|
71
|
+
* The value is applied for the `lg` breakpoint and wider screens if not overridden.
|
|
72
|
+
* @default false
|
|
73
|
+
*/
|
|
74
|
+
lg: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number, PropTypes.bool]),
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* If a number, it sets the margin-left equals to the number of columns the grid item uses.
|
|
78
|
+
* If 'auto', the grid item push itself to the right-end of the container.
|
|
79
|
+
* The value is applied for the `lg` breakpoint and wider screens if not overridden.
|
|
80
|
+
*/
|
|
81
|
+
lgOffset: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number]),
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* If a number, it sets the number of columns the grid item uses.
|
|
85
|
+
* It can't be greater than the total number of columns of the container (12 by default).
|
|
86
|
+
* If 'auto', the grid item's width matches its content.
|
|
87
|
+
* If false, the prop is ignored.
|
|
88
|
+
* If true, the grid item's width grows to use the space available in the grid container.
|
|
89
|
+
* The value is applied for the `md` breakpoint and wider screens if not overridden.
|
|
90
|
+
* @default false
|
|
91
|
+
*/
|
|
92
|
+
md: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number, PropTypes.bool]),
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* If a number, it sets the margin-left equals to the number of columns the grid item uses.
|
|
96
|
+
* If 'auto', the grid item push itself to the right-end of the container.
|
|
97
|
+
* The value is applied for the `md` breakpoint and wider screens if not overridden.
|
|
98
|
+
*/
|
|
99
|
+
mdOffset: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number]),
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Defines the vertical space between the type `item` components.
|
|
103
|
+
* It overrides the value of the `spacing` prop.
|
|
104
|
+
*/
|
|
105
|
+
rowSpacing: PropTypes
|
|
106
|
+
/* @typescript-to-proptypes-ignore */
|
|
107
|
+
.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.number, PropTypes.string])), PropTypes.number, PropTypes.object, PropTypes.string]),
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* If a number, it sets the number of columns the grid item uses.
|
|
111
|
+
* It can't be greater than the total number of columns of the container (12 by default).
|
|
112
|
+
* If 'auto', the grid item's width matches its content.
|
|
113
|
+
* If false, the prop is ignored.
|
|
114
|
+
* If true, the grid item's width grows to use the space available in the grid container.
|
|
115
|
+
* The value is applied for the `sm` breakpoint and wider screens if not overridden.
|
|
116
|
+
* @default false
|
|
117
|
+
*/
|
|
118
|
+
sm: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number, PropTypes.bool]),
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* If a number, it sets the margin-left equals to the number of columns the grid item uses.
|
|
122
|
+
* If 'auto', the grid item push itself to the right-end of the container.
|
|
123
|
+
* The value is applied for the `sm` breakpoint and wider screens if not overridden.
|
|
124
|
+
*/
|
|
125
|
+
smOffset: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number]),
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Defines the space between the type `item` components.
|
|
129
|
+
* It can only be used on a type `container` component.
|
|
130
|
+
* @default 0
|
|
131
|
+
*/
|
|
132
|
+
spacing: PropTypes
|
|
133
|
+
/* @typescript-to-proptypes-ignore */
|
|
134
|
+
.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.number, PropTypes.string])), PropTypes.number, PropTypes.object, PropTypes.string]),
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* @ignore
|
|
138
|
+
*/
|
|
139
|
+
sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Defines the `flex-wrap` style property.
|
|
143
|
+
* It's applied for all screen sizes.
|
|
144
|
+
* @default 'wrap'
|
|
145
|
+
*/
|
|
146
|
+
wrap: PropTypes.oneOf(['nowrap', 'wrap-reverse', 'wrap']),
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* If a number, it sets the number of columns the grid item uses.
|
|
150
|
+
* It can't be greater than the total number of columns of the container (12 by default).
|
|
151
|
+
* If 'auto', the grid item's width matches its content.
|
|
152
|
+
* If false, the prop is ignored.
|
|
153
|
+
* If true, the grid item's width grows to use the space available in the grid container.
|
|
154
|
+
* The value is applied for the `xl` breakpoint and wider screens if not overridden.
|
|
155
|
+
* @default false
|
|
156
|
+
*/
|
|
157
|
+
xl: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number, PropTypes.bool]),
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* If a number, it sets the margin-left equals to the number of columns the grid item uses.
|
|
161
|
+
* If 'auto', the grid item push itself to the right-end of the container.
|
|
162
|
+
* The value is applied for the `xl` breakpoint and wider screens if not overridden.
|
|
163
|
+
*/
|
|
164
|
+
xlOffset: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number]),
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* If a number, it sets the number of columns the grid item uses.
|
|
168
|
+
* It can't be greater than the total number of columns of the container (12 by default).
|
|
169
|
+
* If 'auto', the grid item's width matches its content.
|
|
170
|
+
* If false, the prop is ignored.
|
|
171
|
+
* If true, the grid item's width grows to use the space available in the grid container.
|
|
172
|
+
* The value is applied for all the screen sizes with the lowest priority.
|
|
173
|
+
* @default false
|
|
174
|
+
*/
|
|
175
|
+
xs: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number, PropTypes.bool]),
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* If a number, it sets the margin-left equals to the number of columns the grid item uses.
|
|
179
|
+
* If 'auto', the grid item push itself to the right-end of the container.
|
|
180
|
+
* The value is applied for the `xs` breakpoint and wider screens if not overridden.
|
|
181
|
+
*/
|
|
182
|
+
xsOffset: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number])
|
|
183
|
+
} : void 0;
|
|
184
|
+
export default Grid;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,175 @@
|
|
|
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", "disableEqualOverflow"];
|
|
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
|
+
const OverflowContext = /*#__PURE__*/React.createContext(undefined);
|
|
40
|
+
|
|
41
|
+
const useUtilityClasses = (ownerState, theme) => {
|
|
42
|
+
const {
|
|
43
|
+
container,
|
|
44
|
+
direction,
|
|
45
|
+
spacing,
|
|
46
|
+
wrap,
|
|
47
|
+
gridSize
|
|
48
|
+
} = ownerState;
|
|
49
|
+
const slots = {
|
|
50
|
+
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]) : [])]
|
|
51
|
+
};
|
|
52
|
+
return composeClasses(slots, slot => generateUtilityClass(componentName, slot), {});
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const GridRoot = createStyledComponent(generateGridColumnsStyles, generateGridColumnSpacingStyles, generateGridRowSpacingStyles, generateGridSizeStyles, generateGridDirectionStyles, generateGridStyles, generateGridOffsetStyles);
|
|
56
|
+
const Grid = /*#__PURE__*/React.forwardRef(function Grid(inProps, ref) {
|
|
57
|
+
const theme = useTheme();
|
|
58
|
+
const themeProps = useThemeProps(inProps);
|
|
59
|
+
const props = extendSxProp(themeProps); // `color` type conflicts with html color attribute.
|
|
60
|
+
|
|
61
|
+
const nested = React.useContext(NestedContext);
|
|
62
|
+
const overflow = React.useContext(OverflowContext);
|
|
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
|
+
disableEqualOverflow: themeDisableEqualOverflow
|
|
75
|
+
} = props,
|
|
76
|
+
rest = _objectWithoutPropertiesLoose(props, _excluded); // Because `disableEqualOverflow` can be set from the theme's defaultProps, the **nested** grid should look at the instance props instead.
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
let disableEqualOverflow = themeDisableEqualOverflow;
|
|
80
|
+
|
|
81
|
+
if (nested && themeDisableEqualOverflow !== undefined) {
|
|
82
|
+
disableEqualOverflow = inProps.disableEqualOverflow;
|
|
83
|
+
} // collect breakpoints related props because they can be customized from the theme.
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
const gridSize = {};
|
|
87
|
+
const gridOffset = {};
|
|
88
|
+
const other = {};
|
|
89
|
+
Object.entries(rest).forEach(([key, val]) => {
|
|
90
|
+
if (theme.breakpoints.values[key] !== undefined) {
|
|
91
|
+
gridSize[key] = val;
|
|
92
|
+
} else if (theme.breakpoints.values[key.replace('Offset', '')] !== undefined) {
|
|
93
|
+
gridOffset[key.replace('Offset', '')] = val;
|
|
94
|
+
} else {
|
|
95
|
+
other[key] = val;
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
const columns = inProps.columns ?? (nested ? undefined : columnsProp);
|
|
99
|
+
const spacing = inProps.spacing ?? (nested ? undefined : spacingProp);
|
|
100
|
+
const rowSpacing = inProps.rowSpacing ?? inProps.spacing ?? (nested ? undefined : rowSpacingProp);
|
|
101
|
+
const columnSpacing = inProps.columnSpacing ?? inProps.spacing ?? (nested ? undefined : columnSpacingProp);
|
|
102
|
+
|
|
103
|
+
const ownerState = _extends({}, props, {
|
|
104
|
+
nested,
|
|
105
|
+
columns,
|
|
106
|
+
container,
|
|
107
|
+
direction,
|
|
108
|
+
wrap,
|
|
109
|
+
spacing,
|
|
110
|
+
rowSpacing,
|
|
111
|
+
columnSpacing,
|
|
112
|
+
gridSize,
|
|
113
|
+
gridOffset,
|
|
114
|
+
disableEqualOverflow: disableEqualOverflow ?? overflow ?? false,
|
|
115
|
+
// use context value if exists.
|
|
116
|
+
parentDisableEqualOverflow: overflow // for nested grid
|
|
117
|
+
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
const classes = useUtilityClasses(ownerState, theme);
|
|
121
|
+
|
|
122
|
+
let result = /*#__PURE__*/_jsx(GridRoot, _extends({
|
|
123
|
+
ref: ref,
|
|
124
|
+
as: component,
|
|
125
|
+
ownerState: ownerState,
|
|
126
|
+
className: clsx(classes.root, className)
|
|
127
|
+
}, other));
|
|
128
|
+
|
|
129
|
+
if (!nested) {
|
|
130
|
+
result = /*#__PURE__*/_jsx(NestedContext.Provider, {
|
|
131
|
+
value: true,
|
|
132
|
+
children: result
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (disableEqualOverflow !== undefined && disableEqualOverflow !== (overflow ?? false)) {
|
|
137
|
+
// There are 2 possibilities that should wrap with the OverflowContext to communicate with the nested grids:
|
|
138
|
+
// 1. It is the root grid with `disableEqualOverflow`.
|
|
139
|
+
// 2. It is a nested grid with different `disableEqualOverflow` from the context.
|
|
140
|
+
result = /*#__PURE__*/_jsx(OverflowContext.Provider, {
|
|
141
|
+
value: disableEqualOverflow,
|
|
142
|
+
children: result
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return result;
|
|
147
|
+
});
|
|
148
|
+
process.env.NODE_ENV !== "production" ? Grid.propTypes
|
|
149
|
+
/* remove-proptypes */
|
|
150
|
+
= {
|
|
151
|
+
children: PropTypes.node,
|
|
152
|
+
className: PropTypes.string,
|
|
153
|
+
columns: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.number), PropTypes.number, PropTypes.object]),
|
|
154
|
+
columnSpacing: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.number, PropTypes.string])), PropTypes.number, PropTypes.object, PropTypes.string]),
|
|
155
|
+
component: PropTypes.elementType,
|
|
156
|
+
container: PropTypes.bool,
|
|
157
|
+
direction: PropTypes.oneOfType([PropTypes.oneOf(['column-reverse', 'column', 'row-reverse', 'row']), PropTypes.arrayOf(PropTypes.oneOf(['column-reverse', 'column', 'row-reverse', 'row'])), PropTypes.object]),
|
|
158
|
+
disableEqualOverflow: PropTypes.bool,
|
|
159
|
+
lg: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number, PropTypes.bool]),
|
|
160
|
+
lgOffset: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number]),
|
|
161
|
+
md: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number, PropTypes.bool]),
|
|
162
|
+
mdOffset: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number]),
|
|
163
|
+
rowSpacing: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.number, PropTypes.string])), PropTypes.number, PropTypes.object, PropTypes.string]),
|
|
164
|
+
sm: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number, PropTypes.bool]),
|
|
165
|
+
smOffset: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number]),
|
|
166
|
+
spacing: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.number, PropTypes.string])), PropTypes.number, PropTypes.object, PropTypes.string]),
|
|
167
|
+
sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
|
|
168
|
+
wrap: PropTypes.oneOf(['nowrap', 'wrap-reverse', 'wrap']),
|
|
169
|
+
xl: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number, PropTypes.bool]),
|
|
170
|
+
xlOffset: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number]),
|
|
171
|
+
xs: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number, PropTypes.bool]),
|
|
172
|
+
xsOffset: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number])
|
|
173
|
+
} : void 0;
|
|
174
|
+
return Grid;
|
|
175
|
+
}
|