react-toolbox/components/avatar/Avatar.js

36 lines
1.3 KiB
JavaScript
Raw Normal View History

2015-11-28 00:17:35 +03:00
import React, {PropTypes} from 'react';
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 = ({children, className, icon, image, theme, title, ...other}) => (
<div data-react-toolbox='avatar' className={`${theme.avatar} ${className}`} {...other}>
{children}
{typeof image === 'string' ? <img className={theme.image} src={image} title={title} /> : image}
{typeof icon === 'string' ? <FontIcon className={theme.letter} value={icon} /> : icon}
{title ? <span className={theme.letter}>{title[0]}</span> : null}
</div>
);
Avatar.propTypes = {
children: PropTypes.node,
className: PropTypes.string,
icon: PropTypes.oneOfType([PropTypes.string, PropTypes.element]),
image: PropTypes.oneOfType([PropTypes.string, PropTypes.element]),
theme: React.PropTypes.shape({
avatar: React.PropTypes.string.isRequired,
image: React.PropTypes.string.isRequired,
letter: React.PropTypes.string.isRequired
}),
title: PropTypes.string
};
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 };