react-toolbox/components/avatar/Avatar.js

45 lines
1.5 KiB
JavaScript
Raw Normal View History

import React, { PropTypes } from 'react';
2016-07-04 23:03:57 +03:00
import classnames from 'classnames';
2016-05-16 14:39:59 +03:00
import { themr } from 'react-css-themr';
import { AVATAR } from '../identifiers.js';
import InjectFontIcon from '../font_icon/FontIcon.js';
const factory = (FontIcon) => {
const Avatar = ({alt, children, className, cover, icon, image, theme, title, ...other}) => (
2016-07-04 23:03:57 +03:00
<div data-react-toolbox='avatar' className={classnames(theme.avatar, className)} {...other}>
{children}
{cover && typeof image === 'string' && <span aria-label={alt} className={theme.image} style={{backgroundImage: `url(${image})`}} />}
{!cover && (typeof image === 'string' ? <img alt={alt} className={theme.image} src={image} /> : image)}
{typeof icon === 'string' ? <FontIcon className={theme.letter} value={icon} alt={alt} /> : icon}
{title ? <span className={theme.letter}>{title[0]}</span> : null}
</div>
);
Avatar.propTypes = {
alt: PropTypes.string,
children: PropTypes.node,
className: PropTypes.string,
2016-07-10 15:23:40 +03:00
cover: PropTypes.bool,
icon: PropTypes.oneOfType([PropTypes.string, PropTypes.element]),
image: PropTypes.oneOfType([PropTypes.string, PropTypes.element]),
theme: PropTypes.shape({
avatar: PropTypes.string,
image: PropTypes.string,
letter: PropTypes.string
}),
title: PropTypes.string
};
2016-07-10 15:23:40 +03:00
Avatar.defaultProps = {
alt: '',
2016-07-10 15:23:40 +03:00
cover: false
};
return Avatar;
2015-11-26 03:53:42 +03:00
};
const Avatar = factory(InjectFontIcon);
export default themr(AVATAR)(Avatar);
export { factory as avatarFactory };
export { Avatar };