2019-01-12 11:33:27 +08:00
|
|
|
import classNames from 'classnames';
|
|
|
|
import PropTypes from '../_util/vue-types';
|
|
|
|
import { initDefaultProps } from '../_util/props-util';
|
2018-12-10 11:34:51 +08:00
|
|
|
|
|
|
|
const skeletonAvatarProps = {
|
|
|
|
prefixCls: PropTypes.string,
|
2020-03-07 19:45:13 +08:00
|
|
|
size: PropTypes.oneOfType([PropTypes.oneOf(['large', 'small', 'default']), PropTypes.number]),
|
2018-12-10 11:34:51 +08:00
|
|
|
shape: PropTypes.oneOf(['circle', 'square']),
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|
2018-12-10 11:34:51 +08:00
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
export const SkeletonAvatarProps = PropTypes.shape(skeletonAvatarProps).loose;
|
2018-12-10 11:34:51 +08:00
|
|
|
|
|
|
|
const Avatar = {
|
|
|
|
props: initDefaultProps(skeletonAvatarProps, {
|
|
|
|
size: 'large',
|
|
|
|
}),
|
2019-01-12 11:33:27 +08:00
|
|
|
render() {
|
|
|
|
const { prefixCls, size, shape } = this.$props;
|
2018-12-10 11:34:51 +08:00
|
|
|
|
|
|
|
const sizeCls = classNames({
|
|
|
|
[`${prefixCls}-lg`]: size === 'large',
|
|
|
|
[`${prefixCls}-sm`]: size === 'small',
|
2019-01-12 11:33:27 +08:00
|
|
|
});
|
2018-12-10 11:34:51 +08:00
|
|
|
|
|
|
|
const shapeCls = classNames({
|
|
|
|
[`${prefixCls}-circle`]: shape === 'circle',
|
|
|
|
[`${prefixCls}-square`]: shape === 'square',
|
2019-01-12 11:33:27 +08:00
|
|
|
});
|
2018-12-10 11:34:51 +08:00
|
|
|
|
2020-03-07 19:45:13 +08:00
|
|
|
const sizeStyle =
|
|
|
|
typeof size === 'number'
|
|
|
|
? {
|
|
|
|
width: `${size}px`,
|
|
|
|
height: `${size}px`,
|
|
|
|
lineHeight: `${size}px`,
|
|
|
|
}
|
|
|
|
: {};
|
|
|
|
|
|
|
|
return <span class={classNames(prefixCls, sizeCls, shapeCls)} style={sizeStyle} />;
|
2018-12-10 11:34:51 +08:00
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|
2018-12-10 11:34:51 +08:00
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
export default Avatar;
|