UNPKG

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