mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-25 03:29:59 +08:00
775d1800bb
* chore(deps-dev): bump eslint-config-prettier from 6.15.0 to 7.0.0 Bumps [eslint-config-prettier](https://github.com/prettier/eslint-config-prettier) from 6.15.0 to 7.0.0. - [Release notes](https://github.com/prettier/eslint-config-prettier/releases) - [Changelog](https://github.com/prettier/eslint-config-prettier/blob/main/CHANGELOG.md) - [Commits](https://github.com/prettier/eslint-config-prettier/compare/v6.15.0...v7.0.0) Signed-off-by: dependabot[bot] <support@github.com> * chore: fix eslint style * chore: prettier code style Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: afc163 <afc163@gmail.com>
51 lines
1.4 KiB
TypeScript
51 lines
1.4 KiB
TypeScript
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;
|