import React from 'react'; import PropTypes from 'prop-types'; import classNames from 'classnames'; import _ from 'lodash'; import { Avatar } from './Avatar'; import { AvatarFont } from './AvatarFont'; class AvatarImage extends React.PureComponent { static propTypes = { src: PropTypes.string.isRequired, placeholder: PropTypes.node, alt: PropTypes.string, className: PropTypes.string, ..._.omit(Avatar.propTypes, ['children']) }; static defaultProps = { placeholder: } constructor(props) { super(props); this.state = { imgLoaded: false }; } render() { const { src, placeholder, alt, className, ...avatarProps } = this.props; const parentClass = classNames('avatar-image', { 'avatar-image--loaded': this.state.imgLoaded }, className); return (
{ { this.setState({ imgLoaded: true }) } } /> { !this.state.imgLoaded && ( { placeholder } ) }
) } } export { AvatarImage };