UNPKG

4.07 kBJavaScriptView Raw
1"use strict";
2
3var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
4
5var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
6
7Object.defineProperty(exports, "__esModule", {
8 value: true
9});
10exports.default = exports.styles = void 0;
11
12var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
13
14var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
15
16var React = _interopRequireWildcard(require("react"));
17
18var _reactIs = require("react-is");
19
20var _propTypes = _interopRequireDefault(require("prop-types"));
21
22var _clsx = _interopRequireDefault(require("clsx"));
23
24var _withStyles = _interopRequireDefault(require("../styles/withStyles"));
25
26var styles = {
27 /* Styles applied to the root element. */
28 root: {
29 display: 'flex',
30 flexWrap: 'wrap',
31 overflowY: 'auto',
32 listStyle: 'none',
33 padding: 0,
34 WebkitOverflowScrolling: 'touch' // Add iOS momentum scrolling.
35
36 }
37};
38exports.styles = styles;
39var GridList = /*#__PURE__*/React.forwardRef(function GridList(props, ref) {
40 var _props$cellHeight = props.cellHeight,
41 cellHeight = _props$cellHeight === void 0 ? 180 : _props$cellHeight,
42 children = props.children,
43 classes = props.classes,
44 className = props.className,
45 _props$cols = props.cols,
46 cols = _props$cols === void 0 ? 2 : _props$cols,
47 _props$component = props.component,
48 Component = _props$component === void 0 ? 'ul' : _props$component,
49 _props$spacing = props.spacing,
50 spacing = _props$spacing === void 0 ? 4 : _props$spacing,
51 style = props.style,
52 other = (0, _objectWithoutProperties2.default)(props, ["cellHeight", "children", "classes", "className", "cols", "component", "spacing", "style"]);
53 return /*#__PURE__*/React.createElement(Component, (0, _extends2.default)({
54 className: (0, _clsx.default)(classes.root, className),
55 ref: ref,
56 style: (0, _extends2.default)({
57 margin: -spacing / 2
58 }, style)
59 }, other), React.Children.map(children, function (child) {
60 if (! /*#__PURE__*/React.isValidElement(child)) {
61 return null;
62 }
63
64 if (process.env.NODE_ENV !== 'production') {
65 if ((0, _reactIs.isFragment)(child)) {
66 console.error(["Material-UI: The GridList component doesn't accept a Fragment as a child.", 'Consider providing an array instead.'].join('\n'));
67 }
68 }
69
70 var childCols = child.props.cols || 1;
71 var childRows = child.props.rows || 1;
72 return /*#__PURE__*/React.cloneElement(child, {
73 style: (0, _extends2.default)({
74 width: "".concat(100 / cols * childCols, "%"),
75 height: cellHeight === 'auto' ? 'auto' : cellHeight * childRows + spacing,
76 padding: spacing / 2
77 }, child.props.style)
78 });
79 }));
80});
81process.env.NODE_ENV !== "production" ? GridList.propTypes = {
82 /**
83 * Number of px for one cell height.
84 * You can set `'auto'` if you want to let the children determine the height.
85 */
86 cellHeight: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.oneOf(['auto'])]),
87
88 /**
89 * Grid Tiles that will be in Grid List.
90 */
91 children: _propTypes.default.node.isRequired,
92
93 /**
94 * Override or extend the styles applied to the component.
95 * See [CSS API](#css) below for more details.
96 */
97 classes: _propTypes.default.object.isRequired,
98
99 /**
100 * @ignore
101 */
102 className: _propTypes.default.string,
103
104 /**
105 * Number of columns.
106 */
107 cols: _propTypes.default.number,
108
109 /**
110 * The component used for the root node.
111 * Either a string to use a HTML element or a component.
112 */
113 component: _propTypes.default
114 /* @typescript-to-proptypes-ignore */
115 .elementType,
116
117 /**
118 * Number of px for the spacing between tiles.
119 */
120 spacing: _propTypes.default.number,
121
122 /**
123 * @ignore
124 */
125 style: _propTypes.default.object
126} : void 0;
127
128var _default = (0, _withStyles.default)(styles, {
129 name: 'MuiGridList'
130})(GridList);
131
132exports.default = _default;
\No newline at end of file