'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.styles = undefined; var _extends2 = require('babel-runtime/helpers/extends'); var _extends3 = _interopRequireDefault(_extends2); var _defineProperty2 = require('babel-runtime/helpers/defineProperty'); var _defineProperty3 = _interopRequireDefault(_defineProperty2); var _objectWithoutProperties2 = require('babel-runtime/helpers/objectWithoutProperties'); var _objectWithoutProperties3 = _interopRequireDefault(_objectWithoutProperties2); var _react = require('react'); var _react2 = _interopRequireDefault(_react); var _propTypes = require('prop-types'); var _propTypes2 = _interopRequireDefault(_propTypes); var _classnames = require('classnames'); var _classnames2 = _interopRequireDefault(_classnames); var _withStyles = require('../styles/withStyles'); var _withStyles2 = _interopRequireDefault(_withStyles); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var styles = exports.styles = function styles(theme) { return { root: { position: 'relative', display: 'flex', alignItems: 'center', justifyContent: 'center', flexShrink: 0, width: theme.spacing.unit * 5, height: theme.spacing.unit * 5, fontFamily: theme.typography.fontFamily, fontSize: theme.typography.pxToRem(20), borderRadius: '50%', overflow: 'hidden', userSelect: 'none' }, colorDefault: { color: theme.palette.background.default, backgroundColor: theme.palette.type === 'light' ? theme.palette.grey[400] : theme.palette.grey[600] }, img: { width: '100%', height: '100%', textAlign: 'center', // Handle non-square image. The property isn't supported by IE11. objectFit: 'cover' } }; }; function Avatar(props) { var alt = props.alt, childrenProp = props.children, childrenClassNameProp = props.childrenClassName, classes = props.classes, classNameProp = props.className, Component = props.component, imgProps = props.imgProps, sizes = props.sizes, src = props.src, srcSet = props.srcSet, other = (0, _objectWithoutProperties3.default)(props, ['alt', 'children', 'childrenClassName', 'classes', 'className', 'component', 'imgProps', 'sizes', 'src', 'srcSet']); var className = (0, _classnames2.default)(classes.root, (0, _defineProperty3.default)({}, classes.colorDefault, childrenProp && !src && !srcSet), classNameProp); var children = null; if (childrenProp) { if (childrenClassNameProp && typeof childrenProp !== 'string' && _react2.default.isValidElement(childrenProp)) { var childrenClassName = (0, _classnames2.default)(childrenClassNameProp, childrenProp.props.className); children = _react2.default.cloneElement(childrenProp, { className: childrenClassName }); } else { children = childrenProp; } } else if (src || srcSet) { children = _react2.default.createElement('img', (0, _extends3.default)({ alt: alt, src: src, srcSet: srcSet, sizes: sizes, className: classes.img }, imgProps)); } return _react2.default.createElement( Component, (0, _extends3.default)({ className: className }, other), children ); } Avatar.propTypes = process.env.NODE_ENV !== "production" ? { /** * Used in combination with `src` or `srcSet` to * provide an alt attribute for the rendered `img` element. */ alt: _propTypes2.default.string, /** * Used to render icon or text elements inside the Avatar. * `src` and `alt` props will not be used and no `img` will * be rendered by default. * * This can be an element, or just a string. */ children: _propTypes2.default.node, /** * @ignore * The className of the child element. * Used by Chip and ListItemIcon to style the Avatar icon. */ childrenClassName: _propTypes2.default.string, /** * Useful to extend the style applied to components. */ classes: _propTypes2.default.object.isRequired, /** * @ignore */ className: _propTypes2.default.string, /** * The component used for the root node. * Either a string to use a DOM element or a component. */ component: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.func]), /** * Properties applied to the `img` element when the component * is used to display an image. */ imgProps: _propTypes2.default.object, /** * The `sizes` attribute for the `img` element. */ sizes: _propTypes2.default.string, /** * The `src` attribute for the `img` element. */ src: _propTypes2.default.string, /** * The `srcSet` attribute for the `img` element. */ srcSet: _propTypes2.default.string } : {}; Avatar.defaultProps = { component: 'div' }; exports.default = (0, _withStyles2.default)(styles, { name: 'MuiAvatar' })(Avatar);