1 | "use strict";
|
2 |
|
3 | var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
|
4 |
|
5 | var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
6 |
|
7 | Object.defineProperty(exports, "__esModule", {
|
8 | value: true
|
9 | });
|
10 | exports.default = exports.styles = void 0;
|
11 |
|
12 | var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
13 |
|
14 | var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
15 |
|
16 | var React = _interopRequireWildcard(require("react"));
|
17 |
|
18 | var _propTypes = _interopRequireDefault(require("prop-types"));
|
19 |
|
20 | var _clsx = _interopRequireDefault(require("clsx"));
|
21 |
|
22 | var _withStyles = _interopRequireDefault(require("../styles/withStyles"));
|
23 |
|
24 | var _requirePropFactory = _interopRequireDefault(require("../utils/requirePropFactory"));
|
25 |
|
26 | var _deprecatedPropType = _interopRequireDefault(require("../utils/deprecatedPropType"));
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 | var SPACINGS = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
39 | var GRID_SIZES = ['auto', true, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
|
40 |
|
41 | function generateGrid(globalStyles, theme, breakpoint) {
|
42 | var styles = {};
|
43 | GRID_SIZES.forEach(function (size) {
|
44 | var key = "grid-".concat(breakpoint, "-").concat(size);
|
45 |
|
46 | if (size === true) {
|
47 |
|
48 | styles[key] = {
|
49 | flexBasis: 0,
|
50 | flexGrow: 1,
|
51 | maxWidth: '100%'
|
52 | };
|
53 | return;
|
54 | }
|
55 |
|
56 | if (size === 'auto') {
|
57 | styles[key] = {
|
58 | flexBasis: 'auto',
|
59 | flexGrow: 0,
|
60 | maxWidth: 'none'
|
61 | };
|
62 | return;
|
63 | }
|
64 |
|
65 |
|
66 | var width = "".concat(Math.round(size / 12 * 10e7) / 10e5, "%");
|
67 |
|
68 |
|
69 | styles[key] = {
|
70 | flexBasis: width,
|
71 | flexGrow: 0,
|
72 | maxWidth: width
|
73 | };
|
74 | });
|
75 |
|
76 | if (breakpoint === 'xs') {
|
77 | (0, _extends2.default)(globalStyles, styles);
|
78 | } else {
|
79 | globalStyles[theme.breakpoints.up(breakpoint)] = styles;
|
80 | }
|
81 | }
|
82 |
|
83 | function getOffset(val) {
|
84 | var div = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
85 | var parse = parseFloat(val);
|
86 | return "".concat(parse / div).concat(String(val).replace(String(parse), '') || 'px');
|
87 | }
|
88 |
|
89 | function generateGutter(theme, breakpoint) {
|
90 | var styles = {};
|
91 | SPACINGS.forEach(function (spacing) {
|
92 | var themeSpacing = theme.spacing(spacing);
|
93 |
|
94 | if (themeSpacing === 0) {
|
95 | return;
|
96 | }
|
97 |
|
98 | styles["spacing-".concat(breakpoint, "-").concat(spacing)] = {
|
99 | margin: "-".concat(getOffset(themeSpacing, 2)),
|
100 | width: "calc(100% + ".concat(getOffset(themeSpacing), ")"),
|
101 | '& > $item': {
|
102 | padding: getOffset(themeSpacing, 2)
|
103 | }
|
104 | };
|
105 | });
|
106 | return styles;
|
107 | }
|
108 |
|
109 |
|
110 |
|
111 |
|
112 |
|
113 |
|
114 |
|
115 | var styles = function styles(theme) {
|
116 | return (0, _extends2.default)({
|
117 |
|
118 | root: {},
|
119 |
|
120 |
|
121 | container: {
|
122 | boxSizing: 'border-box',
|
123 | display: 'flex',
|
124 | flexWrap: 'wrap',
|
125 | width: '100%'
|
126 | },
|
127 |
|
128 |
|
129 | item: {
|
130 | boxSizing: 'border-box',
|
131 | margin: '0'
|
132 |
|
133 | },
|
134 |
|
135 |
|
136 | zeroMinWidth: {
|
137 | minWidth: 0
|
138 | },
|
139 |
|
140 |
|
141 | 'direction-xs-column': {
|
142 | flexDirection: 'column'
|
143 | },
|
144 |
|
145 |
|
146 | 'direction-xs-column-reverse': {
|
147 | flexDirection: 'column-reverse'
|
148 | },
|
149 |
|
150 |
|
151 | 'direction-xs-row-reverse': {
|
152 | flexDirection: 'row-reverse'
|
153 | },
|
154 |
|
155 |
|
156 | 'wrap-xs-nowrap': {
|
157 | flexWrap: 'nowrap'
|
158 | },
|
159 |
|
160 |
|
161 | 'wrap-xs-wrap-reverse': {
|
162 | flexWrap: 'wrap-reverse'
|
163 | },
|
164 |
|
165 |
|
166 | 'align-items-xs-center': {
|
167 | alignItems: 'center'
|
168 | },
|
169 |
|
170 |
|
171 | 'align-items-xs-flex-start': {
|
172 | alignItems: 'flex-start'
|
173 | },
|
174 |
|
175 |
|
176 | 'align-items-xs-flex-end': {
|
177 | alignItems: 'flex-end'
|
178 | },
|
179 |
|
180 |
|
181 | 'align-items-xs-baseline': {
|
182 | alignItems: 'baseline'
|
183 | },
|
184 |
|
185 |
|
186 | 'align-content-xs-center': {
|
187 | alignContent: 'center'
|
188 | },
|
189 |
|
190 |
|
191 | 'align-content-xs-flex-start': {
|
192 | alignContent: 'flex-start'
|
193 | },
|
194 |
|
195 |
|
196 | 'align-content-xs-flex-end': {
|
197 | alignContent: 'flex-end'
|
198 | },
|
199 |
|
200 |
|
201 | 'align-content-xs-space-between': {
|
202 | alignContent: 'space-between'
|
203 | },
|
204 |
|
205 |
|
206 | 'align-content-xs-space-around': {
|
207 | alignContent: 'space-around'
|
208 | },
|
209 |
|
210 |
|
211 | 'justify-content-xs-center': {
|
212 | justifyContent: 'center'
|
213 | },
|
214 |
|
215 |
|
216 | 'justify-content-xs-flex-end': {
|
217 | justifyContent: 'flex-end'
|
218 | },
|
219 |
|
220 |
|
221 | 'justify-content-xs-space-between': {
|
222 | justifyContent: 'space-between'
|
223 | },
|
224 |
|
225 |
|
226 | 'justify-content-xs-space-around': {
|
227 | justifyContent: 'space-around'
|
228 | },
|
229 |
|
230 |
|
231 | 'justify-content-xs-space-evenly': {
|
232 | justifyContent: 'space-evenly'
|
233 | }
|
234 | }, generateGutter(theme, 'xs'), theme.breakpoints.keys.reduce(function (accumulator, key) {
|
235 |
|
236 | generateGrid(accumulator, theme, key);
|
237 | return accumulator;
|
238 | }, {}));
|
239 | };
|
240 |
|
241 | exports.styles = styles;
|
242 | var Grid = React.forwardRef(function Grid(props, ref) {
|
243 | var _props$alignContent = props.alignContent,
|
244 | alignContent = _props$alignContent === void 0 ? 'stretch' : _props$alignContent,
|
245 | _props$alignItems = props.alignItems,
|
246 | alignItems = _props$alignItems === void 0 ? 'stretch' : _props$alignItems,
|
247 | classes = props.classes,
|
248 | classNameProp = props.className,
|
249 | _props$component = props.component,
|
250 | Component = _props$component === void 0 ? 'div' : _props$component,
|
251 | _props$container = props.container,
|
252 | container = _props$container === void 0 ? false : _props$container,
|
253 | _props$direction = props.direction,
|
254 | direction = _props$direction === void 0 ? 'row' : _props$direction,
|
255 | _props$item = props.item,
|
256 | item = _props$item === void 0 ? false : _props$item,
|
257 | justify = props.justify,
|
258 | _props$justifyContent = props.justifyContent,
|
259 | justifyContent = _props$justifyContent === void 0 ? 'flex-start' : _props$justifyContent,
|
260 | _props$lg = props.lg,
|
261 | lg = _props$lg === void 0 ? false : _props$lg,
|
262 | _props$md = props.md,
|
263 | md = _props$md === void 0 ? false : _props$md,
|
264 | _props$sm = props.sm,
|
265 | sm = _props$sm === void 0 ? false : _props$sm,
|
266 | _props$spacing = props.spacing,
|
267 | spacing = _props$spacing === void 0 ? 0 : _props$spacing,
|
268 | _props$wrap = props.wrap,
|
269 | wrap = _props$wrap === void 0 ? 'wrap' : _props$wrap,
|
270 | _props$xl = props.xl,
|
271 | xl = _props$xl === void 0 ? false : _props$xl,
|
272 | _props$xs = props.xs,
|
273 | xs = _props$xs === void 0 ? false : _props$xs,
|
274 | _props$zeroMinWidth = props.zeroMinWidth,
|
275 | zeroMinWidth = _props$zeroMinWidth === void 0 ? false : _props$zeroMinWidth,
|
276 | other = (0, _objectWithoutProperties2.default)(props, ["alignContent", "alignItems", "classes", "className", "component", "container", "direction", "item", "justify", "justifyContent", "lg", "md", "sm", "spacing", "wrap", "xl", "xs", "zeroMinWidth"]);
|
277 | var className = (0, _clsx.default)(classes.root, classNameProp, container && [classes.container, spacing !== 0 && classes["spacing-xs-".concat(String(spacing))]], item && classes.item, zeroMinWidth && classes.zeroMinWidth, direction !== 'row' && classes["direction-xs-".concat(String(direction))], wrap !== 'wrap' && classes["wrap-xs-".concat(String(wrap))], alignItems !== 'stretch' && classes["align-items-xs-".concat(String(alignItems))], alignContent !== 'stretch' && classes["align-content-xs-".concat(String(alignContent))], (justify || justifyContent) !== 'flex-start' && classes["justify-content-xs-".concat(String(justify || justifyContent))], xs !== false && classes["grid-xs-".concat(String(xs))], sm !== false && classes["grid-sm-".concat(String(sm))], md !== false && classes["grid-md-".concat(String(md))], lg !== false && classes["grid-lg-".concat(String(lg))], xl !== false && classes["grid-xl-".concat(String(xl))]);
|
278 | return React.createElement(Component, (0, _extends2.default)({
|
279 | className: className,
|
280 | ref: ref
|
281 | }, other));
|
282 | });
|
283 | process.env.NODE_ENV !== "production" ? Grid.propTypes = {
|
284 | |
285 |
|
286 |
|
287 |
|
288 | alignContent: _propTypes.default.oneOf(['stretch', 'center', 'flex-start', 'flex-end', 'space-between', 'space-around']),
|
289 |
|
290 | |
291 |
|
292 |
|
293 |
|
294 | alignItems: _propTypes.default.oneOf(['flex-start', 'center', 'flex-end', 'stretch', 'baseline']),
|
295 |
|
296 | |
297 |
|
298 |
|
299 | children: _propTypes.default.node,
|
300 |
|
301 | |
302 |
|
303 |
|
304 |
|
305 | classes: _propTypes.default.object.isRequired,
|
306 |
|
307 | |
308 |
|
309 |
|
310 | className: _propTypes.default.string,
|
311 |
|
312 | |
313 |
|
314 |
|
315 |
|
316 | component: _propTypes.default
|
317 |
|
318 | .elementType,
|
319 |
|
320 | |
321 |
|
322 |
|
323 |
|
324 | container: _propTypes.default.bool,
|
325 |
|
326 | |
327 |
|
328 |
|
329 |
|
330 | direction: _propTypes.default.oneOf(['row', 'row-reverse', 'column', 'column-reverse']),
|
331 |
|
332 | |
333 |
|
334 |
|
335 |
|
336 | item: _propTypes.default.bool,
|
337 |
|
338 | |
339 |
|
340 |
|
341 |
|
342 |
|
343 | justify: (0, _deprecatedPropType.default)(_propTypes.default.oneOf(['flex-start', 'center', 'flex-end', 'space-between', 'space-around', 'space-evenly']), 'Use `justifyContent` instead, the prop was renamed.'),
|
344 |
|
345 | |
346 |
|
347 |
|
348 |
|
349 | justifyContent: _propTypes.default.oneOf(['flex-start', 'center', 'flex-end', 'space-between', 'space-around', 'space-evenly']),
|
350 |
|
351 | |
352 |
|
353 |
|
354 |
|
355 | lg: _propTypes.default.oneOf([false, 'auto', true, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]),
|
356 |
|
357 | |
358 |
|
359 |
|
360 |
|
361 | md: _propTypes.default.oneOf([false, 'auto', true, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]),
|
362 |
|
363 | |
364 |
|
365 |
|
366 |
|
367 | sm: _propTypes.default.oneOf([false, 'auto', true, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]),
|
368 |
|
369 | |
370 |
|
371 |
|
372 |
|
373 | spacing: _propTypes.default.oneOf(SPACINGS),
|
374 |
|
375 | |
376 |
|
377 |
|
378 |
|
379 | wrap: _propTypes.default.oneOf(['nowrap', 'wrap', 'wrap-reverse']),
|
380 |
|
381 | |
382 |
|
383 |
|
384 |
|
385 | xl: _propTypes.default.oneOf([false, 'auto', true, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]),
|
386 |
|
387 | |
388 |
|
389 |
|
390 |
|
391 | xs: _propTypes.default.oneOf([false, 'auto', true, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]),
|
392 |
|
393 | |
394 |
|
395 |
|
396 |
|
397 | zeroMinWidth: _propTypes.default.bool
|
398 | } : void 0;
|
399 | var StyledGrid = (0, _withStyles.default)(styles, {
|
400 | name: 'MuiGrid'
|
401 | })(Grid);
|
402 |
|
403 | if (process.env.NODE_ENV !== 'production') {
|
404 | var requireProp = (0, _requirePropFactory.default)('Grid');
|
405 | StyledGrid.propTypes = (0, _extends2.default)({}, StyledGrid.propTypes, {
|
406 | alignContent: requireProp('container'),
|
407 | alignItems: requireProp('container'),
|
408 | direction: requireProp('container'),
|
409 | justifyContent: requireProp('container'),
|
410 | lg: requireProp('item'),
|
411 | md: requireProp('item'),
|
412 | sm: requireProp('item'),
|
413 | spacing: requireProp('container'),
|
414 | wrap: requireProp('container'),
|
415 | xs: requireProp('item'),
|
416 | zeroMinWidth: requireProp('item')
|
417 | });
|
418 | }
|
419 |
|
420 | var _default = StyledGrid;
|
421 | exports.default = _default; |
\ | No newline at end of file |