UNPKG

5 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 _deprecatedPropType = _interopRequireDefault(require("../utils/deprecatedPropType"));
27
28var styles = {
29 /* Styles applied to the root element. */
30 root: {
31 display: 'flex',
32 flexWrap: 'wrap',
33 overflowY: 'auto',
34 listStyle: 'none',
35 padding: 0,
36 WebkitOverflowScrolling: 'touch' // Add iOS momentum scrolling.
37
38 }
39};
40exports.styles = styles;
41var ImageList = /*#__PURE__*/React.forwardRef(function ImageList(props, ref) {
42 var cellHeight = props.cellHeight,
43 children = props.children,
44 classes = props.classes,
45 className = props.className,
46 _props$cols = props.cols,
47 cols = _props$cols === void 0 ? 2 : _props$cols,
48 _props$component = props.component,
49 Component = _props$component === void 0 ? 'ul' : _props$component,
50 _props$gap = props.gap,
51 gapProp = _props$gap === void 0 ? 4 : _props$gap,
52 _props$rowHeight = props.rowHeight,
53 rowHeightProp = _props$rowHeight === void 0 ? 180 : _props$rowHeight,
54 spacing = props.spacing,
55 style = props.style,
56 other = (0, _objectWithoutProperties2.default)(props, ["cellHeight", "children", "classes", "className", "cols", "component", "gap", "rowHeight", "spacing", "style"]);
57 var gap = spacing || gapProp;
58 var rowHeight = cellHeight || rowHeightProp;
59 return /*#__PURE__*/React.createElement(Component, (0, _extends2.default)({
60 className: (0, _clsx.default)(classes.root, className),
61 ref: ref,
62 style: (0, _extends2.default)({
63 margin: -gap / 2
64 }, style)
65 }, other), React.Children.map(children, function (child) {
66 if (! /*#__PURE__*/React.isValidElement(child)) {
67 return null;
68 }
69
70 if (process.env.NODE_ENV !== 'production') {
71 if ((0, _reactIs.isFragment)(child)) {
72 console.error(["Material-UI: The ImageList component doesn't accept a Fragment as a child.", 'Consider providing an array instead.'].join('\n'));
73 }
74 }
75
76 var childCols = child.props.cols || 1;
77 var childRows = child.props.rows || 1;
78 return /*#__PURE__*/React.cloneElement(child, {
79 style: (0, _extends2.default)({
80 width: "".concat(100 / cols * childCols, "%"),
81 height: rowHeight === 'auto' ? 'auto' : rowHeight * childRows + gap,
82 padding: gap / 2
83 }, child.props.style)
84 });
85 }));
86});
87process.env.NODE_ENV !== "production" ? ImageList.propTypes = {
88 // ----------------------------- Warning --------------------------------
89 // | These PropTypes are generated from the TypeScript type definitions |
90 // | To update them edit the d.ts file and run "yarn proptypes" |
91 // ----------------------------------------------------------------------
92
93 /**
94 * Cell height in `px`.
95 * Set to `'auto'` to let the children determine the height.
96 * @deprecated Use rowHeight instead.
97 */
98 cellHeight: (0, _deprecatedPropType.default)(_propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.oneOf(['auto'])]), 'Use the `rowHeight` prop instead.'),
99
100 /**
101 * Items that will be in the image list.
102 */
103 children: _propTypes.default.node,
104
105 /**
106 * Override or extend the styles applied to the component.
107 * See [CSS API](#css) below for more details.
108 */
109 classes: _propTypes.default.object,
110
111 /**
112 * @ignore
113 */
114 className: _propTypes.default.string,
115
116 /**
117 * Number of columns.
118 */
119 cols: _propTypes.default.number,
120
121 /**
122 * The component used for the root node.
123 * Either a string to use a HTML element or a component.
124 */
125 component: _propTypes.default
126 /* @typescript-to-proptypes-ignore */
127 .elementType,
128
129 /**
130 * The gap between items in `px`.
131 */
132 gap: _propTypes.default.number,
133
134 /**
135 * The height of one row in `px`.
136 */
137 rowHeight: _propTypes.default.oneOfType([_propTypes.default.oneOf(['auto']), _propTypes.default.number]),
138
139 /**
140 * The spacing between items in `px`.
141 * @deprecated Use gap instead.
142 */
143 spacing: (0, _deprecatedPropType.default)(_propTypes.default.number, 'Use the `gap` prop instead.'),
144
145 /**
146 * @ignore
147 */
148 style: _propTypes.default.object
149} : void 0;
150
151var _default = (0, _withStyles.default)(styles, {
152 name: 'MuiImageList'
153})(ImageList);
154
155exports.default = _default;
\No newline at end of file