UNPKG

@material-ui/core

Version:

React components that implement Google's Material Design.

155 lines (128 loc) 5 kB
"use strict"; var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard"); var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = exports.styles = void 0; var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties")); var React = _interopRequireWildcard(require("react")); var _reactIs = require("react-is"); var _propTypes = _interopRequireDefault(require("prop-types")); var _clsx = _interopRequireDefault(require("clsx")); var _withStyles = _interopRequireDefault(require("../styles/withStyles")); var _deprecatedPropType = _interopRequireDefault(require("../utils/deprecatedPropType")); 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. } }; exports.styles = styles; var ImageList = /*#__PURE__*/React.forwardRef(function ImageList(props, ref) { var cellHeight = props.cellHeight, children = props.children, classes = props.classes, className = 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$gap = props.gap, gapProp = _props$gap === void 0 ? 4 : _props$gap, _props$rowHeight = props.rowHeight, rowHeightProp = _props$rowHeight === void 0 ? 180 : _props$rowHeight, spacing = props.spacing, style = props.style, other = (0, _objectWithoutProperties2.default)(props, ["cellHeight", "children", "classes", "className", "cols", "component", "gap", "rowHeight", "spacing", "style"]); var gap = spacing || gapProp; var rowHeight = cellHeight || rowHeightProp; return /*#__PURE__*/React.createElement(Component, (0, _extends2.default)({ className: (0, _clsx.default)(classes.root, className), ref: ref, style: (0, _extends2.default)({ margin: -gap / 2 }, style) }, other), React.Children.map(children, function (child) { if (! /*#__PURE__*/React.isValidElement(child)) { return null; } if (process.env.NODE_ENV !== 'production') { if ((0, _reactIs.isFragment)(child)) { console.error(["Material-UI: The ImageList component doesn't accept a Fragment as a child.", 'Consider providing an array instead.'].join('\n')); } } var childCols = child.props.cols || 1; var childRows = child.props.rows || 1; return /*#__PURE__*/React.cloneElement(child, { style: (0, _extends2.default)({ width: "".concat(100 / cols * childCols, "%"), height: rowHeight === 'auto' ? 'auto' : rowHeight * childRows + gap, padding: gap / 2 }, child.props.style) }); })); }); process.env.NODE_ENV !== "production" ? ImageList.propTypes = { // ----------------------------- Warning -------------------------------- // | These PropTypes are generated from the TypeScript type definitions | // | To update them edit the d.ts file and run "yarn proptypes" | // ---------------------------------------------------------------------- /** * Cell height in `px`. * Set to `'auto'` to let the children determine the height. * @deprecated Use rowHeight instead. */ cellHeight: (0, _deprecatedPropType.default)(_propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.oneOf(['auto'])]), 'Use the `rowHeight` prop instead.'), /** * Items that will be in the image list. */ children: _propTypes.default.node, /** * Override or extend the styles applied to the component. * See [CSS API](#css) below for more details. */ classes: _propTypes.default.object, /** * @ignore */ className: _propTypes.default.string, /** * Number of columns. */ cols: _propTypes.default.number, /** * The component used for the root node. * Either a string to use a HTML element or a component. */ component: _propTypes.default /* @typescript-to-proptypes-ignore */ .elementType, /** * The gap between items in `px`. */ gap: _propTypes.default.number, /** * The height of one row in `px`. */ rowHeight: _propTypes.default.oneOfType([_propTypes.default.oneOf(['auto']), _propTypes.default.number]), /** * The spacing between items in `px`. * @deprecated Use gap instead. */ spacing: (0, _deprecatedPropType.default)(_propTypes.default.number, 'Use the `gap` prop instead.'), /** * @ignore */ style: _propTypes.default.object } : void 0; var _default = (0, _withStyles.default)(styles, { name: 'MuiImageList' })(ImageList); exports.default = _default;