2018-08-22 23:34:36 +08:00
|
|
|
import * as React from 'react';
|
2019-12-03 13:33:04 +08:00
|
|
|
import omit from 'omit.js';
|
|
|
|
import classNames from 'classnames';
|
|
|
|
import { ConfigConsumer, ConfigConsumerProps } from '../config-provider';
|
|
|
|
import Element, { SkeletonElementProps } from './Element';
|
2018-08-22 23:34:36 +08:00
|
|
|
|
2019-11-21 20:23:56 +08:00
|
|
|
export interface AvatarProps extends Omit<SkeletonElementProps, 'shape'> {
|
2018-12-07 20:02:01 +08:00
|
|
|
shape?: 'circle' | 'square';
|
2018-08-22 23:34:36 +08:00
|
|
|
}
|
|
|
|
|
2019-08-06 15:02:05 +08:00
|
|
|
// eslint-disable-next-line react/prefer-stateless-function
|
2019-11-21 20:23:56 +08:00
|
|
|
class SkeletonAvatar extends React.Component<AvatarProps, any> {
|
2019-12-03 13:33:04 +08:00
|
|
|
static defaultProps: Partial<AvatarProps> = {
|
|
|
|
size: 'default',
|
|
|
|
shape: 'circle',
|
|
|
|
};
|
|
|
|
|
|
|
|
renderSkeletonAvatar = ({ getPrefixCls }: ConfigConsumerProps) => {
|
|
|
|
const { prefixCls: customizePrefixCls, className, active } = this.props;
|
|
|
|
const prefixCls = getPrefixCls('skeleton', customizePrefixCls);
|
|
|
|
const otherProps = omit(this.props, ['prefixCls']);
|
|
|
|
const cls = classNames(prefixCls, className, `${prefixCls}-element`, {
|
|
|
|
[`${prefixCls}-active`]: active,
|
|
|
|
});
|
|
|
|
return (
|
|
|
|
<div className={cls}>
|
|
|
|
<Element prefixCls={`${prefixCls}-avatar`} {...otherProps} />
|
|
|
|
</div>
|
|
|
|
);
|
2018-08-22 23:34:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
render() {
|
2019-12-03 13:33:04 +08:00
|
|
|
return <ConfigConsumer>{this.renderSkeletonAvatar}</ConfigConsumer>;
|
2018-08-22 23:34:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-09 13:42:34 +08:00
|
|
|
export default SkeletonAvatar;
|