@material-ui/core
Version:
React components that implement Google's Material Design.
104 lines (94 loc) • 3.25 kB
JavaScript
import _extends from "@babel/runtime/helpers/esm/extends";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
import React from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
import warning from 'warning';
import withStyles from '../styles/withStyles';
export var styles = {
/* Styles applied to the root element. */
root: {
display: 'flex',
flexWrap: 'wrap',
overflowY: 'auto',
listStyle: 'none',
padding: 0,
WebkitOverflowScrolling: 'touch' // Add iOS momentum scrolling.
}
};
var GridList = React.forwardRef(function GridList(props, ref) {
var _props$cellHeight = props.cellHeight,
cellHeight = _props$cellHeight === void 0 ? 180 : _props$cellHeight,
children = props.children,
classes = props.classes,
classNameProp = props.className,
_props$cols = props.cols,
cols = _props$cols === void 0 ? 2 : _props$cols,
_props$component = props.component,
Component = _props$component === void 0 ? 'ul' : _props$component,
_props$spacing = props.spacing,
spacing = _props$spacing === void 0 ? 4 : _props$spacing,
style = props.style,
other = _objectWithoutProperties(props, ["cellHeight", "children", "classes", "className", "cols", "component", "spacing", "style"]);
return React.createElement(Component, _extends({
className: clsx(classes.root, classNameProp),
ref: ref,
style: _extends({
margin: -spacing / 2
}, style)
}, other), React.Children.map(children, function (child) {
if (!React.isValidElement(child)) {
return null;
}
process.env.NODE_ENV !== "production" ? warning(child.type !== React.Fragment, ["Material-UI: the GridList component doesn't accept a Fragment as a child.", 'Consider providing an array instead.'].join('\n')) : void 0;
var childCols = child.props.cols || 1;
var childRows = child.props.rows || 1;
return React.cloneElement(child, {
style: _extends({
width: "".concat(100 / cols * childCols, "%"),
height: cellHeight === 'auto' ? 'auto' : cellHeight * childRows + spacing,
padding: spacing / 2
}, child.props.style)
});
}));
});
process.env.NODE_ENV !== "production" ? GridList.propTypes = {
/**
* Number of px for one cell height.
* You can set `'auto'` if you want to let the children determine the height.
*/
cellHeight: PropTypes.oneOfType([PropTypes.number, PropTypes.oneOf(['auto'])]),
/**
* Grid Tiles that will be in Grid List.
*/
children: PropTypes.node.isRequired,
/**
* Override or extend the styles applied to the component.
* See [CSS API](#css) below for more details.
*/
classes: PropTypes.object.isRequired,
/**
* @ignore
*/
className: PropTypes.string,
/**
* Number of columns.
*/
cols: PropTypes.number,
/**
* The component used for the root node.
* Either a string to use a DOM element or a component.
*/
component: PropTypes.elementType,
/**
* Number of px for the spacing between tiles.
*/
spacing: PropTypes.number,
/**
* @ignore
*/
style: PropTypes.object
} : void 0;
export default withStyles(styles, {
name: 'MuiGridList'
})(GridList);