mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-01 03:29:39 +08:00
41ed9bd430
* feat: add semantic doc * 🔀 feat: rebase feature * feat: update for code reviewer * feat: update snap * feat: update snap * 🐛 bug: update for cov * Message * bug: update snap * 💄 style: update style * 💄 style: update style * 💄 style: update style * 💄 style: update style * 💄 style: update style * 💄 style: update style * ♻️ feat: ref code * 🩺 feat: update for review * 💄 style: update style * 📝 doc: update doc * 💄 style: update style * 💄 style: update style * 💄 style: update style * 💄 style: update style * 💄 style: update style * 💄 style: update style * 💄 style: update style * 📸 feat:update snap * 🚧 feat: clean up * 🚧 feat: clean up * feat: icon wrapper * test: update snapshot * chore: code clean * fix: icon only font size * chore: rollback unexpected commit --------- Co-authored-by: MadCcc <1075746765@qq.com>
92 lines
2.2 KiB
TypeScript
92 lines
2.2 KiB
TypeScript
import LoadingOutlined from '@ant-design/icons/LoadingOutlined';
|
|
import CSSMotion from 'rc-motion';
|
|
import React, { forwardRef } from 'react';
|
|
import classNames from 'classnames';
|
|
import IconWrapper from './IconWrapper';
|
|
|
|
type InnerLoadingIconProps = {
|
|
prefixCls: string;
|
|
className?: string;
|
|
style?: React.CSSProperties;
|
|
iconClassName?: string;
|
|
};
|
|
|
|
const InnerLoadingIcon = forwardRef<HTMLSpanElement, InnerLoadingIconProps>(
|
|
({ prefixCls, className, style, iconClassName }, ref) => {
|
|
const mergedIconCls = classNames(`${prefixCls}-loading-icon`, className);
|
|
|
|
return (
|
|
<IconWrapper prefixCls={prefixCls} className={mergedIconCls} style={style} ref={ref}>
|
|
<LoadingOutlined className={iconClassName} />
|
|
</IconWrapper>
|
|
);
|
|
},
|
|
);
|
|
|
|
export interface LoadingIconProps {
|
|
prefixCls: string;
|
|
existIcon: boolean;
|
|
loading?: boolean | object;
|
|
className?: string;
|
|
style?: React.CSSProperties;
|
|
}
|
|
|
|
const getCollapsedWidth = (): React.CSSProperties => ({
|
|
width: 0,
|
|
opacity: 0,
|
|
transform: 'scale(0)',
|
|
});
|
|
|
|
const getRealWidth = (node: HTMLElement): React.CSSProperties => ({
|
|
width: node.scrollWidth,
|
|
opacity: 1,
|
|
transform: 'scale(1)',
|
|
});
|
|
|
|
const LoadingIcon: React.FC<LoadingIconProps> = ({
|
|
prefixCls,
|
|
loading,
|
|
existIcon,
|
|
className,
|
|
style,
|
|
}) => {
|
|
const visible = !!loading;
|
|
|
|
if (existIcon) {
|
|
return <InnerLoadingIcon prefixCls={prefixCls} className={className} style={style} />;
|
|
}
|
|
|
|
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: motionCls,
|
|
style: motionStyle,
|
|
}: { className?: string; style?: React.CSSProperties },
|
|
ref: any,
|
|
) => (
|
|
<InnerLoadingIcon
|
|
prefixCls={prefixCls}
|
|
className={className}
|
|
style={{ ...style, ...motionStyle }}
|
|
ref={ref}
|
|
iconClassName={motionCls}
|
|
/>
|
|
)}
|
|
</CSSMotion>
|
|
);
|
|
};
|
|
|
|
export default LoadingIcon;
|