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