UNPKG

@krowdy-ui/views

Version:

React components that implement Google's Material Design.

125 lines (119 loc) 3.54 kB
import React from 'react'; import PropTypes from 'prop-types'; import clsx from 'clsx'; import { withStyles } from '@krowdy-ui/styles'; import { HighlightOff as HighlightOffIcon } from '@material-ui/icons'; export var styles = function styles(theme) { return { big: { height: 44, width: 44 }, 'default': { height: 36, width: 36 }, defaultAvatar: { alignItems: 'center', backgroundColor: 'white', border: "solid 1px ".concat(theme.palette.primary.main), borderRadius: '50%', display: 'flex', fontSize: 14, justifyContent: 'center' // marginRight: theme.spacing(2), }, defaultAvatarNothing: { background: theme.palette.grey[400] }, deleteIcon: { backgroundColor: theme.palette.primary[500], borderRadius: '50%', color: 'white', cursor: 'pointer', display: 'none', height: theme.spacing(1.5), padding: 0, position: 'absolute', right: 0, top: 0, width: theme.spacing(1.5) }, hover: { '&:hover': { border: "solid 3px ".concat(theme.palette.primary[300]) } }, image: { border: "solid 3px ".concat(theme.palette.primary[300]), borderRadius: '50%' // marginRight: theme.spacing(2), }, imageActive: { border: "solid 3px ".concat(theme.palette.primary.main) }, imageDefault: { border: "solid 3px ".concat(theme.palette.grey[300]) }, root: { '&:hover': { '& $deleteIcon': { display: 'block' } }, position: 'relative' }, small: { height: 28, width: 28 } }; }; function AvatarUser(props) { var user = props.user, classes = props.classes, active = props.active, hover = props.hover, _props$size = props.size, size = _props$size === void 0 ? 'default' : _props$size, onDelete = props.onDelete; var acro = "".concat(user.firstName && typeof user.firstName === 'string' ? user.firstName.charAt() : '').concat(user.lastName && typeof user.lastName === 'string' ? user.lastName.charAt() : ''); var _handleClickDelete = function _handleClickDelete() { return onDelete(); }; return /*#__PURE__*/React.createElement("div", { className: classes.root }, user ? user.photo ? /*#__PURE__*/React.createElement("img", { alt: acro, className: clsx(classes.image, active ? classes.imageActive : hover && classes.hover, active === undefined && classes.imageDefault, { "default": classes["default"], small: classes.small, big: classes.big }[size]), src: user.photo }) : /*#__PURE__*/React.createElement("div", { className: clsx(classes.defaultAvatar, { "default": classes["default"], small: classes.small, big: classes.big }[size]) }, acro) : null // <div className={clsx(classes.defaultAvatar, classes.defaultAvatarNothing )} /> , onDelete && /*#__PURE__*/React.createElement(HighlightOffIcon, { className: classes.deleteIcon, fontSize: "small", onClick: _handleClickDelete })); } process.env.NODE_ENV !== "production" ? AvatarUser.propTypes = { active: PropTypes.bool, classes: PropTypes.object, hover: PropTypes.bool, size: PropTypes.string, user: PropTypes.shape({ firstName: PropTypes.string, lastName: PropTypes.string, photo: PropTypes.string }) } : void 0; AvatarUser.muiName = 'AvatarUser'; export default withStyles(styles, { name: 'AvatarUser' })(AvatarUser);