2024-04-08 14:04:08 +08:00
|
|
|
import * as React from 'react';
|
2019-12-03 13:33:04 +08:00
|
|
|
import classNames from 'classnames';
|
2022-06-22 14:57:09 +08:00
|
|
|
import omit from 'rc-util/lib/omit';
|
2024-04-08 14:04:08 +08:00
|
|
|
|
2022-03-25 20:11:33 +08:00
|
|
|
import { ConfigContext } from '../config-provider';
|
2022-05-07 14:31:54 +08:00
|
|
|
import type { SkeletonElementProps } from './Element';
|
|
|
|
import Element from './Element';
|
2022-06-22 15:18:03 +08:00
|
|
|
import useStyle from './style';
|
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
|
|
|
}
|
|
|
|
|
2022-11-19 13:47:33 +08:00
|
|
|
const SkeletonAvatar: React.FC<AvatarProps> = (props) => {
|
2022-09-27 09:57:36 +08:00
|
|
|
const {
|
|
|
|
prefixCls: customizePrefixCls,
|
|
|
|
className,
|
2023-01-20 11:03:50 +08:00
|
|
|
rootClassName,
|
2022-09-27 09:57:36 +08:00
|
|
|
active,
|
|
|
|
shape = 'circle',
|
|
|
|
size = 'default',
|
|
|
|
} = props;
|
2022-03-25 20:11:33 +08:00
|
|
|
const { getPrefixCls } = React.useContext(ConfigContext);
|
|
|
|
const prefixCls = getPrefixCls('skeleton', customizePrefixCls);
|
2023-12-14 14:58:53 +08:00
|
|
|
const [wrapCSSVar, hashId, cssVarCls] = useStyle(prefixCls);
|
2022-03-25 20:11:33 +08:00
|
|
|
|
|
|
|
const otherProps = omit(props, ['prefixCls', 'className']);
|
|
|
|
const cls = classNames(
|
|
|
|
prefixCls,
|
|
|
|
`${prefixCls}-element`,
|
|
|
|
{
|
|
|
|
[`${prefixCls}-active`]: active,
|
|
|
|
},
|
|
|
|
className,
|
2023-01-20 11:03:50 +08:00
|
|
|
rootClassName,
|
2022-03-29 20:55:44 +08:00
|
|
|
hashId,
|
2023-12-14 14:58:53 +08:00
|
|
|
cssVarCls,
|
2022-03-25 20:11:33 +08:00
|
|
|
);
|
2022-03-29 20:55:44 +08:00
|
|
|
|
2023-11-13 20:18:37 +08:00
|
|
|
return wrapCSSVar(
|
2022-03-25 20:11:33 +08:00
|
|
|
<div className={cls}>
|
2022-09-27 09:57:36 +08:00
|
|
|
<Element prefixCls={`${prefixCls}-avatar`} shape={shape} size={size} {...otherProps} />
|
2022-03-29 20:55:44 +08:00
|
|
|
</div>,
|
2022-03-25 20:11:33 +08:00
|
|
|
);
|
2020-06-28 22:41:59 +08:00
|
|
|
};
|
2018-08-22 23:34:36 +08:00
|
|
|
|
2019-04-09 13:42:34 +08:00
|
|
|
export default SkeletonAvatar;
|