You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.4 KiB

import React from 'react';
import CSSMotion from 'rc-motion';
import LoadingOutlined from '@ant-design/icons/LoadingOutlined';
export interface LoadingIconProps {
prefixCls: string;
existIcon: boolean;
loading?: boolean | object;
}
const getCollapsedWidth = () => ({ width: 0, opacity: 0, transform: 'scale(0)' });
const getRealWidth = (node: HTMLElement) => ({
width: node.scrollWidth,
opacity: 1,
transform: 'scale(1)',
});
const LoadingIcon: React.FC<LoadingIconProps> = ({ prefixCls, loading, existIcon }) => {
const visible = !!loading;
if (existIcon) {
return (
<span className={`${prefixCls}-loading-icon`}>
<LoadingOutlined />
</span>
);
}
return (
<CSSMotion
visible={visible}
// We do not really use this motionName
motionName={`${prefixCls}-loading-icon-motion`}
removeOnLeave
onAppearStart={getCollapsedWidth}
onAppearActive={getRealWidth}
onEnterStart={getCollapsedWidth}
onEnterActive={getRealWidth}
onLeaveStart={getRealWidth}
onLeaveActive={getCollapsedWidth}
>
{({ className, style }: { className?: string; style?: React.CSSProperties }, ref: any) => (
<span className={`${prefixCls}-loading-icon`} style={style} ref={ref}>
<LoadingOutlined className={className} />
</span>
)}
</CSSMotion>
);
};
export default LoadingIcon;