UNPKG

4.73 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 warnedOnce = false;
40/**
41 * ⚠️ The GridList component was renamed to ImageList to align with the current Material Design naming.
42 *
43 * You should use `import { ImageList } from '@material-ui/core'`
44 * or `import ImageList from '@material-ui/core/ImageList'`.
45 */
46
47var GridList = /*#__PURE__*/React.forwardRef(function GridList(props, ref) {
48 if (process.env.NODE_ENV !== 'production') {
49 if (!warnedOnce) {
50 warnedOnce = true;
51 console.error(['Material-UI: The GridList component was renamed to ImageList to align with the current Material Design naming.', '', "You should use `import { ImageList } from '@material-ui/core'`", "or `import ImageList from '@material-ui/core/ImageList'`."].join('\n'));
52 }
53 }
54
55 var _props$cellHeight = props.cellHeight,
56 cellHeight = _props$cellHeight === void 0 ? 180 : _props$cellHeight,
57 children = props.children,
58 classes = props.classes,
59 className = props.className,
60 _props$cols = props.cols,
61 cols = _props$cols === void 0 ? 2 : _props$cols,
62 _props$component = props.component,
63 Component = _props$component === void 0 ? 'ul' : _props$component,
64 _props$spacing = props.spacing,
65 spacing = _props$spacing === void 0 ? 4 : _props$spacing,
66 style = props.style,
67 other = (0, _objectWithoutProperties2.default)(props, ["cellHeight", "children", "classes", "className", "cols", "component", "spacing", "style"]);
68 return /*#__PURE__*/React.createElement(Component, (0, _extends2.default)({
69 className: (0, _clsx.default)(classes.root, className),
70 ref: ref,
71 style: (0, _extends2.default)({
72 margin: -spacing / 2
73 }, style)
74 }, other), React.Children.map(children, function (child) {
75 if (! /*#__PURE__*/React.isValidElement(child)) {
76 return null;
77 }
78
79 if (process.env.NODE_ENV !== 'production') {
80 if ((0, _reactIs.isFragment)(child)) {
81 console.error(["Material-UI: The GridList component doesn't accept a Fragment as a child.", 'Consider providing an array instead.'].join('\n'));
82 }
83 }
84
85 var childCols = child.props.cols || 1;
86 var childRows = child.props.rows || 1;
87 return /*#__PURE__*/React.cloneElement(child, {
88 style: (0, _extends2.default)({
89 width: "".concat(100 / cols * childCols, "%"),
90 height: cellHeight === 'auto' ? 'auto' : cellHeight * childRows + spacing,
91 padding: spacing / 2
92 }, child.props.style)
93 });
94 }));
95});
96process.env.NODE_ENV !== "production" ? GridList.propTypes = {
97 /**
98 * Number of px for one cell height.
99 * You can set `'auto'` if you want to let the children determine the height.
100 */
101 cellHeight: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.oneOf(['auto'])]),
102
103 /**
104 * Grid Tiles that will be in Grid List.
105 */
106 children: _propTypes.default.node.isRequired,
107
108 /**
109 * Override or extend the styles applied to the component.
110 * See [CSS API](#css) below for more details.
111 */
112 classes: _propTypes.default.object.isRequired,
113
114 /**
115 * @ignore
116 */
117 className: _propTypes.default.string,
118
119 /**
120 * Number of columns.
121 */
122 cols: _propTypes.default.number,
123
124 /**
125 * The component used for the root node.
126 * Either a string to use a HTML element or a component.
127 */
128 component: _propTypes.default
129 /* @typescript-to-proptypes-ignore */
130 .elementType,
131
132 /**
133 * Number of px for the spacing between tiles.
134 */
135 spacing: _propTypes.default.number,
136
137 /**
138 * @ignore
139 */
140 style: _propTypes.default.object
141} : void 0;
142
143var _default = (0, _withStyles.default)(styles, {
144 name: 'MuiGridList'
145})(GridList);
146
147exports.default = _default;
\No newline at end of file